mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-25 12:08:40 +02:00
test cases added
This commit is contained in:
parent
a2a6b9e68f
commit
77cf108323
1 changed files with 36 additions and 0 deletions
|
@ -1,3 +1,4 @@
|
|||
from django.forms import ValidationError
|
||||
from django.test import TestCase
|
||||
from django.db.utils import IntegrityError
|
||||
from django.db import transaction
|
||||
|
@ -1348,6 +1349,7 @@ class TestUser(TestCase):
|
|||
self.user.phone = None
|
||||
self.assertFalse(self.user.has_contact_info())
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_has_portfolio_permission(self):
|
||||
"""
|
||||
0. Returns False when user does not have a permission
|
||||
|
@ -1401,6 +1403,40 @@ class TestUser(TestCase):
|
|||
|
||||
Portfolio.objects.all().delete()
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_user_with_portfolio_but_no_roles(self):
|
||||
# Create an instance of User with a portfolio but no roles or additional permissions
|
||||
portfolio, _ = Portfolio.objects.get_or_create(creator=self.user, organization_name="Hotel California")
|
||||
|
||||
self.user.portfolio = portfolio
|
||||
self.user.portfolio_roles = []
|
||||
|
||||
# Test if the ValidationError is raised with the correct message
|
||||
with self.assertRaises(ValidationError) as cm:
|
||||
self.user.clean()
|
||||
|
||||
self.assertEqual(
|
||||
cm.exception.message, "When portfolio is assigned, portfolio roles or additional permissions are required."
|
||||
)
|
||||
self.user.refresh_from_db()
|
||||
Portfolio.objects.all().delete()
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_user_with_portfolio_roles_but_no_portfolio(self):
|
||||
# Create an instance of User with a portfolio role but no portfolio
|
||||
self.user.portfolio = None
|
||||
self.user.portfolio_roles = [UserPortfolioRoleChoices.ORGANIZATION_ADMIN]
|
||||
|
||||
# Test if the ValidationError is raised with the correct message
|
||||
with self.assertRaises(ValidationError) as cm:
|
||||
self.user.clean()
|
||||
|
||||
self.assertEqual(
|
||||
cm.exception.message, "When portfolio roles or additional permissions are assigned, portfolio is required."
|
||||
)
|
||||
self.user.refresh_from_db()
|
||||
Portfolio.objects.all().delete()
|
||||
|
||||
|
||||
class TestContact(TestCase):
|
||||
@less_console_noise_decorator
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue