From e4ed7ed1f62051f1161e19aceed1d9b7843d6df9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Wed, 31 Jul 2024 16:29:34 +0200 Subject: [PATCH] new: get user profile --- pyvulnerabilitylookup/api.py | 5 +++++ tests/test_web.py | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/pyvulnerabilitylookup/api.py b/pyvulnerabilitylookup/api.py index d7b7a43..580fd2b 100644 --- a/pyvulnerabilitylookup/api.py +++ b/pyvulnerabilitylookup/api.py @@ -211,3 +211,8 @@ class PyVulnerabilityLookup(): '''List users''' r = self.session.get(urljoin(self.root_url, str(PurePosixPath('api', 'user')))) return r.json() + + def get_user_information(self) -> dict[str, Any]: + '''Get user information''' + r = self.session.get(urljoin(self.root_url, str(PurePosixPath('api', 'user', 'me')))) + return r.json() diff --git a/tests/test_web.py b/tests/test_web.py index 4161b03..e82e090 100644 --- a/tests/test_web.py +++ b/tests/test_web.py @@ -253,6 +253,18 @@ class TestPublic(unittest.TestCase): self.assertTrue(len(comments["data"]) == 0) # Test User + def test_users_info(self) -> None: + if not self.admin_token: + # this test is only working if the admin token is set + return None + # Makes sure the userkey is set to the right one + self.client.set_apikey(self.admin_token) + user_info = self.client.get_user_information() + self.assertTrue(isinstance(user_info, dict)) + self.assertTrue('login' in user_info) + self.assertTrue('apikey' in user_info) + self.assertEqual(user_info['apikey'], self.admin_token) + def test_list_users(self) -> None: if not self.admin_token: # this test is only working if the admin token is set