|
6 | 6 |
|
7 | 7 | import base64 |
8 | 8 | import calendar |
| 9 | +import datetime |
9 | 10 | import io |
10 | 11 | import time |
11 | 12 | from typing import Dict, Union |
12 | 13 | from urllib.parse import urljoin |
13 | 14 |
|
14 | 15 | import pytest |
| 16 | +import pytz |
15 | 17 | import requests |
16 | 18 | from PIL import Image |
17 | 19 | from requests import codes |
@@ -1618,17 +1620,50 @@ class TestDateFormats: |
1618 | 1620 | > header. |
1619 | 1621 | """ |
1620 | 1622 |
|
| 1623 | + @pytest.mark.parametrize('datetime_format', [ |
| 1624 | + '%a %b %d %H:%M:%S %Y', |
| 1625 | + ]) |
1621 | 1626 | def test_date_formats( |
1622 | 1627 | self, |
1623 | 1628 | high_quality_image: io.BytesIO, |
1624 | 1629 | vuforia_database_keys: VuforiaDatabaseKeys, |
| 1630 | + datetime_format: str, |
1625 | 1631 | ) -> None: |
1626 | 1632 | image_content = high_quality_image.getvalue() |
1627 | 1633 | body = {'image': ('image.jpeg', image_content, 'image/jpeg')} |
1628 | 1634 |
|
1629 | | - response = query( |
1630 | | - vuforia_database_keys=vuforia_database_keys, |
1631 | | - body=body, |
| 1635 | + gmt = pytz.timezone('GMT') |
| 1636 | + now = datetime.datetime.now(tz=gmt) |
| 1637 | + date = now.strftime(datetime_format) |
| 1638 | + request_path = '/v1/query' |
| 1639 | + content, content_type_header = encode_multipart_formdata(body) |
| 1640 | + method = POST |
| 1641 | + |
| 1642 | + access_key = vuforia_database_keys.client_access_key |
| 1643 | + secret_key = vuforia_database_keys.client_secret_key |
| 1644 | + authorization_string = authorization_header( |
| 1645 | + access_key=access_key, |
| 1646 | + secret_key=secret_key, |
| 1647 | + method=method, |
| 1648 | + content=content, |
| 1649 | + # Note that this is not the actual Content-Type header value sent. |
| 1650 | + content_type='multipart/form-data', |
| 1651 | + date=date, |
| 1652 | + request_path=request_path, |
| 1653 | + ) |
| 1654 | + |
| 1655 | + headers = { |
| 1656 | + 'Authorization': authorization_string, |
| 1657 | + 'Date': date, |
| 1658 | + 'Content-Type': content_type_header, |
| 1659 | + } |
| 1660 | + |
| 1661 | + vwq_host = 'https://cloudreco.vuforia.com' |
| 1662 | + response = requests.request( |
| 1663 | + method=method, |
| 1664 | + url=urljoin(base=vwq_host, url=request_path), |
| 1665 | + headers=headers, |
| 1666 | + data=content, |
1632 | 1667 | ) |
1633 | 1668 |
|
1634 | 1669 | assert_query_success(response=response) |
|
0 commit comments