Skip to content

Commit

Permalink
added functional test
Browse files Browse the repository at this point in the history
  • Loading branch information
raftmsohani committed Jan 16, 2025
1 parent 6f18151 commit 75405a9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions tdrs-backend/tdpservice/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
33 changes: 33 additions & 0 deletions tdrs-backend/tdpservice/users/test/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 75405a9

Please sign in to comment.