From 208e46e056d4adcfd03b4edac1a311773c69f9b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Daher?= Date: Tue, 21 May 2019 13:52:24 -0300 Subject: [PATCH] Add detailed information from linked_data Policy, Accountability and Domain now have more data, extracted from the linked data, since they do not have a dedicated endpoint --- glassfrog/models.py | 16 ++++++++++++++++ tests/unit/tests_models/tests_circle.py | 11 ++++++++++- tests/unit/tests_models/tests_role.py | 16 ++++++++++++++-- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/glassfrog/models.py b/glassfrog/models.py index f26c698..d48088b 100644 --- a/glassfrog/models.py +++ b/glassfrog/models.py @@ -284,14 +284,30 @@ class Organization(UnsupportedModelMixin, BaseModel): class Domain(UnsupportedModelMixin, BaseModel): _RESOURCE_NAME = 'domains' + @property + def description(self): + return self._get('description') + class Policy(UnsupportedModelMixin, BaseModel): _RESOURCE_NAME = 'policies' + @property + def title(self): + return self._get('title') + + @property + def body(self): + return self._get('body') + class Accountability(UnsupportedModelMixin, BaseModel): _RESOURCE_NAME = 'accountabilities' + @property + def description(self): + return self._get('description') + class Project(UnsupportedModelMixin, BaseModel): _RESOURCE_NAME = 'projects' diff --git a/tests/unit/tests_models/tests_circle.py b/tests/unit/tests_models/tests_circle.py index df23796..b29e1c1 100644 --- a/tests/unit/tests_models/tests_circle.py +++ b/tests/unit/tests_models/tests_circle.py @@ -83,7 +83,11 @@ def test_fields_roles(self): def test_fields_policies(self): data = self.sample_data()[0] - circle = models.Circle(data=data) + linked_data = {'policies': [ + {'id': 100, 'title': 'potato 100', 'body': 'tomato 100'}, + {'id': 200, 'title': 'potato 200', 'body': 'tomato 200'}, + ]} + circle = models.Circle(data=data, linked_data=linked_data) policy_data = [{'id': 100}, {'id': 200}] with self.patch_get(resource='policies', data=policy_data, many=True) as get: @@ -92,7 +96,12 @@ def test_fields_policies(self): self.assertEqual(2, len(policies)) [policy_a, policy_b] = policies self.assertEqual(100, policy_a.id) + self.assertEqual('potato 100', policy_a.title) + self.assertEqual('tomato 100', policy_a.body) + self.assertEqual(200, policy_b.id) + self.assertEqual('potato 200', policy_b.title) + self.assertEqual('tomato 200', policy_b.body) self.assertEqual(0, get.call_count) diff --git a/tests/unit/tests_models/tests_role.py b/tests/unit/tests_models/tests_role.py index a743b8a..b6c5d4b 100644 --- a/tests/unit/tests_models/tests_role.py +++ b/tests/unit/tests_models/tests_role.py @@ -97,7 +97,11 @@ def test_fields_circle(self): def test_fields_accontabilities(self): data = self.sample_data()[0] - role = models.Role(data=data) + linked_data = {'accountabilities': [ + {'id': 10, 'description': 'potato 10'}, + {'id': 20, 'description': 'potato 20'}, + ]} + role = models.Role(data=data, linked_data=linked_data) account_data = [{'id': 10}, {'id': 20}] with self.patch_get(resource='accountabilities', data=account_data, many=True) as get: @@ -106,13 +110,19 @@ def test_fields_accontabilities(self): self.assertEqual(2, len(accountabilities)) [accountabilities_a, accountabilities_b] = accountabilities self.assertEqual(10, accountabilities_a.id) + self.assertEqual('potato 10', accountabilities_a.description) self.assertEqual(20, accountabilities_b.id) + self.assertEqual('potato 20', accountabilities_b.description) self.assertEqual(0, get.call_count) def test_fields_domains(self): data = self.sample_data()[0] - role = models.Role(data=data) + linked_data = {'domains': [ + {'id': 1000, 'description': 'potato 1000'}, + {'id': 2000, 'description': 'potato 2000'}, + ]} + role = models.Role(data=data, linked_data=linked_data) domain_data = [{'id': 1000}, {'id': 2000}] with self.patch_get(resource='domains', data=domain_data, many=True) as get: @@ -121,7 +131,9 @@ def test_fields_domains(self): self.assertEqual(2, len(domains)) [domain_a, domain_b] = domains self.assertEqual(1000, domain_a.id) + self.assertEqual('potato 1000', domain_a.description) self.assertEqual(2000, domain_b.id) + self.assertEqual('potato 2000', domain_b.description) self.assertEqual(0, get.call_count)