mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-20 09:46:06 +02:00
Fix two tests
This commit is contained in:
parent
cbec3f2ed7
commit
5c07775277
3 changed files with 28 additions and 16 deletions
|
@ -1747,3 +1747,12 @@ class MockEppLib(TestCase):
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.mockSendPatch.stop()
|
self.mockSendPatch.stop()
|
||||||
|
|
||||||
|
|
||||||
|
def get_wsgi_request_object(client, user, url="/"):
|
||||||
|
"""Returns client.get(url).wsgi_request for testing functions or classes
|
||||||
|
that need a request object directly passed to them."""
|
||||||
|
client.force_login(user)
|
||||||
|
request = client.get(url).wsgi_request
|
||||||
|
request.user = user
|
||||||
|
return request
|
||||||
|
|
|
@ -1459,9 +1459,15 @@ class TestUser(TestCase):
|
||||||
portfolio_permission.portfolio = None
|
portfolio_permission.portfolio = None
|
||||||
portfolio_permission.roles = [UserPortfolioRoleChoices.ORGANIZATION_ADMIN]
|
portfolio_permission.roles = [UserPortfolioRoleChoices.ORGANIZATION_ADMIN]
|
||||||
|
|
||||||
|
# Create a new UserPortfolioPermission instance without a portfolio
|
||||||
|
invalid_permission = UserPortfolioPermission(
|
||||||
|
user=self.user,
|
||||||
|
roles=[UserPortfolioRoleChoices.ORGANIZATION_ADMIN],
|
||||||
|
portfolio=None # This should trigger the validation error
|
||||||
|
)
|
||||||
# Test if the ValidationError is raised with the correct message
|
# Test if the ValidationError is raised with the correct message
|
||||||
with self.assertRaises(ValidationError) as cm:
|
with self.assertRaises(ValidationError) as cm:
|
||||||
portfolio_permission.clean()
|
invalid_permission.clean()
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
cm.exception.message, "When portfolio roles or additional permissions are assigned, portfolio is required."
|
cm.exception.message, "When portfolio roles or additional permissions are assigned, portfolio is required."
|
||||||
|
|
|
@ -34,7 +34,7 @@ import boto3_mocking
|
||||||
from registrar.utility.s3_bucket import S3ClientError, S3ClientErrorCodes # type: ignore
|
from registrar.utility.s3_bucket import S3ClientError, S3ClientErrorCodes # type: ignore
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from api.tests.common import less_console_noise_decorator
|
from api.tests.common import less_console_noise_decorator
|
||||||
from .common import MockDbForSharedTests, MockDbForIndividualTests, MockEppLib, less_console_noise, get_time_aware_date
|
from .common import MockDbForSharedTests, MockDbForIndividualTests, MockEppLib, get_wsgi_request_object, less_console_noise, get_time_aware_date
|
||||||
from waffle.testutils import override_flag
|
from waffle.testutils import override_flag
|
||||||
|
|
||||||
|
|
||||||
|
@ -282,10 +282,8 @@ class ExportDataTest(MockDbForIndividualTests, MockEppLib):
|
||||||
# Create a user and associate it with some domains
|
# Create a user and associate it with some domains
|
||||||
UserDomainRole.objects.create(user=self.user, domain=self.domain_2)
|
UserDomainRole.objects.create(user=self.user, domain=self.domain_2)
|
||||||
|
|
||||||
# Create a request object
|
# Make a GET request using self.client to get a request object
|
||||||
factory = RequestFactory()
|
request = get_wsgi_request_object(client=self.client, user=self.user)
|
||||||
request = factory.get("/")
|
|
||||||
request.user = self.user
|
|
||||||
|
|
||||||
# Create a CSV file in memory
|
# Create a CSV file in memory
|
||||||
csv_file = StringIO()
|
csv_file = StringIO()
|
||||||
|
@ -339,13 +337,9 @@ class ExportDataTest(MockDbForIndividualTests, MockEppLib):
|
||||||
portfolio_permission.roles = [UserPortfolioRoleChoices.ORGANIZATION_ADMIN]
|
portfolio_permission.roles = [UserPortfolioRoleChoices.ORGANIZATION_ADMIN]
|
||||||
portfolio_permission.save()
|
portfolio_permission.save()
|
||||||
portfolio_permission.refresh_from_db()
|
portfolio_permission.refresh_from_db()
|
||||||
self.user.refresh_from_db()
|
|
||||||
|
|
||||||
# Create a request object
|
# Make a GET request using self.client to get a request object
|
||||||
factory = RequestFactory()
|
request = get_wsgi_request_object(client=self.client, user=self.user)
|
||||||
request = factory.get("/")
|
|
||||||
request.user = self.user
|
|
||||||
request.session = {}
|
|
||||||
|
|
||||||
# Get the csv content
|
# Get the csv content
|
||||||
csv_content = self._run_domain_data_type_user_export(request)
|
csv_content = self._run_domain_data_type_user_export(request)
|
||||||
|
@ -356,19 +350,22 @@ class ExportDataTest(MockDbForIndividualTests, MockEppLib):
|
||||||
self.assertNotIn(self.domain_2.name, csv_content)
|
self.assertNotIn(self.domain_2.name, csv_content)
|
||||||
|
|
||||||
# Test the output for readonly admin
|
# Test the output for readonly admin
|
||||||
portfolio_permission.portfolio_roles = [UserPortfolioRoleChoices.ORGANIZATION_ADMIN_READ_ONLY]
|
portfolio_permission.roles = [UserPortfolioRoleChoices.ORGANIZATION_ADMIN_READ_ONLY]
|
||||||
portfolio_permission.save()
|
portfolio_permission.save()
|
||||||
|
portfolio_permission.refresh_from_db()
|
||||||
|
|
||||||
|
# Get the csv content
|
||||||
|
csv_content = self._run_domain_data_type_user_export(request)
|
||||||
self.assertIn(self.domain_1.name, csv_content)
|
self.assertIn(self.domain_1.name, csv_content)
|
||||||
self.assertIn(self.domain_3.name, csv_content)
|
self.assertIn(self.domain_3.name, csv_content)
|
||||||
self.assertNotIn(self.domain_2.name, csv_content)
|
self.assertNotIn(self.domain_2.name, csv_content)
|
||||||
|
|
||||||
# Get the csv content
|
portfolio_permission.roles = [UserPortfolioRoleChoices.ORGANIZATION_MEMBER]
|
||||||
portfolio_permission.portfolio_roles = [UserPortfolioRoleChoices.ORGANIZATION_MEMBER]
|
|
||||||
portfolio_permission.save()
|
portfolio_permission.save()
|
||||||
|
portfolio_permission.refresh_from_db()
|
||||||
|
|
||||||
|
# Get the csv content
|
||||||
csv_content = self._run_domain_data_type_user_export(request)
|
csv_content = self._run_domain_data_type_user_export(request)
|
||||||
|
|
||||||
self.assertNotIn(self.domain_1.name, csv_content)
|
self.assertNotIn(self.domain_1.name, csv_content)
|
||||||
self.assertNotIn(self.domain_3.name, csv_content)
|
self.assertNotIn(self.domain_3.name, csv_content)
|
||||||
self.assertIn(self.domain_2.name, csv_content)
|
self.assertIn(self.domain_2.name, csv_content)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue