From 740b6065304fa9fcb295f7b99fbce738493bf595 Mon Sep 17 00:00:00 2001 From: mr-palindrome Date: Sat, 14 Oct 2023 20:55:28 +0530 Subject: [PATCH 1/2] feat: added missing regenerate api key method in Environments --- novu/api/environment.py | 12 ++++++++++++ tests/api/test_environment.py | 17 +++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/novu/api/environment.py b/novu/api/environment.py index a1359e67..7fbccdeb 100644 --- a/novu/api/environment.py +++ b/novu/api/environment.py @@ -67,3 +67,15 @@ def api_keys(self) -> Iterator[EnvironmentApiKeyDto]: results = self.handle_request("GET", f"{self._environment_url}/api-keys")["data"] for result in results: yield EnvironmentApiKeyDto.from_camel_case(result) + + def regenerate_api_key(self) -> Iterator[EnvironmentApiKeyDto]: + """Regenerate an environment api key + + Yields: + Mapped environment's api key + """ + results = self.handle_request("POST", f"{self._environment_url}/api-keys/regenerate")["data"] + if not isinstance(results, list): + results = [results] + for result in results: + yield EnvironmentApiKeyDto.from_camel_case(result) diff --git a/tests/api/test_environment.py b/tests/api/test_environment.py index a5513c30..5a650258 100644 --- a/tests/api/test_environment.py +++ b/tests/api/test_environment.py @@ -129,3 +129,20 @@ def test_list_environment_api_keys(self, mock_request: mock.MagicMock) -> None: params=None, timeout=5, ) + + @mock.patch("requests.request") + def test_regenerate_api_key(self, mock_request: mock.MagicMock) -> None: + mock_request.return_value = MockResponse(200, {"data": self.response_json_api_key}) + + res = self.api.regenerate_api_key() + self.assertIsInstance(res, types.GeneratorType) + self.assertEqual(list(res), [self.expected_dto_api_key]) + + mock_request.assert_called_once_with( + method="POST", + url="sample.novu.com/v1/environments/api-keys/regenerate", + headers={"Authorization": "ApiKey api-key"}, + json=None, + params=None, + timeout=5, + ) From b31ae5623ef98ddc93022c0959f02487d2157da7 Mon Sep 17 00:00:00 2001 From: Oscar MARIE--TAILLEFER Date: Sat, 14 Oct 2023 17:44:00 +0200 Subject: [PATCH 2/2] fix: api only return list --- novu/api/environment.py | 2 -- tests/api/test_environment.py | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/novu/api/environment.py b/novu/api/environment.py index 7fbccdeb..b5e446af 100644 --- a/novu/api/environment.py +++ b/novu/api/environment.py @@ -75,7 +75,5 @@ def regenerate_api_key(self) -> Iterator[EnvironmentApiKeyDto]: Mapped environment's api key """ results = self.handle_request("POST", f"{self._environment_url}/api-keys/regenerate")["data"] - if not isinstance(results, list): - results = [results] for result in results: yield EnvironmentApiKeyDto.from_camel_case(result) diff --git a/tests/api/test_environment.py b/tests/api/test_environment.py index 5a650258..fc1a3403 100644 --- a/tests/api/test_environment.py +++ b/tests/api/test_environment.py @@ -132,7 +132,7 @@ def test_list_environment_api_keys(self, mock_request: mock.MagicMock) -> None: @mock.patch("requests.request") def test_regenerate_api_key(self, mock_request: mock.MagicMock) -> None: - mock_request.return_value = MockResponse(200, {"data": self.response_json_api_key}) + mock_request.return_value = MockResponse(200, {"data": [self.response_json_api_key]}) res = self.api.regenerate_api_key() self.assertIsInstance(res, types.GeneratorType)