-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
477277f
commit 7e39737
Showing
13 changed files
with
589 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from api.app import constants as famConstants | ||
|
||
|
||
TEST_CREATOR = "TESTER" | ||
TEST_FOM_DEV_ADMIN_ROLE = "FOM_DEV_ACCESS_ADMIN" | ||
INVALID_APPLICATION_ID = "invalid_application_id" | ||
|
||
# ---------------------- test user data ----------------------------- # | ||
TEST_INVALID_USER_TYPE = "NS" | ||
TEST_NON_EXISTS_COGNITO_USER_ID = f"dev-idir_nonexists@idir" | ||
|
||
TEST_NEW_USER = { | ||
"user_type_code": famConstants.UserType.IDIR, | ||
"user_name": "TEST_USER", | ||
"create_user": TEST_CREATOR, | ||
} | ||
|
||
# ---------------------- test application data ---------------------- # | ||
TEST_NOT_EXIST_APPLICATION_ID = 0 | ||
TEST_APPLICATION_ID_FAM = 1 | ||
TEST_APPLICATION_NAME_FAM = "FAM" | ||
|
||
# -------------------- test application admin data ------------------ # | ||
TEST_NEW_APPLICATION_ADMIN_USER_ID = 1 | ||
TEST_NEW_APPLICATION_ADMIN = { | ||
"user_type_code": famConstants.UserType.BCEID, | ||
"user_name": "TEST_USER", | ||
"application_id": TEST_APPLICATION_ID_FAM, | ||
} |
103 changes: 103 additions & 0 deletions
103
server/admin_management/tests/repositories/test_application_admin_repository.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import logging | ||
|
||
from api.app.repositories.application_admin_repository import ApplicationAdminRepository | ||
|
||
from tests.constants import ( | ||
TEST_APPLICATION_ID_FAM, | ||
TEST_NEW_APPLICATION_ADMIN_USER_ID, | ||
TEST_CREATOR, | ||
) | ||
|
||
|
||
LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
def test_create_application_admin_and_get( | ||
application_admin_repo: ApplicationAdminRepository, | ||
): | ||
# create a new application admin | ||
new_application_admin = application_admin_repo.create_application_admin( | ||
TEST_APPLICATION_ID_FAM, | ||
TEST_NEW_APPLICATION_ADMIN_USER_ID, | ||
TEST_CREATOR, | ||
) | ||
assert new_application_admin.application_id == TEST_APPLICATION_ID_FAM | ||
assert new_application_admin.user_id == TEST_NEW_APPLICATION_ADMIN_USER_ID | ||
|
||
# get the new created application admin | ||
application_admin = application_admin_repo.get_application_admin_by_app_and_user_id( | ||
TEST_APPLICATION_ID_FAM, | ||
TEST_NEW_APPLICATION_ADMIN_USER_ID, | ||
) | ||
assert new_application_admin.user_id == application_admin.user_id | ||
assert new_application_admin.application_id == application_admin.application_id | ||
assert ( | ||
new_application_admin.application_admin_id | ||
== application_admin.application_admin_id | ||
) | ||
|
||
|
||
def test_get_application_admin_by_application_id( | ||
application_admin_repo: ApplicationAdminRepository, | ||
): | ||
# find application admin, no data initially | ||
application_admin = application_admin_repo.get_application_admin_by_application_id( | ||
TEST_APPLICATION_ID_FAM | ||
) | ||
assert len(application_admin) == 0 | ||
|
||
# create a new application admin | ||
new_application_admin = application_admin_repo.create_application_admin( | ||
TEST_APPLICATION_ID_FAM, | ||
TEST_NEW_APPLICATION_ADMIN_USER_ID, | ||
TEST_CREATOR, | ||
) | ||
assert new_application_admin.application_id == TEST_APPLICATION_ID_FAM | ||
# get the new application admin by application id | ||
application_admin = application_admin_repo.get_application_admin_by_application_id( | ||
TEST_APPLICATION_ID_FAM | ||
) | ||
assert application_admin is not None | ||
|
||
|
||
def test_get_application_admin_by_id( | ||
application_admin_repo: ApplicationAdminRepository, | ||
): | ||
# create a new application admin | ||
new_application_admin = application_admin_repo.create_application_admin( | ||
TEST_APPLICATION_ID_FAM, | ||
TEST_NEW_APPLICATION_ADMIN_USER_ID, | ||
TEST_CREATOR, | ||
) | ||
# get the new application admin by id | ||
application_admin = application_admin_repo.get_application_admin_by_id( | ||
new_application_admin.application_admin_id | ||
) | ||
assert ( | ||
application_admin.application_admin_id | ||
== new_application_admin.application_admin_id | ||
) | ||
|
||
|
||
def test_delete_application_admin(application_admin_repo: ApplicationAdminRepository): | ||
# create a new application admin | ||
new_application_admin = application_admin_repo.create_application_admin( | ||
TEST_APPLICATION_ID_FAM, | ||
TEST_NEW_APPLICATION_ADMIN_USER_ID, | ||
TEST_CREATOR, | ||
) | ||
# verify the new application admin is created | ||
application_admin = application_admin_repo.get_application_admin_by_id( | ||
new_application_admin.application_admin_id | ||
) | ||
assert application_admin is not None | ||
|
||
# remove the application admin | ||
application_admin_repo.delete_application_admin( | ||
new_application_admin.application_admin_id | ||
) | ||
# verify the application admin cannot be found anymore | ||
application_admin = application_admin_repo.get_application_admin_by_id( | ||
new_application_admin.application_admin_id | ||
) | ||
assert application_admin is None |
23 changes: 23 additions & 0 deletions
23
server/admin_management/tests/repositories/test_application_repository.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import logging | ||
|
||
from api.app.repositories.application_repository import ApplicationRepository | ||
|
||
from tests.constants import ( | ||
TEST_NOT_EXIST_APPLICATION_ID, | ||
TEST_APPLICATION_ID_FAM, | ||
TEST_APPLICATION_NAME_FAM, | ||
) | ||
|
||
|
||
LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
def test_get_application(application_repo: ApplicationRepository): | ||
# test get existing application | ||
app_by_id = application_repo.get_application(TEST_APPLICATION_ID_FAM) | ||
assert app_by_id.application_id == TEST_APPLICATION_ID_FAM | ||
assert app_by_id.application_name == TEST_APPLICATION_NAME_FAM | ||
|
||
# test get non exist application | ||
app_by_id = application_repo.get_application(TEST_NOT_EXIST_APPLICATION_ID) | ||
assert app_by_id is None |
83 changes: 83 additions & 0 deletions
83
server/admin_management/tests/repositories/test_user_repository.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import logging | ||
import pytest | ||
from sqlalchemy.exc import IntegrityError | ||
|
||
import api.app.schemas as schemas | ||
from api.app.repositories.user_repository import UserRepository | ||
|
||
from tests.constants import ( | ||
TEST_NEW_USER, | ||
TEST_NON_EXISTS_COGNITO_USER_ID, | ||
) | ||
import tests.jwt_utils as jwt_utils | ||
|
||
|
||
LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
def test_get_user_by_domain_and_name(user_repo: UserRepository): | ||
# test not found | ||
fam_user = user_repo.get_user_by_domain_and_name( | ||
TEST_NEW_USER["user_type_code"], TEST_NEW_USER["user_name"] | ||
) | ||
assert fam_user is None | ||
|
||
# create a new user and find it and verify found | ||
request_user = schemas.FamUser(**TEST_NEW_USER) | ||
new_user = user_repo.create_user(request_user) | ||
fam_user = user_repo.get_user_by_domain_and_name( | ||
TEST_NEW_USER["user_type_code"], TEST_NEW_USER["user_name"] | ||
) | ||
assert new_user.user_id == fam_user.user_id | ||
assert new_user.user_name == fam_user.user_name | ||
assert new_user.user_type_code == fam_user.user_type_code | ||
|
||
# get user with username lower case | ||
fam_user = user_repo.get_user_by_domain_and_name( | ||
TEST_NEW_USER["user_type_code"], "test_user" | ||
) | ||
assert new_user.user_id == fam_user.user_id | ||
assert new_user.user_name == fam_user.user_name | ||
assert new_user.user_type_code == fam_user.user_type_code | ||
|
||
|
||
def test_get_user_by_cognito_user_id(user_repo: UserRepository): | ||
# test not found | ||
fam_user = user_repo.get_user_by_cognito_user_id(TEST_NON_EXISTS_COGNITO_USER_ID) | ||
assert fam_user is None | ||
|
||
# test found | ||
fam_user = user_repo.get_user_by_cognito_user_id(jwt_utils.COGNITO_USERNAME) | ||
assert fam_user.cognito_user_id == jwt_utils.COGNITO_USERNAME | ||
|
||
|
||
def test_get_users(user_repo: UserRepository): | ||
users = user_repo.get_users() | ||
assert users is not None | ||
users_count = len(users) | ||
|
||
request_user = schemas.FamUser(**TEST_NEW_USER) | ||
user_repo.create_user(request_user) | ||
users = user_repo.get_users() | ||
assert len(users) == users_count + 1 | ||
|
||
|
||
def test_create_user(user_repo: UserRepository): | ||
request_user = schemas.FamUser(**TEST_NEW_USER) | ||
new_user = user_repo.create_user(request_user) | ||
assert new_user.user_name == TEST_NEW_USER.get("user_name") | ||
assert new_user.user_type_code == TEST_NEW_USER.get("user_type_code") | ||
fam_user = user_repo.get_user_by_domain_and_name( | ||
TEST_NEW_USER["user_type_code"], TEST_NEW_USER["user_name"] | ||
) | ||
assert new_user.user_id == fam_user.user_id | ||
assert new_user.user_name == fam_user.user_name | ||
assert new_user.user_type_code == fam_user.user_type_code | ||
|
||
# test create duplicate user | ||
with pytest.raises(IntegrityError) as e: | ||
user_repo.create_user(request_user) | ||
assert ( | ||
str(e.value).find('duplicate key value violates unique constraint "fam_usr_uk"') | ||
!= -1 | ||
) |
Oops, something went wrong.