Skip to content

Commit

Permalink
Rename more variables
Browse files Browse the repository at this point in the history
  • Loading branch information
hnryjmes committed Sep 13, 2024
1 parent 19c93d6 commit 91fcefb
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 36 deletions.
2 changes: 1 addition & 1 deletion api/data_workspace/v1/tests/test_staticdata_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class DataWorkspaceTests(DataTestClient):
def test_control_list_entries(self):
url = reverse("data_workspace:v1:dw-control-list-entries-list")
expected_fields = ("id", "rating", "text", "category", "controlled", "deprecated", "parent")
expected_fields = ("id", "rating", "text", "category", "controlled", "selectable_for_assessment", "parent")

response = self.client.get(url)
self.assertEqual(response.status_code, status.HTTP_200_OK)
Expand Down
2 changes: 1 addition & 1 deletion api/staticdata/control_list_entries/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ControlListEntriesFactory(factory.django.DjangoModelFactory):
parent = None
category = "test-list"
controlled = True
deprecated = False
selectable_for_assessment = True

class Meta:
model = models.ControlListEntry
30 changes: 17 additions & 13 deletions api/staticdata/control_list_entries/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def setUp(self):
super().setUp()
self.url = reverse("staticdata:control_list_entries:control_list_entries")

def test_gov_user_control_list_entries_list_ignores_deprecated_cles(self):
def test_gov_user_control_list_entries_list_ignores_unselectable_cles(self):
cles_count_model = ControlListEntry.objects.all().count()

# Assert that we have at least 1 CLE returned by the db manager
Expand All @@ -27,12 +27,14 @@ def test_gov_user_control_list_entries_list_ignores_deprecated_cles(self):
# Assert that we have at least 1 CLE returned by the view
self.assertTrue(cles_count_data > 0)

# Create a CLE with deprecated=True
deprecated_cle = ControlListEntriesFactory(rating="rating123", text="text", deprecated=True)
# Create a CLE with selectable_for_assessment=False
unselectable_cle = ControlListEntriesFactory(rating="rating123", text="text", selectable_for_assessment=False)

# Assert that the object was created successfully
self.assertTrue(deprecated_cle.deprecated)
self.assertTrue(ControlListEntry.objects.filter(rating="rating123", deprecated=True).count() == 1)
self.assertFalse(unselectable_cle.selectable_for_assessment)
self.assertTrue(
ControlListEntry.objects.filter(rating="rating123", selectable_for_assessment=False).count() == 1
)

updated_cles_count_model = ControlListEntry.objects.all().count()

Expand All @@ -46,11 +48,11 @@ def test_gov_user_control_list_entries_list_ignores_deprecated_cles(self):
# Assert that the count returned by the view is unchanged
self.assertTrue(updated_cles_count_data == cles_count_data)

# Assert that the data returned by the view does not contain the deprecated CLE
# Assert that the data returned by the view does not contain the unselectable CLE
self.assertNotIn("rating123", [cle["rating"] for cle in updated_cles_data])

def test_gov_user_control_list_entries_list_includes_deprecated_cles_if_include_deprecated_is_true(self):
url = reverse("staticdata:control_list_entries:control_list_entries") + "?include_deprecated=True"
def test_gov_user_control_list_entries_list_includes_unselectable_cles_if_include_unselectable_is_true(self):
url = reverse("staticdata:control_list_entries:control_list_entries") + "?include_unselectable=True"
cles_count_model = ControlListEntry.objects.all().count()

# Assert that we have at least 1 CLE returned by the db manager
Expand All @@ -63,12 +65,14 @@ def test_gov_user_control_list_entries_list_includes_deprecated_cles_if_include_
# Assert that we have at least 1 CLE returned by the view
self.assertTrue(cles_count_data > 0)

# Create a CLE with deprecated=True
deprecated_cle = ControlListEntriesFactory(rating="rating123", text="text", deprecated=True)
# Create a CLE with selectable_for_assessment=False
unselectable_cle = ControlListEntriesFactory(rating="rating123", text="text", selectable_for_assessment=False)

# Assert that the object was created successfully
self.assertTrue(deprecated_cle.deprecated)
self.assertTrue(ControlListEntry.objects.filter(rating="rating123", deprecated=True).count() == 1)
self.assertFalse(unselectable_cle.selectable_for_assessment)
self.assertTrue(
ControlListEntry.objects.filter(rating="rating123", selectable_for_assessment=False).count() == 1
)

updated_cles_count_model = ControlListEntry.objects.all().count()

Expand All @@ -82,5 +86,5 @@ def test_gov_user_control_list_entries_list_includes_deprecated_cles_if_include_
# Assert that the count returned by the view has increased by 1
self.assertTrue(updated_cles_count_data == cles_count_data + 1)

# Assert that the data returned by the view contains the deprecated CLE
# Assert that the data returned by the view contains the unselectable CLE
self.assertIn("rating123", [cle["rating"] for cle in updated_cles_data])
10 changes: 5 additions & 5 deletions api/staticdata/control_list_entries/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@
class ControlListEntriesList(APIView):
authentication_classes = (GovAuthentication,)

