From 87f68dfd18c560c4ed1614257b7396bd9be5b011 Mon Sep 17 00:00:00 2001 From: Ben Woods Date: Sun, 6 Aug 2023 00:27:03 -0500 Subject: [PATCH 1/2] Adding assistant management methods to UserV2, with tests and README update. --- README.md | 4 ++ .../components/user/test_add_assistants.py | 45 +++++++++++++++++++ .../user/test_delete_all_assistants.py | 36 +++++++++++++++ .../components/user/test_delete_assistant.py | 42 +++++++++++++++++ .../components/user/test_list_assistants.py | 38 ++++++++++++++++ zoomus/components/user.py | 31 +++++++++++++ 6 files changed, 196 insertions(+) create mode 100644 tests/zoomus/components/user/test_add_assistants.py create mode 100644 tests/zoomus/components/user/test_delete_all_assistants.py create mode 100644 tests/zoomus/components/user/test_delete_assistant.py create mode 100644 tests/zoomus/components/user/test_list_assistants.py diff --git a/README.md b/README.md index 8eb9619..ee14ab0 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,10 @@ with ZoomClient('API_KEY', 'API_SECRET', 'ACCOUNT_ID') as client: * client.user.get_by_email(...) * client.user.get_settings(...) * client.user.update_settings(...) +* client.user.add_assistants(...) +* client.user.delete_all_assistants(...) +* client.user.delete_assistant(...) +* client.user.list_assistants(...) * client.meeting.get(...) * client.meeting.end(...) diff --git a/tests/zoomus/components/user/test_add_assistants.py b/tests/zoomus/components/user/test_add_assistants.py new file mode 100644 index 0000000..e10fcc4 --- /dev/null +++ b/tests/zoomus/components/user/test_add_assistants.py @@ -0,0 +1,45 @@ +import unittest + +from zoomus import components, util +import responses + + +def suite(): + """Define all the tests of the module.""" + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(AddAssistantsV2TestCase)) + return suite + + +class AddAssistantsV2TestCase(unittest.TestCase): + def setUp(self): + self.component = components.user.UserComponentV2( + base_uri="http://foo.com", + config={ + "api_key": "KEY", + "api_secret": "SECRET", + "version": util.API_VERSION_2, + }, + ) + + @responses.activate + def test_can_add_assistants(self): + responses.add(responses.POST, "http://foo.com/users/ID/assistants") + response = self.component.add_assistants( + id="ID", assistants=[{"email": "foo@bar.com"}] + ) + self.assertEqual( + response.request.body, '{"assistants": [{"email": "foo@bar.com"}]}' + ) + + def test_requires_id(self): + with self.assertRaisesRegexp(ValueError, "'id' must be set"): + self.component.add_assistants(assistants=[{"email": "foo@bar.com"}]) + + def test_requires_assistants(self): + with self.assertRaisesRegexp(ValueError, "'assistants' must be set"): + self.component.add_assistants(id="ID") + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/zoomus/components/user/test_delete_all_assistants.py b/tests/zoomus/components/user/test_delete_all_assistants.py new file mode 100644 index 0000000..fee08b6 --- /dev/null +++ b/tests/zoomus/components/user/test_delete_all_assistants.py @@ -0,0 +1,36 @@ +import unittest + +from zoomus import components, util +import responses + + +def suite(): + """Define all the tests of the module.""" + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(DeleteAllAssistantsV2TestCase)) + return suite + + +class DeleteAllAssistantsV2TestCase(unittest.TestCase): + def setUp(self): + self.component = components.user.UserComponentV2( + base_uri="http://foo.com", + config={ + "api_key": "KEY", + "api_secret": "SECRET", + "version": util.API_VERSION_2, + }, + ) + + @responses.activate + def test_can_delete_all_assistants(self): + responses.add(responses.DELETE, "http://foo.com/users/ID/assistants") + response = self.component.delete_all_assistants(id="ID") + + def test_requires_id(self): + with self.assertRaisesRegexp(ValueError, "'id' must be set"): + self.component.delete_all_assistants() + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/zoomus/components/user/test_delete_assistant.py b/tests/zoomus/components/user/test_delete_assistant.py new file mode 100644 index 0000000..1d309c9 --- /dev/null +++ b/tests/zoomus/components/user/test_delete_assistant.py @@ -0,0 +1,42 @@ +import unittest + +from zoomus import components, util +import responses + + +def suite(): + """Define all the tests of the module.""" + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(DeleteAssistantV2TestCase)) + return suite + + +class DeleteAssistantV2TestCase(unittest.TestCase): + def setUp(self): + self.component = components.user.UserComponentV2( + base_uri="http://foo.com", + config={ + "api_key": "KEY", + "api_secret": "SECRET", + "version": util.API_VERSION_2, + }, + ) + + @responses.activate + def test_can_add_assistants(self): + responses.add(responses.DELETE, "http://foo.com/users/ID/assistants/ASSISTID") + response = self.component.delete_assistant( + id="ID", assistant_id="ASSISTID" + ) + + def test_requires_id(self): + with self.assertRaisesRegexp(ValueError, "'id' must be set"): + self.component.delete_assistant(assistant_id="ASSISTID") + + def test_requires_assistant_id(self): + with self.assertRaisesRegexp(ValueError, "'assistant_id' must be set"): + self.component.delete_assistant(id="ID") + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/zoomus/components/user/test_list_assistants.py b/tests/zoomus/components/user/test_list_assistants.py new file mode 100644 index 0000000..96b8120 --- /dev/null +++ b/tests/zoomus/components/user/test_list_assistants.py @@ -0,0 +1,38 @@ +import unittest + +from zoomus import components, util +import responses + + +def suite(): + """Define all the tests of the module.""" + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(ListAssistantV2TestCase)) + return suite + + +class ListAssistantV2TestCase(unittest.TestCase): + def setUp(self): + self.component = components.user.UserComponentV2( + base_uri="http://foo.com", + config={ + "api_key": "KEY", + "api_secret": "SECRET", + "version": util.API_VERSION_2, + }, + ) + + @responses.activate + def test_can_list_assistants(self): + responses.add(responses.GET, "http://foo.com/users/ID/assistants") + response = self.component.list_assistants( + id="ID" + ) + + def test_requires_id(self): + with self.assertRaisesRegexp(ValueError, "'id' must be set"): + self.component.list_assistants(assistant_id="ASSISTID") + + +if __name__ == "__main__": + unittest.main() diff --git a/zoomus/components/user.py b/zoomus/components/user.py index 75f18c6..ed3ddab 100644 --- a/zoomus/components/user.py +++ b/zoomus/components/user.py @@ -112,3 +112,34 @@ def get_settings(self, **kwargs): return self.get_request( "/users/{}/settings".format(kwargs.pop("id")), params=kwargs ) + + def add_assistants(self, **kwargs): + util.require_keys(kwargs, ["id", "assistants"]) + body = { + "assistants": kwargs['assistants'] + } + + return self.post_request( + "/users/{}/assistants".format(kwargs.pop("id")), data=kwargs + ) + + def list_assistants(self, **kwargs): + util.require_keys(kwargs, "id") + + return self.get_request( + "/users/{}/assistants".format(kwargs.pop("id")) + ) + + def delete_assistant(self, **kwargs): + util.require_keys(kwargs, ["id", "assistant_id"]) + + return self.delete_request( + "/users/{id}/assistants/{assistant_id}".format(id=kwargs.pop("id"), assistant_id=kwargs['assistant_id']) + ) + + def delete_all_assistants(self, **kwargs): + util.require_keys(kwargs, "id") + + return self.delete_request( + "/users/{}/assistants".format(kwargs.pop("id")) + ) From 99fda8addcd29de6327fbb5f573d6a4c8da40bbd Mon Sep 17 00:00:00 2001 From: Ben Woods Date: Sun, 6 Aug 2023 00:34:09 -0500 Subject: [PATCH 2/2] Formatting changes to make black happy. --- .../components/user/test_delete_assistant.py | 4 +--- .../components/user/test_list_assistants.py | 4 +--- tests/zoomus/test_client.py | 15 ++++++++---- tests/zoomus/test_util.py | 1 - zoomus/components/user.py | 24 ++++++++----------- 5 files changed, 23 insertions(+), 25 deletions(-) diff --git a/tests/zoomus/components/user/test_delete_assistant.py b/tests/zoomus/components/user/test_delete_assistant.py index 1d309c9..3e664a3 100644 --- a/tests/zoomus/components/user/test_delete_assistant.py +++ b/tests/zoomus/components/user/test_delete_assistant.py @@ -25,9 +25,7 @@ def setUp(self): @responses.activate def test_can_add_assistants(self): responses.add(responses.DELETE, "http://foo.com/users/ID/assistants/ASSISTID") - response = self.component.delete_assistant( - id="ID", assistant_id="ASSISTID" - ) + response = self.component.delete_assistant(id="ID", assistant_id="ASSISTID") def test_requires_id(self): with self.assertRaisesRegexp(ValueError, "'id' must be set"): diff --git a/tests/zoomus/components/user/test_list_assistants.py b/tests/zoomus/components/user/test_list_assistants.py index 96b8120..cfb1f1d 100644 --- a/tests/zoomus/components/user/test_list_assistants.py +++ b/tests/zoomus/components/user/test_list_assistants.py @@ -25,9 +25,7 @@ def setUp(self): @responses.activate def test_can_list_assistants(self): responses.add(responses.GET, "http://foo.com/users/ID/assistants") - response = self.component.list_assistants( - id="ID" - ) + response = self.component.list_assistants(id="ID") def test_requires_id(self): with self.assertRaisesRegexp(ValueError, "'id' must be set"): diff --git a/tests/zoomus/test_client.py b/tests/zoomus/test_client.py index a24b750..4f77a4a 100644 --- a/tests/zoomus/test_client.py +++ b/tests/zoomus/test_client.py @@ -17,7 +17,6 @@ def suite(): class ZoomClientTestCase(unittest.TestCase): - @mock.patch("zoomus.client.util.generate_token") def test_invalid_api_version_raises_error(self, mock_token): with self.assertRaisesRegexp(RuntimeError, "API version not supported: 42"): @@ -117,7 +116,9 @@ def test_can_set_api_version_to_1(self, mock_token): @mock.patch("zoomus.client.util.generate_token") def test_can_set_base_uri_to_gdpr(self, mock_token): - client = ZoomClient("KEY", "SECRET", "ACCOUNT_ID", base_uri=API_BASE_URIS[util.API_GDPR]) + client = ZoomClient( + "KEY", "SECRET", "ACCOUNT_ID", base_uri=API_BASE_URIS[util.API_GDPR] + ) self.assertEqual(client.config["version"], util.API_VERSION_2) for key in client.components.keys(): self.assertEqual( @@ -127,7 +128,11 @@ def test_can_set_base_uri_to_gdpr(self, mock_token): @mock.patch("zoomus.client.util.generate_token") def test_can_set_custom_base_uri(self, mock_token): client = ZoomClient( - "KEY", "SECRET", "ACCOUNT_ID", version=util.API_VERSION_1, base_uri="https://www.test.com" + "KEY", + "SECRET", + "ACCOUNT_ID", + version=util.API_VERSION_1, + base_uri="https://www.test.com", ) self.assertEqual(client.config["version"], util.API_VERSION_1) for key in client.components.keys(): @@ -135,7 +140,9 @@ def test_can_set_custom_base_uri(self, mock_token): @mock.patch("zoomus.client.util.generate_token") def test_can_set_api_version_to_1_and_set_custom_base_uri(self, mock_token): - client = ZoomClient("KEY", "SECRET", "ACCOUNT_ID", base_uri=API_BASE_URIS[util.API_GDPR]) + client = ZoomClient( + "KEY", "SECRET", "ACCOUNT_ID", base_uri=API_BASE_URIS[util.API_GDPR] + ) self.assertEqual(client.config["version"], util.API_VERSION_2) for key in client.components.keys(): self.assertEqual( diff --git a/tests/zoomus/test_util.py b/tests/zoomus/test_util.py index e8628ef..38561d5 100644 --- a/tests/zoomus/test_util.py +++ b/tests/zoomus/test_util.py @@ -706,7 +706,6 @@ def test_can_convert_datetime_to_str(self): class IsStrTypeTestCase(unittest.TestCase): - from sys import version_info def test_str_is_str_type(self): diff --git a/zoomus/components/user.py b/zoomus/components/user.py index ed3ddab..faf57ab 100644 --- a/zoomus/components/user.py +++ b/zoomus/components/user.py @@ -112,34 +112,30 @@ def get_settings(self, **kwargs): return self.get_request( "/users/{}/settings".format(kwargs.pop("id")), params=kwargs ) - + def add_assistants(self, **kwargs): util.require_keys(kwargs, ["id", "assistants"]) - body = { - "assistants": kwargs['assistants'] - } + body = {"assistants": kwargs["assistants"]} return self.post_request( "/users/{}/assistants".format(kwargs.pop("id")), data=kwargs ) - + def list_assistants(self, **kwargs): util.require_keys(kwargs, "id") - return self.get_request( - "/users/{}/assistants".format(kwargs.pop("id")) - ) - + return self.get_request("/users/{}/assistants".format(kwargs.pop("id"))) + def delete_assistant(self, **kwargs): util.require_keys(kwargs, ["id", "assistant_id"]) return self.delete_request( - "/users/{id}/assistants/{assistant_id}".format(id=kwargs.pop("id"), assistant_id=kwargs['assistant_id']) + "/users/{id}/assistants/{assistant_id}".format( + id=kwargs.pop("id"), assistant_id=kwargs["assistant_id"] + ) ) - + def delete_all_assistants(self, **kwargs): util.require_keys(kwargs, "id") - return self.delete_request( - "/users/{}/assistants".format(kwargs.pop("id")) - ) + return self.delete_request("/users/{}/assistants".format(kwargs.pop("id")))