Skip to content

Commit

Permalink
Add detailed information from linked_data
Browse files Browse the repository at this point in the history
Policy, Accountability and Domain now have more data, extracted from the linked data, since they do not have a dedicated endpoint
  • Loading branch information
joaodaher committed May 22, 2019
1 parent 17048d9 commit 208e46e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
16 changes: 16 additions & 0 deletions glassfrog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
11 changes: 10 additions & 1 deletion tests/unit/tests_models/tests_circle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)

Expand Down
16 changes: 14 additions & 2 deletions tests/unit/tests_models/tests_role.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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)

Expand Down

0 comments on commit 208e46e

Please sign in to comment.