From 75405a9617ac642ff73f07088224df8bd085e41b Mon Sep 17 00:00:00 2001 From: Mo Sohani Date: Thu, 16 Jan 2025 14:02:53 -0500 Subject: [PATCH] added functional test --- tdrs-backend/tdpservice/users/models.py | 1 + .../tdpservice/users/test/test_models.py | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/tdrs-backend/tdpservice/users/models.py b/tdrs-backend/tdpservice/users/models.py index d491ba98d..4382444ab 100644 --- a/tdrs-backend/tdpservice/users/models.py +++ b/tdrs-backend/tdpservice/users/models.py @@ -122,6 +122,7 @@ class Meta: @property def has_fra_access(self): + """Return whether or not the user has FRA access.""" return self.feature_flags.get('fra_access', False) def __str__(self): diff --git a/tdrs-backend/tdpservice/users/test/test_models.py b/tdrs-backend/tdpservice/users/test/test_models.py index 7c63015e0..2004e74d6 100644 --- a/tdrs-backend/tdpservice/users/test/test_models.py +++ b/tdrs-backend/tdpservice/users/test/test_models.py @@ -4,6 +4,10 @@ import pytest from tdpservice.stts.models import STT, Region +from tdpservice.data_files.models import DataFile +from tdpservice.data_files.test.factories import DataFileFactory +from tdpservice.users.models import User +from django.test import Client @pytest.mark.django_db @@ -70,3 +74,32 @@ def test_user_can_only_have_stt_or_region(user, stt, region): user.clean() user.save() + +@pytest.mark.django_db +def test_user_with_fra_access(client, user, stt): + """Test that a user with FRA access can only have an STT.""" + user.stt = stt + user.is_superuser = True + user.feature_flags = {"fra_access": False} + + user.clean() + user.save() + + user = User.objects.create_superuser('admin', 'admin@example.com', 'password') + client = Client() + client.force_login(user) + + # Need a datafile, with a section that is not in the FRA_SECTION_LIST + datafile = DataFileFactory() + datafile.section = DataFile.Section.FRA_WORK_OUTCOME_TANF_EXITERS + datafile.save() + + response = client.get(f"/admin/data_files/datafile/{datafile.id}/change/") + assert response.status_code != 200 + assert f'Data file with ID “{datafile.id}” doesn’t exist. Perhaps it was deleted?' + + user.feature_flags = {"fra_access": True} + user.save() + + response = client.get(f"/admin/data_files/datafile/{datafile.id}/change/") + assert response.status_code == 200