class ApiKeyTestCase(unittest.TestCase): def setUp(self): self.client = Client() self.key = """ { "data": { "count": 0, "customer": null, "expireTime": "2018-10-03T08:36:14.651Z", "href": "http://localhost:8080/key/BpSG0Ck5JCqk5TJiuBSLAWuTs03QKc_527T5cDtw", "id": "f4203347-d1b2-4f56-b5e9-6de97cf2d8ae", "key": "BpSG0Ck5JCqk5TJiuBSLAWuTs03QKc_527T5cDtw", "lastUsedTime": null, "scopes": [ "write:alerts", "admin:keys" ], "text": "Ops kAPI Key", "type": "read-write", "user": "******" }, "key": "BpSG0Ck5JCqk5TJiuBSLAWuTs03QKc_527T5cDtw", "status": "ok" } """ @requests_mock.mock() def test_key(self, m): m.post('http://*****:*****@example.com') self.assertEqual(sorted(api_key.scopes), sorted(['write:alerts', 'admin:keys']))
class AlertTestCase(unittest.TestCase): def setUp(self): self.client = Client(endpoint='http://*****:*****@alerta.io') self.assertEqual(sorted(api_key.scopes), sorted(['write:alerts', 'admin:keys'])) api_key = self.client.update_key(api_key_id, scopes=[ Scope.write_alerts, Scope.write_heartbeats, Scope.admin_keys ], text='Updated Ops API Key') self.assertEqual( sorted(api_key.scopes), sorted( [Scope.write_alerts, Scope.write_heartbeats, Scope.admin_keys])) self.assertEqual(api_key.text, 'Updated Ops API Key') api_key = self.client.create_key(username='******', scopes=[Scope.admin], text='Admin API Key', key='admin-key') self.assertEqual(api_key.key, 'admin-key') api_keys = self.client.get_keys(query=[('user', '*****@*****.**')]) self.assertEqual(len(api_keys), 2) api_keys = self.client.delete_key(api_key_id) self.assertEqual(len(api_keys), 1)
class ApiKeyTestCase(unittest.TestCase): def setUp(self): self.client = Client() self.key = """ { "data": { "count": 0, "customer": null, "expireTime": "2018-10-03T08:36:14.651Z", "href": "http://localhost:8080/key/BpSG0Ck5JCqk5TJiuBSLAWuTs03QKc_527T5cDtw", "id": "f4203347-d1b2-4f56-b5e9-6de97cf2d8ae", "key": "BpSG0Ck5JCqk5TJiuBSLAWuTs03QKc_527T5cDtw", "lastUsedTime": null, "scopes": [ "write:alerts", "admin:keys" ], "text": "Ops kAPI Key", "type": "read-write", "user": "******" }, "key": "demo-key", "status": "ok" } """ @requests_mock.mock() def test_key(self, m): m.post('http://*****:*****@example.com') self.assertEqual(sorted(api_key.scopes), sorted(['write:alerts', 'admin:keys']))