From 75257d0ca161853aa3c1e4119a59ee328708609b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Pablo=20Castro=20Leal?= Date: Mon, 8 Apr 2024 15:12:58 -0400 Subject: [PATCH 1/6] feature(versioning): Add versioning to client --- fintoc/client.py | 16 +++++++++++++--- fintoc/core.py | 4 ++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/fintoc/client.py b/fintoc/client.py index 3e0e43d..2653abf 100644 --- a/fintoc/client.py +++ b/fintoc/client.py @@ -10,15 +10,15 @@ class Client: - """Encapsulates the client behaviour and methods.""" - def __init__(self, base_url, api_key, user_agent, params={}): + def __init__(self, base_url, api_key, api_version, user_agent, params={}): self.base_url = base_url self.api_key = api_key self.user_agent = user_agent self.params = params self.__client = None + self.api_version = api_version @property def _client(self): @@ -33,7 +33,15 @@ def _client(self): @property def headers(self): """Return the appropriate headers for every request.""" - return {"Authorization": self.api_key, "User-Agent": self.user_agent} + headers = { + "Authorization": self.api_key, + "User-Agent": self.user_agent, + } + + if self.api_version is not None: + headers["Fintoc-Version"] = self.api_version + + return headers def request(self, path, paginated=False, method="get", params=None, json=None): """ @@ -52,6 +60,7 @@ def extend( self, base_url=None, api_key=None, + api_version=None, user_agent=None, params=None, ): @@ -62,6 +71,7 @@ def extend( return Client( base_url=base_url or self.base_url, api_key=api_key or self.api_key, + api_version=api_version or self.api_version, user_agent=user_agent or self.user_agent, params={**self.params, **params} if params else self.params, ) diff --git a/fintoc/core.py b/fintoc/core.py index db9e705..9146bc2 100644 --- a/fintoc/core.py +++ b/fintoc/core.py @@ -16,13 +16,13 @@ class Fintoc: - """Encapsulates the core object's behaviour and methods.""" - def __init__(self, api_key): + def __init__(self, api_key, api_version=None): self._client = Client( base_url=f"{API_BASE_URL}/{API_VERSION}", api_key=api_key, + api_version=api_version, user_agent=f"fintoc-python/{__version__}", ) self.charges = ChargesManager("/charges", self._client) From 330ea48591c285b886d189ed11c08eb829c009df Mon Sep 17 00:00:00 2001 From: Francisco Cumsille Date: Tue, 9 Apr 2024 13:11:22 -0400 Subject: [PATCH 2/6] tests(version): add tests to fintoc version header --- tests/managers/test_links_manager.py | 2 ++ tests/mixins/test_manager_mixin.py | 6 ++++++ tests/mixins/test_resource_mixin.py | 6 ++++++ tests/resources/test_account.py | 2 ++ tests/resources/test_link.py | 2 ++ tests/test_client.py | 28 ++++++++++++++++++++++++---- tests/test_core.py | 3 ++- 7 files changed, 44 insertions(+), 5 deletions(-) diff --git a/tests/managers/test_links_manager.py b/tests/managers/test_links_manager.py index 1dfe26d..83bf8c1 100644 --- a/tests/managers/test_links_manager.py +++ b/tests/managers/test_links_manager.py @@ -12,11 +12,13 @@ def patch_http_client(self, patch_http_client): def setup_method(self): self.base_url = "https://test.com" self.api_key = "super_secret_api_key" + self.api_version = None self.user_agent = "fintoc-python/test" self.params = {"first_param": "first_value", "second_param": "second_value"} self.client = Client( self.base_url, self.api_key, + self.api_version, self.user_agent, params=self.params, ) diff --git a/tests/mixins/test_manager_mixin.py b/tests/mixins/test_manager_mixin.py index 59342e9..346ac2b 100644 --- a/tests/mixins/test_manager_mixin.py +++ b/tests/mixins/test_manager_mixin.py @@ -57,11 +57,13 @@ def patch_http_client(self, patch_http_client): def setup_method(self): self.base_url = "https://test.com" self.api_key = "super_secret_api_key" + self.api_version = None self.user_agent = "fintoc-python/test" self.params = {"first_param": "first_value", "second_param": "second_value"} self.client = Client( self.base_url, self.api_key, + self.api_version, self.user_agent, params=self.params, ) @@ -95,11 +97,13 @@ def patch_http_client(self, patch_http_client): def setup_method(self): self.base_url = "https://test.com" self.api_key = "super_secret_api_key" + self.api_version = None self.user_agent = "fintoc-python/test" self.params = {"first_param": "first_value", "second_param": "second_value"} self.client = Client( self.base_url, self.api_key, + self.api_version, self.user_agent, params=self.params, ) @@ -148,11 +152,13 @@ def patch_http_client(self, patch_http_client): def setup_method(self): self.base_url = "https://test.com" self.api_key = "super_secret_api_key" + self.api_version = None self.user_agent = "fintoc-python/test" self.params = {"first_param": "first_value", "second_param": "second_value"} self.client = Client( self.base_url, self.api_key, + self.api_version, self.user_agent, params=self.params, ) diff --git a/tests/mixins/test_resource_mixin.py b/tests/mixins/test_resource_mixin.py index 2086608..d0bd99d 100644 --- a/tests/mixins/test_resource_mixin.py +++ b/tests/mixins/test_resource_mixin.py @@ -22,11 +22,13 @@ def patch_http_client(self, patch_http_client): def setup_method(self): self.base_url = "https://test.com" self.api_key = "super_secret_api_key" + self.api_version = None self.user_agent = "fintoc-python/test" self.params = {"first_param": "first_value", "second_param": "second_value"} self.client = Client( self.base_url, self.api_key, + self.api_version, self.user_agent, params=self.params, ) @@ -108,11 +110,13 @@ def patch_http_client(self, patch_http_client): def setup_method(self): self.base_url = "https://test.com" self.api_key = "super_secret_api_key" + self.api_version = None self.user_agent = "fintoc-python/test" self.params = {"first_param": "first_value", "second_param": "second_value"} self.client = Client( self.base_url, self.api_key, + self.api_version, self.user_agent, params=self.params, ) @@ -159,11 +163,13 @@ def patch_http_client(self, patch_http_client): def setup_method(self): self.base_url = "https://test.com" self.api_key = "super_secret_api_key" + self.api_version = None self.user_agent = "fintoc-python/test" self.params = {"first_param": "first_value", "second_param": "second_value"} self.client = Client( self.base_url, self.api_key, + self.api_version, self.user_agent, params=self.params, ) diff --git a/tests/resources/test_account.py b/tests/resources/test_account.py index cfa4496..e04fb92 100644 --- a/tests/resources/test_account.py +++ b/tests/resources/test_account.py @@ -9,11 +9,13 @@ class TestAccountResource: def setup_method(self): self.base_url = "https://test.com" self.api_key = "super_secret_api_key" + self.api_version = None self.user_agent = "fintoc-python/test" self.params = {"first_param": "first_value", "second_param": "second_value"} self.client = Client( self.base_url, self.api_key, + self.api_version, self.user_agent, params=self.params, ) diff --git a/tests/resources/test_link.py b/tests/resources/test_link.py index b8ff611..bde1486 100644 --- a/tests/resources/test_link.py +++ b/tests/resources/test_link.py @@ -9,11 +9,13 @@ class TestLinkResource: def setup_method(self): self.base_url = "https://test.com" self.api_key = "super_secret_api_key" + self.api_version = None self.user_agent = "fintoc-python/test" self.params = {"first_param": "first_value", "second_param": "second_value"} self.client = Client( self.base_url, self.api_key, + self.api_version, self.user_agent, params=self.params, ) diff --git a/tests/test_client.py b/tests/test_client.py index 149c661..3b1b9be 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -12,11 +12,19 @@ def setup_method(self): self.api_key = "super_secret_api_key" self.user_agent = "fintoc-python/test" self.params = {"first_param": "first_value", "second_param": "second_value"} + self.api_version = None - def create_client(self, params=False): + def create_client(self, params=False, api_version=None): if not params: - return Client(self.base_url, self.api_key, self.user_agent) - return Client(self.base_url, self.api_key, self.user_agent, params=self.params) + return Client(self.base_url, self.api_key, api_version, self.user_agent) + + return Client( + self.base_url, + self.api_key, + self.api_version, + self.user_agent, + params=self.params, + ) def test_client_creation_without_params(self): client = self.create_client() @@ -34,7 +42,17 @@ def test_client_creation_with_params(self): assert client.user_agent == self.user_agent assert client.params == self.params - def test_client_headers(self): + def test_client_headers_with_api_version(self): + client = self.create_client(api_version="2023-01-01") + assert isinstance(client.headers, dict) + assert len(client.headers.keys()) == 3 + assert "Authorization" in client.headers + assert "User-Agent" in client.headers + assert client.headers["Authorization"] == self.api_key + assert client.headers["User-Agent"] == self.user_agent + assert client.headers["Fintoc-Version"] == "2023-01-01" + + def test_client_headers_without_api_version(self): client = self.create_client() assert isinstance(client.headers, dict) assert len(client.headers.keys()) == 2 @@ -87,11 +105,13 @@ def patch_http_client(self, patch_http_client): def setup_method(self): self.base_url = "https://test.com" self.api_key = "super_secret_api_key" + self.api_version = None self.user_agent = "fintoc-python/test" self.params = {"first_param": "first_value", "second_param": "second_value"} self.client = Client( self.base_url, self.api_key, + self.api_version, self.user_agent, params=self.params, ) diff --git a/tests/test_core.py b/tests/test_core.py index b72baba..754b1c8 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -7,7 +7,8 @@ class TestCoreFintocObject: def test_object_creations(self): # pylint: disable=protected-access api_key = "super_secret_api_key" - fintoc = Fintoc(api_key) + api_version = "2023-01-01" + fintoc = Fintoc(api_key, api_version) assert isinstance(fintoc._client, Client) assert isinstance(fintoc.links, ManagerMixin) assert isinstance(fintoc.webhook_endpoints, ManagerMixin) From 27fb32d72de02027f6a4ff5fd02c5561f2eef354 Mon Sep 17 00:00:00 2001 From: Francisco Cumsille Date: Tue, 9 Apr 2024 14:55:38 -0400 Subject: [PATCH 3/6] fixup! feature(versioning): Add versioning to client --- fintoc/client.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fintoc/client.py b/fintoc/client.py index 2653abf..186ed27 100644 --- a/fintoc/client.py +++ b/fintoc/client.py @@ -60,7 +60,6 @@ def extend( self, base_url=None, api_key=None, - api_version=None, user_agent=None, params=None, ): @@ -71,7 +70,7 @@ def extend( return Client( base_url=base_url or self.base_url, api_key=api_key or self.api_key, - api_version=api_version or self.api_version, + api_version=self.api_version, user_agent=user_agent or self.user_agent, params={**self.params, **params} if params else self.params, ) From 705390104d5800df55ff62a6b231e274a160661b Mon Sep 17 00:00:00 2001 From: Francisco Cumsille Date: Tue, 9 Apr 2024 14:55:52 -0400 Subject: [PATCH 4/6] fixup! tests(version): add tests to fintoc version header --- tests/test_core.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/test_core.py b/tests/test_core.py index 754b1c8..0a742ac 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -7,8 +7,20 @@ class TestCoreFintocObject: def test_object_creations(self): # pylint: disable=protected-access api_key = "super_secret_api_key" - api_version = "2023-01-01" - fintoc = Fintoc(api_key, api_version) + fintoc = Fintoc(api_key) assert isinstance(fintoc._client, Client) assert isinstance(fintoc.links, ManagerMixin) assert isinstance(fintoc.webhook_endpoints, ManagerMixin) + + def test_fintoc_creation_with_api_version(self): + # pylint: disable=protected-access + api_key = "super_secret_api_key" + api_version = "2023-01-01" + fintoc = Fintoc(api_key, api_version) + assert fintoc._client.headers["Fintoc-Version"] == api_version + + def test_fintoc_creation_without_api_version(self): + # pylint: disable=protected-access + api_key = "super_secret_api_key" + fintoc = Fintoc(api_key) + assert "Fintoc-Version" not in fintoc._client.headers From 4d8731d9f318d93b4d6553e54f8292f6693a8142 Mon Sep 17 00:00:00 2001 From: Francisco Cumsille Date: Tue, 9 Apr 2024 15:06:53 -0400 Subject: [PATCH 5/6] pre-release: prepare 2.4.0 release --- fintoc/version.py | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fintoc/version.py b/fintoc/version.py index e098f95..d704f7f 100644 --- a/fintoc/version.py +++ b/fintoc/version.py @@ -1,4 +1,4 @@ """Module to hold the version utilities.""" -version_info = (2, 3, 0) +version_info = (2, 4, 0) __version__ = ".".join([str(x) for x in version_info]) diff --git a/pyproject.toml b/pyproject.toml index d658bf5..5e3dacf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "fintoc" -version = "2.3.0" +version = "2.4.0" description = "The official Python client for the Fintoc API." authors = ["Daniel Leal ", "Nebil Kawas "] maintainers = ["Daniel Leal "] From 4092243794ef87e369d53706a0c73ac50ef5379f Mon Sep 17 00:00:00 2001 From: Francisco Cumsille Date: Tue, 9 Apr 2024 17:20:44 -0400 Subject: [PATCH 6/6] fix(ci): remove upload coverage --- .github/workflows/tests.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a650969..5094692 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -42,9 +42,3 @@ jobs: - name: Run Pytest run: make tests - - - name: Upload coverage to CodeCov - uses: codecov/codecov-action@v3 - with: - fail_ci_if_error: true - verbose: true