-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2152 from uktrade/LTD-5349_Update_CLE_queryset_to…
…_ignore_deprecated_CLEs Update CLE queryset to ignore unselectable CLEs by default
- Loading branch information
Showing
12 changed files
with
203 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...icdata/control_list_entries/migrations/0006_controllistentry_selectable_for_assessment.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 4.2.15 on 2024-09-13 13:08 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("control_list_entries", "0005_adds_5D001e"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="controllistentry", | ||
name="selectable_for_assessment", | ||
field=models.BooleanField(default=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
from rest_framework.reverse import reverse | ||
|
||
from api.staticdata.control_list_entries.models import ControlListEntry | ||
from api.staticdata.control_list_entries.factories import ControlListEntriesFactory | ||
from test_helpers.clients import DataTestClient | ||
|
||
|
||
class ControlListEntriesListTests(DataTestClient): | ||
""" | ||
Most other view tests are in api/staticdata/control_list_entries/test.py | ||
""" | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self.url = reverse("staticdata:control_list_entries:control_list_entries") | ||
|
||
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 | ||
self.assertTrue(cles_count_model > 0) | ||
|
||
response = self.client.get(self.url, **self.gov_headers) | ||
cles_data = response.json().get("control_list_entries") | ||
cles_count_data = len(cles_data) | ||
|
||
# Assert that we have at least 1 CLE returned by the view | ||
self.assertTrue(cles_count_data > 0) | ||
|
||
# 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.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() | ||
|
||
# Assert that the count returned by the db manager has increased by 1 | ||
self.assertTrue(updated_cles_count_model == cles_count_model + 1) | ||
|
||
response = self.client.get(self.url, **self.gov_headers) | ||
updated_cles_data = response.json().get("control_list_entries") | ||
updated_cles_count_data = len(updated_cles_data) | ||
|
||
# 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 unselectable CLE | ||
self.assertNotIn("rating123", [cle["rating"] for cle in updated_cles_data]) | ||
|
||
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 | ||
self.assertTrue(cles_count_model > 0) | ||
|
||
response = self.client.get(url, **self.gov_headers) | ||
cles_data = response.json().get("control_list_entries") | ||
cles_count_data = len(cles_data) | ||
|
||
# Assert that we have at least 1 CLE returned by the view | ||
self.assertTrue(cles_count_data > 0) | ||
|
||
# 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.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() | ||
|
||
# Assert that the count returned by the db manager has increased by 1 | ||
self.assertTrue(updated_cles_count_model == cles_count_model + 1) | ||
|
||
response = self.client.get(url, **self.gov_headers) | ||
updated_cles_data = response.json().get("control_list_entries") | ||
updated_cles_count_data = len(updated_cles_data) | ||
|
||
# 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 unselectable CLE | ||
self.assertIn("rating123", [cle["rating"] for cle in updated_cles_data]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters