Skip to content

Commit

Permalink
test create user and group with minted IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
jsjiang committed Oct 16, 2023
1 parent b351035 commit b3507ad
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tests/test_group_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright©2021, Regents of the University of California
# http://creativecommons.org/licenses/BSD

"""Test the minter data modle
"""
import pytest
import logging
from django.core.exceptions import ValidationError

import django.conf
import ezidapp.models.group

log = logging.getLogger(__name__)

class TestGropu:
def test_1_create_group(self, caplog):
"""test - Create group with group ID minted on Agent shoulder"""
caplog.set_level(logging.INFO)

next_spin = '154dv8s'
expected_pid = f'{django.conf.settings.SHOULDERS_AGENT}{next_spin}'

assert not ezidapp.models.group.Group.objects.filter(
pid=expected_pid
).exists()

group = ezidapp.models.group.Group(
groupname='testgroup',
organizationName = "Test Group",
realm_id = 1,
)
with pytest.raises(ValidationError) as exc_info:
group.full_clean()

group.save()

assert ezidapp.models.group.Group.objects.filter(
pid=expected_pid
).exists()

group = ezidapp.models.group.Group.objects.get(pid=expected_pid)

assert group.pid == expected_pid
assert group.groupname == 'testgroup'
assert group.organizationName == 'Test Group'
assert group.realm_id == 1






56 changes: 56 additions & 0 deletions tests/test_user_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright©2021, Regents of the University of California
# http://creativecommons.org/licenses/BSD

"""Test the minter data modle
"""
import pytest
import logging
from django.core.exceptions import ValidationError

import django.conf
import ezidapp.models.user

log = logging.getLogger(__name__)

class TestUser:
def test_1_create_user(self, caplog):
"""test - Create user with user ID minted on Agent shoulder"""
caplog.set_level(logging.INFO)

next_spin = '154dv8s'
expected_pid = f'{django.conf.settings.SHOULDERS_AGENT}{next_spin}'

assert not ezidapp.models.user.User.objects.filter(
pid=expected_pid
).exists()

user = ezidapp.models.user.User(
username='testuser',
displayName = "Test User",
group_id = 2,
realm_id = 1,
)
with pytest.raises(ValidationError) as exc_info:
user.full_clean()

user.save()

assert ezidapp.models.user.User.objects.filter(
pid=expected_pid
).exists()

user = ezidapp.models.user.User.objects.get(pid=expected_pid)

assert user.pid == expected_pid
assert user.username == 'testuser'
assert user.displayName == 'Test User'
assert user.group_id == 2
assert user.realm_id == 1
assert user.accountEmail == ''
assert user.password != ''






0 comments on commit b3507ad

Please sign in to comment.