Closed dpgraham4401 closed 1 year ago
Hi, if site_manager is True, should we set the values of annual_report, biennial_report, e_manifest, my_rcra_id, and wiets to 'Certifier', or should we check whether these values are already set to 'Certifier'?
hey @nihalrahmanqb, good question.
We should check whether the remaining values are set to "Certifier"
if site_manager == True
. If, for example, the admin is adjusting a SitePermission instance, we want to prevent the model from saving if it doesn't make sense instead of adjusting the values submitted.
So the following test should fail, site_permission
should not save since the other attributes are options other than "Certifier"
.
import pytest
from apps.trak.models import SitePermission
class TestSitePermissions:
@pytest.fixture(autouse=True)
def _test_user(self, testuser1):
self.user = testuser1
@pytest.fixture(autouse=True)
def _test_user_profile(self, test_user_profile):
self.profile = test_user_profile
@pytest.fixture(autouse=True)
def _site_gen001(self, site_generator001):
self.gen001 = site_generator001
def test_create_validators(self):
site_permission = SitePermission(
site_manager=True,
e_manifest='Viewer',
my_rcra_id='Certifier',
annual_report='Viewer',
biennial_report='Preparer',
profile_id=self.profile.id,
site_id=self.gen001.epa_site.id)
site_permission.save()
saved_permission = SitePermission.objects.get(id=site_permission.id)
assert isinstance(saved_permission, SitePermission)
Let me know if you'd like me to assign you this issue :)
Yes, I would like to have a try :)
Hii @dpgraham4401 "The value for the '{field_name}' field must be set to 'Certifier'." Can I go ahead with the above sentence as the validation error message
@nihalrahmanqb That will work, thanks!
🐞 Bug Report
Currently there is no validation for the SitePermission model on ther server.
All permissions are currently required before a SitePermission model can be saved (that part is covered) however, if
Then all the RCRAInfo modules
[annual_report, biennial_report, e_manifest, my_rcra_id, wiets]
should be equal to'Certifier'
.See Django's documentation on validators