Skip to content

Commit dea1dae

Browse files
authored
Merge pull request #847 from nofusscomputing/model-inheritance-tests
2 parents 5c6ba74 + 92760a6 commit dea1dae

19 files changed

Lines changed: 97 additions & 64 deletions

app/access/models/entity.py

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def __str__(self) -> str:
7070

7171

7272

73-
def clean(self):
73+
def clean_fields(self, exclude = None ):
7474

7575
related_model = self.get_related_model()
7676

@@ -82,6 +82,8 @@ def clean(self):
8282

8383
self.entity_type = str(related_model._meta.verbose_name).lower().replace(' ', '_')
8484

85+
super().clean_fields( exclude = exclude )
86+
8587

8688

8789
def get_related_field_name(self) -> str:
@@ -139,24 +141,3 @@ def get_related_model(self):
139141

140142

141143
return related_model
142-
143-
144-
def get_url_kwargs(self, many = False) -> dict:
145-
146-
model = self.get_related_model()
147-
148-
if (len(self._meta.parents) == 0 and model is None) or not many:
149-
150-
return {
151-
'pk': self.id
152-
}
153-
154-
if model is None:
155-
156-
model = self
157-
158-
kwargs = {
159-
'entity_model': str(model._meta.verbose_name).lower().replace(' ', '_'),
160-
}
161-
162-
return kwargs

app/access/tests/functional/company/test_functional_company_metadata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ def setUpTestData(self):
5353
}
5454

5555
# self.url_kwargs = {
56-
# 'entity_model': self.model._meta.sub_model_type
56+
# 'model_name': self.model._meta.sub_model_type
5757
# }
5858

5959
# self.url_view_kwargs = {
60-
# 'entity_model': self.model._meta.sub_model_type
60+
# 'model_name': self.model._meta.sub_model_type
6161
# }
6262

6363
super().setUpTestData()

app/access/tests/functional/contact/test_functional_contact_permission.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ class ContactPermissionsAPIInheritedCases(
4141
# def inherited_var_setup(self, request):
4242

4343
# request.cls.url_kwargs.update({
44-
# 'entity_model': self.model._meta.sub_model_type
44+
# 'model_name': self.model._meta.sub_model_type
4545
# })
4646

4747
# request.cls.url_view_kwargs.update({
48-
# 'entity_model': self.model._meta.sub_model_type
48+
# 'model_name': self.model._meta.sub_model_type
4949
# })
5050

5151

app/access/tests/functional/entity/test_functional_entity_metadata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,11 @@ def setUpTestData(self):
240240
}
241241

242242
self.url_kwargs = {
243-
'entity_model': self.model._meta.sub_model_type
243+
'model_name': self.model._meta.sub_model_type
244244
}
245245

246246
self.url_view_kwargs = {
247-
'entity_model': self.model._meta.sub_model_type
247+
'model_name': self.model._meta.sub_model_type
248248
}
249249

250250
super().setUpTestData()

app/access/tests/functional/entity/test_functional_entity_permission.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ class EntityPermissionsAPIInheritedCases(
6060
def inherited_var_setup(self, request):
6161

6262
request.cls.url_kwargs.update({
63-
'entity_model': self.model._meta.sub_model_type
63+
'model_name': self.model._meta.sub_model_type
6464
})
6565

6666
request.cls.url_view_kwargs.update({
67-
'entity_model': self.model._meta.sub_model_type
67+
'model_name': self.model._meta.sub_model_type
6868
})
6969

7070

app/access/tests/functional/entity/test_functional_entity_viewset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,11 @@ def setUpTestData(self):
247247
}
248248

249249
self.url_kwargs = {
250-
'entity_model': self.model._meta.sub_model_type
250+
'model_name': self.model._meta.sub_model_type
251251
}
252252

253253
self.url_view_kwargs = {
254-
'entity_model': self.model._meta.sub_model_type
254+
'model_name': self.model._meta.sub_model_type
255255
}
256256

257257
super().setUpTestData()

app/access/tests/functional/person/test_functional_person_metadata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ def setUpTestData(self):
6464
}
6565

6666
# self.url_kwargs = {
67-
# 'entity_model': self.model._meta.sub_model_type
67+
# 'model_name': self.model._meta.sub_model_type
6868
# }
6969

7070
# self.url_view_kwargs = {
71-
# 'entity_model': self.model._meta.sub_model_type
71+
# 'model_name': self.model._meta.sub_model_type
7272
# }
7373

7474
super().setUpTestData()

app/access/tests/functional/person/test_functional_person_permission.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ class PersonPermissionsAPIInheritedCases(
6262
# def inherited_var_setup(self, request):
6363

6464
# request.cls.url_kwargs.update({
65-
# 'entity_model': self.model._meta.sub_model_type
65+
# 'model_name': self.model._meta.sub_model_type
6666
# })
6767

6868
# request.cls.url_view_kwargs.update({
69-
# 'entity_model': self.model._meta.sub_model_type
69+
# 'model_name': self.model._meta.sub_model_type
7070
# })
7171

7272

app/access/tests/unit/entity/test_unit_entity_api_fields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def setup_model(self, request,
2424
if model != self.base_model:
2525

2626
request.cls.url_view_kwargs.update({
27-
'entity_model': model._meta.sub_model_type,
27+
'model_name': model._meta.sub_model_type,
2828
})
2929

3030

app/access/tests/unit/entity/test_unit_entity_model.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,22 @@ def test_attribute_value_kb_model_name(self, model):
9393
assert model.kb_model_name == 'entity'
9494

9595

96+
def test_method_get_url_kwargs(self, mocker, model_instance, settings):
97+
"""Test Class Method
98+
99+
Ensure method `get_url_kwargs` returns the correct value.
100+
"""
101+
102+
103+
url = model_instance.get_url_kwargs()
104+
105+
assert model_instance.get_url_kwargs() == {
106+
'model_name': model_instance._meta.model_name,
107+
'pk': model_instance.id
108+
}
109+
110+
111+
96112

97113
class EntityModelInheritedCases(
98114
EntityModelTestCases,
@@ -113,3 +129,16 @@ def test_function_value_get_related_model(self, model_instance):
113129
"""
114130

115131
assert model_instance.get_related_model() is None
132+
133+
def test_method_get_url_kwargs(self, mocker, model_instance, settings):
134+
"""Test Class Method
135+
136+
Ensure method `get_url_kwargs` returns the correct value.
137+
"""
138+
139+
140+
url = model_instance.get_url_kwargs()
141+
142+
assert model_instance.get_url_kwargs() == {
143+
'pk': model_instance.id
144+
}

0 commit comments

Comments
 (0)