Extended tests for User admin table and models
This commit is contained in:
parent
4aedfe6a5c
commit
611a7abf95
|
@ -1,5 +1,5 @@
|
|||
from django.test import TestCase
|
||||
from idhub.models import Event
|
||||
from idhub.models import Event, Membership, Rol, UserRol, Service
|
||||
from idhub_auth.models import User
|
||||
|
||||
|
||||
|
@ -50,9 +50,24 @@ class UserTest(TestCase):
|
|||
self.assertTrue(self.user.is_staff)
|
||||
|
||||
def test_get_memberships(self):
|
||||
# TODO
|
||||
pass
|
||||
Membership.objects.create(user=self.user,
|
||||
type=Membership.Types.BENEFICIARY)
|
||||
Membership.objects.create(user=self.user,
|
||||
type=Membership.Types.EMPLOYEE)
|
||||
|
||||
# We test for the length because the order in which the string
|
||||
# is given in get_memberships is non-deterministic
|
||||
self.assertEqual(len(self.user.get_memberships()),
|
||||
len("Beneficiary, Employee"))
|
||||
|
||||
def test_get_roles(self):
|
||||
# TODO
|
||||
pass
|
||||
user = User.objects.get(email="test@example.com")
|
||||
service = Service.objects.create(domain="Test Service")
|
||||
role1 = Rol.objects.create(name="Role 1")
|
||||
role2 = Rol.objects.create(name="Role 2")
|
||||
service.rol.add(role1, role2)
|
||||
UserRol.objects.create(user=user, service=service)
|
||||
|
||||
# We test for the length because the order in which the string
|
||||
# is given in get_roles is non-deterministic
|
||||
self.assertEqual(len(user.get_roles()), len("Role 1, Role 2"))
|
||||
|
|
|
@ -4,8 +4,8 @@ from django.test import TestCase
|
|||
from django.urls import reverse
|
||||
|
||||
from idhub_auth.models import User
|
||||
from idhub.admin.tables import DashboardTable
|
||||
from idhub.models import Event
|
||||
from idhub.admin.tables import DashboardTable, UserTable
|
||||
from idhub.models import Event, Membership, Rol, UserRol, Service
|
||||
|
||||
|
||||
class AdminDashboardTableTest(TestCase):
|
||||
|
@ -63,3 +63,34 @@ class AdminDashboardTableTest(TestCase):
|
|||
def test_pagination(self):
|
||||
# TODO
|
||||
pass
|
||||
|
||||
|
||||
class UserTableTest(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.user1 = User.objects.create(email="user1@example.com")
|
||||
self.user2 = User.objects.create(email="user2@example.com")
|
||||
Membership.objects.create(user=self.user1,
|
||||
type=Membership.Types.BENEFICIARY)
|
||||
|
||||
# Set up roles and services
|
||||
service = Service.objects.create(domain="Test Service")
|
||||
role = Rol.objects.create(name="Role 1")
|
||||
service.rol.add(role)
|
||||
UserRol.objects.create(user=self.user1, service=service)
|
||||
|
||||
self.table = UserTable(User.objects.all())
|
||||
|
||||
def test_membership_column_render(self):
|
||||
# Get the user instance for the first row
|
||||
user = self.table.rows[0].record
|
||||
# Use the render_membership method of UserTable
|
||||
rendered_column = self.table.columns['membership'].render(user)
|
||||
self.assertIn("Beneficiary", str(rendered_column))
|
||||
|
||||
def test_role_column_render(self):
|
||||
# Get the user instance for the first row
|
||||
user = self.table.rows[0].record
|
||||
# Use the render_role method of UserTable
|
||||
rendered_column = self.table.columns['role'].render(user)
|
||||
self.assertIn("Role 1", str(rendered_column))
|
||||
|
|
Loading…
Reference in New Issue