From 948c54222398e5617d019f53859e6f23fc3acc02 Mon Sep 17 00:00:00 2001 From: Paul Cothenet Date: Fri, 27 Aug 2021 16:30:42 -0700 Subject: [PATCH 1/8] Make tests less fragile --- test/test_estimates_api.py | 16 +++++------ test/test_rest.py | 58 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 8 deletions(-) create mode 100644 test/test_rest.py diff --git a/test/test_estimates_api.py b/test/test_estimates_api.py index 34be1fb..cb8f281 100644 --- a/test/test_estimates_api.py +++ b/test/test_estimates_api.py @@ -48,13 +48,13 @@ def test_create_and_retrieve_flight_estimate(self): Create an estimate based on the distance in meters flown by an airplane # noqa: E501 """ - distance_m = 10000000 + distance_m = 1000000 estimate = self.api.create_flight_estimate( distance_m=distance_m, create_order=True ) self.assertEqual(estimate.data.type, "flight") - self.assertEqual(estimate.data.order.mass_g, 1031697) - self.assertEqual(estimate.data.mass_g, 1031697) + self.assertGreater(estimate.data.order.mass_g, 50000) + self.assertGreater(estimate.data.mass_g, 50000) retrieved_estimate = self.api.retrieve_estimate(id=estimate.data.id) self.assertTrue(retrieved_estimate) @@ -75,7 +75,7 @@ def test_create_and_retrieve_shipping_estimate(self): ) self.assertEqual(estimate.data.order, None) self.assertEqual(estimate.data.type, "shipping") - self.assertEqual(estimate.data.mass_g, 373) + self.assertGreater(estimate.data.mass_g, 200) retrieved_estimate = self.api.retrieve_estimate(id=estimate.data.id) self.assertTrue(retrieved_estimate) @@ -85,7 +85,7 @@ def test_create_and_retrieve_vehicle_estimate(self): Create an estimate based on the vehicle distance, transportation method, and package mass # noqa: E501 """ - distance_m = 10000000 + distance_m = 1000000 make = "Toyota" model = "Corolla" year = 1995 @@ -93,7 +93,7 @@ def test_create_and_retrieve_vehicle_estimate(self): distance_m=distance_m, model=model, make=make, year=year ) self.assertEqual(estimate.data.type, "vehicle") - self.assertEqual(estimate.data.mass_g, 5719674) + self.assertGreater(estimate.data.mass_g, 50000) retrieved_estimate = self.api.retrieve_estimate(id=estimate.data.id) self.assertTrue(retrieved_estimate) @@ -103,14 +103,14 @@ def test_create_and_retrieve_vehicle_estimate_best_match(self): Create an estimate based on the vehicle with partial information # noqa: E501 """ - distance_m = 10000000 + distance_m = 1000000 make = "Toyota" model = "Corolla" estimate = self.api.create_vehicle_estimate( distance_m=distance_m, model=model, make=make ) self.assertEqual(estimate.data.type, "vehicle") - self.assertEqual(estimate.data.mass_g, 6499629) + self.assertGreater(estimate.data.mass_g, 50000) retrieved_estimate = self.api.retrieve_estimate(id=estimate.data.id) self.assertTrue(retrieved_estimate) diff --git a/test/test_rest.py b/test/test_rest.py new file mode 100644 index 0000000..490b7a9 --- /dev/null +++ b/test/test_rest.py @@ -0,0 +1,58 @@ +from __future__ import absolute_import + +from patch_api.configuration import Configuration +from patch_api import rest + +import unittest +import os + +from patch_api.api_client import ApiClient + + +class TestRESTClientObject(unittest.TestCase): + def test_recursive_urlencode(self): + """Test that the correct query params get encoded""" + + api_key = os.environ.get("SANDBOX_API_KEY") + configuration = Configuration() + client = rest.RESTClientObject(api_key, configuration) + + encoded_params = client.recursive_urlencode({}) + self.assertEqual(encoded_params, "") + + encoded_params = client.recursive_urlencode({"page": 1}) + self.assertEqual(encoded_params, "page=1") + + encoded_params = client.recursive_urlencode({"string": "value"}) + self.assertEqual(encoded_params, "string=value") + + encoded_params = client.recursive_urlencode( + {"multiple": "values", "top": "level"} + ) + self.assertEqual(encoded_params, "multiple=values&top=level") + + encoded_params = client.recursive_urlencode({"metadata": {"some": "arg"}}) + self.assertEqual(encoded_params, "metadata[some]=arg") + + encoded_params = client.recursive_urlencode( + {"deeply": {"nested": {"hash": {"of": "args"}}}} + ) + self.assertEqual(encoded_params, "deeply[nested][hash][of]=args") + + def test_encoded_query_params(self): + """Test that the correct query params get encoded""" + + api_key = os.environ.get("SANDBOX_API_KEY") + configuration = Configuration() + client = rest.RESTClientObject(api_key, configuration) + + encoded_params = client.encoded_query_params([]) + self.assertEqual(encoded_params, "") + + encoded_params = client.encoded_query_params([("mass_g", 100)]) + self.assertEqual(encoded_params, "?mass_g=100") + + encoded_params = client.encoded_query_params( + [("mass_g", 100), ("metadata", {"external_id": "abc-123"})] + ) + self.assertEqual(encoded_params, "?metadata[external_id]=abc-123&mass_g=100") From 90eb7cbdfde7cdf95edb3bc5462de9f983069fee Mon Sep 17 00:00:00 2001 From: Paul Cothenet Date: Fri, 27 Aug 2021 16:43:03 -0700 Subject: [PATCH 2/8] Make tests less fragile --- test/test_projects_api.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/test_projects_api.py b/test/test_projects_api.py index a01aa6e..a9147b8 100644 --- a/test/test_projects_api.py +++ b/test/test_projects_api.py @@ -51,6 +51,8 @@ def test_retrieve_projects(self): if len(projects) > 0: project = projects[0] + print(project) + self.assertEqual(project.production, False) self.assertGreater(project.average_price_per_tonne_cents_usd, 0) self.assertGreater(project.remaining_mass_g, 0) From 2b6ef72891ae89d02cda8374bbc887e27da00459 Mon Sep 17 00:00:00 2001 From: Paul Cothenet Date: Fri, 27 Aug 2021 16:45:45 -0700 Subject: [PATCH 3/8] Remove unwanted addition --- test/test_rest.py | 58 ----------------------------------------------- 1 file changed, 58 deletions(-) delete mode 100644 test/test_rest.py diff --git a/test/test_rest.py b/test/test_rest.py deleted file mode 100644 index 490b7a9..0000000 --- a/test/test_rest.py +++ /dev/null @@ -1,58 +0,0 @@ -from __future__ import absolute_import - -from patch_api.configuration import Configuration -from patch_api import rest - -import unittest -import os - -from patch_api.api_client import ApiClient - - -class TestRESTClientObject(unittest.TestCase): - def test_recursive_urlencode(self): - """Test that the correct query params get encoded""" - - api_key = os.environ.get("SANDBOX_API_KEY") - configuration = Configuration() - client = rest.RESTClientObject(api_key, configuration) - - encoded_params = client.recursive_urlencode({}) - self.assertEqual(encoded_params, "") - - encoded_params = client.recursive_urlencode({"page": 1}) - self.assertEqual(encoded_params, "page=1") - - encoded_params = client.recursive_urlencode({"string": "value"}) - self.assertEqual(encoded_params, "string=value") - - encoded_params = client.recursive_urlencode( - {"multiple": "values", "top": "level"} - ) - self.assertEqual(encoded_params, "multiple=values&top=level") - - encoded_params = client.recursive_urlencode({"metadata": {"some": "arg"}}) - self.assertEqual(encoded_params, "metadata[some]=arg") - - encoded_params = client.recursive_urlencode( - {"deeply": {"nested": {"hash": {"of": "args"}}}} - ) - self.assertEqual(encoded_params, "deeply[nested][hash][of]=args") - - def test_encoded_query_params(self): - """Test that the correct query params get encoded""" - - api_key = os.environ.get("SANDBOX_API_KEY") - configuration = Configuration() - client = rest.RESTClientObject(api_key, configuration) - - encoded_params = client.encoded_query_params([]) - self.assertEqual(encoded_params, "") - - encoded_params = client.encoded_query_params([("mass_g", 100)]) - self.assertEqual(encoded_params, "?mass_g=100") - - encoded_params = client.encoded_query_params( - [("mass_g", 100), ("metadata", {"external_id": "abc-123"})] - ) - self.assertEqual(encoded_params, "?metadata[external_id]=abc-123&mass_g=100") From e6fc0914b7711338969810475eacc7fc2b78b83c Mon Sep 17 00:00:00 2001 From: Paul Cothenet Date: Fri, 27 Aug 2021 16:55:52 -0700 Subject: [PATCH 4/8] Update User-Agent --- CHANGELOG.md | 5 +++++ patch_api/__init__.py | 2 +- patch_api/api_client.py | 2 +- patch_api/configuration.py | 4 +++- setup.py | 2 +- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e4245b..bfcaed7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.10.0] - 2021-08-27 + +### Added + +- Adds a custom User-Agent header ## [1.9.0] - 2021-08-17 ### Added diff --git a/patch_api/__init__.py b/patch_api/__init__.py index fffe9b3..a7c5e5e 100644 --- a/patch_api/__init__.py +++ b/patch_api/__init__.py @@ -15,7 +15,7 @@ from __future__ import absolute_import -__version__ = "1.9.0" +__version__ = "1.10.0" # import ApiClient from patch_api.api_client import ApiClient diff --git a/patch_api/api_client.py b/patch_api/api_client.py index c3e4256..d7ab6d2 100644 --- a/patch_api/api_client.py +++ b/patch_api/api_client.py @@ -91,7 +91,7 @@ def __init__( self.default_headers[header_name] = header_value self.cookie = cookie # Set default User-Agent. - self.user_agent = "OpenAPI-Generator/1.9.0/python" + self.user_agent = "patch-python/1.10.0" def __del__(self): if self._pool: diff --git a/patch_api/configuration.py b/patch_api/configuration.py index 3ae9bee..a2797c0 100644 --- a/patch_api/configuration.py +++ b/patch_api/configuration.py @@ -341,7 +341,9 @@ def to_debug_report(self): "OS: {env}\n" "Python Version: {pyversion}\n" "Version of the API: v1\n" - "SDK Package Version: 1.9.0".format(env=sys.platform, pyversion=sys.version) + "SDK Package Version: 1.10.0".format( + env=sys.platform, pyversion=sys.version + ) ) def get_host_settings(self): diff --git a/setup.py b/setup.py index f4070af..9c81bc2 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ from setuptools import setup, find_packages # noqa: H301 NAME = "patch-api" -VERSION = "1.9.0" +VERSION = "1.10.0" # To install the library, run the following # # python setup.py install From 0250edd2ef6078378193c233eb9eea4f52b9d69e Mon Sep 17 00:00:00 2001 From: Paul Cothenet Date: Fri, 27 Aug 2021 16:58:45 -0700 Subject: [PATCH 5/8] Remove comment --- test/test_projects_api.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/test_projects_api.py b/test/test_projects_api.py index e69865e..11f2d90 100644 --- a/test/test_projects_api.py +++ b/test/test_projects_api.py @@ -51,8 +51,6 @@ def test_retrieve_projects(self): if len(projects) > 0: project = projects[0] - print(project) - self.assertEqual(project.production, False) self.assertGreater(project.average_price_per_tonne_cents_usd, 0) self.assertGreater(project.remaining_mass_g, 0) From e90a393ca609f3e8e9726be3242ca0f2368a731d Mon Sep 17 00:00:00 2001 From: Paul Cothenet Date: Fri, 27 Aug 2021 17:05:29 -0700 Subject: [PATCH 6/8] Re-add tests --- test/test_rest.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 test/test_rest.py diff --git a/test/test_rest.py b/test/test_rest.py new file mode 100644 index 0000000..b21b99a --- /dev/null +++ b/test/test_rest.py @@ -0,0 +1,58 @@ +from __future__ import absolute_import + +from patch_api.configuration import Configuration +from patch_api import rest + +import unittest +import os + +from patch_api.api_client import ApiClient + + +class TestRESTClientObject(unittest.TestCase): + def test_recursive_urlencode(self): + """Test that the correct query params get encoded""" + + api_key = os.environ.get("SANDBOX_API_KEY") + configuration = Configuration() + client = rest.RESTClientObject(api_key, configuration) + + encoded_params = client.recursive_urlencode({}) + self.assertEqual(encoded_params, "") + + encoded_params = client.recursive_urlencode({"page": 1}) + self.assertEqual(encoded_params, "page=1") + + encoded_params = client.recursive_urlencode({"string": "value"}) + self.assertEqual(encoded_params, "string=value") + + encoded_params = client.recursive_urlencode( + {"multiple": "values", "top": "level"} + ) + self.assertEqual(encoded_params, "multiple=values&top=level") + + encoded_params = client.recursive_urlencode({"metadata": {"some": "arg"}}) + self.assertEqual(encoded_params, "metadata[some]=arg") + + encoded_params = client.recursive_urlencode( + {"deeply": {"nested": {"hash": {"of": "args"}}}} + ) + self.assertEqual(encoded_params, "deeply[nested][hash][of]=args") + + def test_encoded_query_params(self): + """Test that the correct query params get encoded""" + + api_key = os.environ.get("SANDBOX_API_KEY") + configuration = Configuration() + client = rest.RESTClientObject(api_key, configuration) + + encoded_params = client.encoded_query_params([]) + self.assertEqual(encoded_params, "") + + encoded_params = client.encoded_query_params([("mass_g", 100)]) + self.assertEqual(encoded_params, "?mass_g=100") + + encoded_params = client.encoded_query_params( + [("mass_g", 100), ("metadata", {"external_id": "abc-123"})] + ) + self.assertEqual(encoded_params, "?metadata[external_id]=abc-123&mass_g=100") \ No newline at end of file From fd85aa67940ee4e58bd9dfe1624c489dfb58fbc2 Mon Sep 17 00:00:00 2001 From: Paul Cothenet Date: Fri, 27 Aug 2021 17:16:30 -0700 Subject: [PATCH 7/8] Lint --- test/test_rest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_rest.py b/test/test_rest.py index b21b99a..490b7a9 100644 --- a/test/test_rest.py +++ b/test/test_rest.py @@ -55,4 +55,4 @@ def test_encoded_query_params(self): encoded_params = client.encoded_query_params( [("mass_g", 100), ("metadata", {"external_id": "abc-123"})] ) - self.assertEqual(encoded_params, "?metadata[external_id]=abc-123&mass_g=100") \ No newline at end of file + self.assertEqual(encoded_params, "?metadata[external_id]=abc-123&mass_g=100") From d902f5d0e8c37dcbe3ec2c0b0203c948747279fd Mon Sep 17 00:00:00 2001 From: Paul Cothenet Date: Mon, 30 Aug 2021 08:57:03 -0700 Subject: [PATCH 8/8] Update CHANGELOG.md Co-authored-by: James Klein --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bfcaed7..884c470 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Adds a custom User-Agent header + ## [1.9.0] - 2021-08-17 ### Added