def get_queryset(self, include_deprecated=False):
if include_deprecated:
def get_queryset(self, include_unselectable=False):
if include_unselectable:
return ControlListEntry.objects.filter(controlled=True)

return ControlListEntry.objects.filter(controlled=True, deprecated=False)
return ControlListEntry.objects.filter(controlled=True, selectable_for_assessment=True)

def get(self, request):
"""
Returns list of all Control List Entries
"""

include_deprecated = request.GET.get("include_deprecated", False)
include_unselectable = request.GET.get("include_unselectable", False)

queryset = self.get_queryset(include_deprecated=include_deprecated)
queryset = self.get_queryset(include_unselectable=include_unselectable)

if request.GET.get("group", False):
return JsonResponse(data={"control_list_entries": convert_control_list_entries_to_tree(queryset.values())})
Expand Down
30 changes: 17 additions & 13 deletions api/staticdata/exporter/control_list_entries/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_list_view_success_exact_response(self):
],
)

def test_list_view_ignores_deprecated_cles_by_default(self):
def test_list_view_ignores_unselectable_cles_by_default(self):
cles_count_model = ControlListEntry.objects.all().count()

# Assert that we have at least 1 CLE returned by the db manager
Expand All @@ -60,12 +60,14 @@ def test_list_view_ignores_deprecated_cles_by_default(self):
# Assert that we have at least 1 CLE returned by the view
self.assertTrue(cles_count_data > 0)

# Create a CLE with deprecated=True
deprecated_cle = ControlListEntriesFactory(rating="rating123", text="text", deprecated=True)
# Create a CLE with selectable_for_assessment=False
unselectable_cle = ControlListEntriesFactory(rating="rating123", text="text", selectable_for_assessment=False)

# Assert that the object was created successfully
self.assertTrue(deprecated_cle.deprecated)
self.assertTrue(ControlListEntry.objects.filter(rating="rating123", deprecated=True).count() == 1)
self.assertFalse(unselectable_cle.selectable_for_assessment)
self.assertTrue(
ControlListEntry.objects.filter(rating="rating123", selectable_for_assessment=False).count() == 1
)

updated_cles_count_model = ControlListEntry.objects.all().count()

Expand All @@ -79,11 +81,11 @@ def test_list_view_ignores_deprecated_cles_by_default(self):
# Assert that the count returned by the view is unchanged
self.assertTrue(updated_cles_count_data == cles_count_data)

# Assert that the data returned by the view does not contain the deprecated CLE
# Assert that the data returned by the view does not contain the unselectable CLE
self.assertNotIn("rating123", [cle["rating"] for cle in updated_cles_data])

def test_list_view_includes_deprecated_cles_if_include_deprecated_is_true(self):
url = reverse("exporter_staticdata:control_list_entries:control_list_entries") + "?include_deprecated=True"
def test_list_view_includes_unselectable_cles_if_include_unselectable_is_true(self):
url = reverse("exporter_staticdata:control_list_entries:control_list_entries") + "?include_unselectable=True"
cles_count_model = ControlListEntry.objects.all().count()

# Assert that we have at least 1 CLE returned by the db manager
Expand All @@ -96,12 +98,14 @@ def test_list_view_includes_deprecated_cles_if_include_deprecated_is_true(self):
# Assert that we have at least 1 CLE returned by the view
self.assertTrue(cles_count_data > 0)

# Create a CLE with deprecated=True
deprecated_cle = ControlListEntriesFactory(rating="rating123", text="text", deprecated=True)
# Create a CLE with selectable_for_assessment=False
unselectable_cle = ControlListEntriesFactory(rating="rating123", text="text", selectable_for_assessment=False)

# Assert that the object was created successfully
self.assertTrue(deprecated_cle.deprecated)
self.assertTrue(ControlListEntry.objects.filter(rating="rating123", deprecated=True).count() == 1)
self.assertFalse(unselectable_cle.selectable_for_assessment)
self.assertTrue(
ControlListEntry.objects.filter(rating="rating123", selectable_for_assessment=False).count() == 1
)

updated_cles_count_model = ControlListEntry.objects.all().count()

Expand All @@ -115,5 +119,5 @@ def test_list_view_includes_deprecated_cles_if_include_deprecated_is_true(self):
# Assert that the count returned by the view has increased by 1
self.assertTrue(updated_cles_count_data == cles_count_data + 1)

# Assert that the data returned by the view contains the deprecated CLE
# Assert that the data returned by the view contains the unselectable CLE
self.assertIn("rating123", [cle["rating"] for cle in updated_cles_data])
6 changes: 3 additions & 3 deletions api/staticdata/exporter/control_list_entries/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class ControlListEntriesList(generics.ListAPIView):
serializer_class = ControlListEntriesListSerializer

def get_queryset(self):
include_deprecated = self.request.GET.get("include_deprecated", False)
if include_deprecated:
include_unselectable = self.request.GET.get("include_unselectable", False)
if include_unselectable:
return ControlListEntry.objects.filter(controlled=True)

return ControlListEntry.objects.filter(controlled=True, deprecated=False)
return ControlListEntry.objects.filter(controlled=True, selectable_for_assessment=True)

0 comments on commit 91fcefb

Please sign in to comment.