Skip to content

Commit

Permalink
test(permission-db): use less critical ids in unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
mabw-rte committed Feb 22, 2024
1 parent 9adace4 commit 78cfe03
Showing 1 changed file with 64 additions and 56 deletions.
120 changes: 64 additions & 56 deletions tests/study/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ def test_get_all__study_tags_filter(
"user_id, study_groups, expected_ids",
[
(
1,
101,
[],
{
"1",
Expand Down Expand Up @@ -731,15 +731,19 @@ def test_get_all__study_tags_filter(
"34",
},
),
(1, ["1"], {"1", "7", "8", "9", "17", "23", "24", "25"}),
(1, ["2"], {"2", "5", "6", "7", "8", "9", "18", "21", "22", "23", "24", "25", "34"}),
(1, ["3"], set()),
(1, ["1", "2"], {"1", "2", "5", "6", "7", "8", "9", "17", "18", "21", "22", "23", "24", "25", "34"}),
(1, ["1", "3"], {"1", "7", "8", "9", "17", "23", "24", "25"}),
(1, ["2", "3"], {"2", "5", "6", "7", "8", "9", "18", "21", "22", "23", "24", "25", "34"}),
(1, ["1", "2", "3"], {"1", "2", "5", "6", "7", "8", "9", "17", "18", "21", "22", "23", "24", "25", "34"}),
(101, ["101"], {"1", "7", "8", "9", "17", "23", "24", "25"}),
(101, ["102"], {"2", "5", "6", "7", "8", "9", "18", "21", "22", "23", "24", "25", "34"}),
(101, ["103"], set()),
(101, ["101", "102"], {"1", "2", "5", "6", "7", "8", "9", "17", "18", "21", "22", "23", "24", "25", "34"}),
(101, ["101", "103"], {"1", "7", "8", "9", "17", "23", "24", "25"}),
(101, ["102", "103"], {"2", "5", "6", "7", "8", "9", "18", "21", "22", "23", "24", "25", "34"}),
(
2,
101,
["101", "102", "103"],
{"1", "2", "5", "6", "7", "8", "9", "17", "18", "21", "22", "23", "24", "25", "34"},
),
(
102,
[],
{
"1",
Expand Down Expand Up @@ -769,29 +773,33 @@ def test_get_all__study_tags_filter(
"33",
},
),
(2, ["1"], {"1", "3", "4", "7", "8", "9", "17", "19", "20", "23", "24", "25", "33"}),
(2, ["2"], {"5", "7", "8", "9", "21", "23", "24", "25"}),
(2, ["3"], set()),
(2, ["1", "2"], {"1", "3", "4", "5", "7", "8", "9", "17", "19", "20", "21", "23", "24", "25", "33"}),
(2, ["1", "3"], {"1", "3", "4", "7", "8", "9", "17", "19", "20", "23", "24", "25", "33"}),
(2, ["2", "3"], {"5", "7", "8", "9", "21", "23", "24", "25"}),
(2, ["1", "2", "3"], {"1", "3", "4", "5", "7", "8", "9", "17", "19", "20", "21", "23", "24", "25", "33"}),
(3, [], {"13", "14", "15", "16", "29", "30", "31", "32", "33", "34", "35", "36"}),
(3, ["1"], {"33"}),
(3, ["2"], {"34"}),
(3, ["3"], set()),
(3, ["1", "2"], {"33", "34"}),
(3, ["1", "3"], {"33"}),
(3, ["2", "3"], {"34"}),
(3, ["1", "2", "3"], {"33", "34"}),
(102, ["101"], {"1", "3", "4", "7", "8", "9", "17", "19", "20", "23", "24", "25", "33"}),
(102, ["102"], {"5", "7", "8", "9", "21", "23", "24", "25"}),
(102, ["103"], set()),
(102, ["101", "102"], {"1", "3", "4", "5", "7", "8", "9", "17", "19", "20", "21", "23", "24", "25", "33"}),
(102, ["101", "103"], {"1", "3", "4", "7", "8", "9", "17", "19", "20", "23", "24", "25", "33"}),
(102, ["102", "103"], {"5", "7", "8", "9", "21", "23", "24", "25"}),
(
102,
["101", "102", "103"],
{"1", "3", "4", "5", "7", "8", "9", "17", "19", "20", "21", "23", "24", "25", "33"},
),
(103, [], {"13", "14", "15", "16", "29", "30", "31", "32", "33", "34", "35", "36"}),
(103, ["101"], {"33"}),
(103, ["102"], {"34"}),
(103, ["103"], set()),
(103, ["101", "102"], {"33", "34"}),
(103, ["101", "103"], {"33"}),
(103, ["102", "103"], {"34"}),
(103, ["101", "102", "103"], {"33", "34"}),
(None, [], set()),
(None, ["1"], set()),
(None, ["2"], set()),
(None, ["3"], set()),
(None, ["1", "2"], set()),
(None, ["1", "3"], set()),
(None, ["2", "3"], set()),
(None, ["1", "2", "3"], set()),
(None, ["101"], set()),
(None, ["102"], set()),
(None, ["103"], set()),
(None, ["101", "102"], set()),
(None, ["101", "103"], set()),
(None, ["102", "103"], set()),
(None, ["101", "102", "103"], set()),
],
)
def test_get_all__non_admin_permissions_filter(
Expand All @@ -803,15 +811,15 @@ def test_get_all__non_admin_permissions_filter(
icache: Mock = Mock(spec=ICache)
repository = StudyMetadataRepository(cache_service=icache, session=db_session)

user_1 = User(id=1, name="user1")
user_2 = User(id=2, name="user2")
user_3 = User(id=3, name="user3")
user_1 = User(id=101, name="user1")
user_2 = User(id=102, name="user2")
user_3 = User(id=103, name="user3")

group_1 = Group(id=1, name="group1")
group_2 = Group(id=2, name="group2")
group_3 = Group(id=3, name="group3")
group_1 = Group(id=101, name="group1")
group_2 = Group(id=102, name="group2")
group_3 = Group(id=103, name="group3")

user_groups_mapping = {1: [group_2.id], 2: [group_1.id], 3: []}
user_groups_mapping = {101: [group_2.id], 102: [group_1.id], 103: []}

# create variant studies for user_1 and user_2 that are part of some groups
study_1 = VariantStudy(id=1, owner=user_1, groups=[group_1])
Expand Down Expand Up @@ -939,12 +947,12 @@ def test_get_all__non_admin_permissions_filter(
"is_admin, study_groups, expected_ids",
[
(True, [], {str(e) for e in range(1, 39)}),
(True, ["1"], {"1", "3", "4", "7", "8", "9", "17", "19", "20", "23", "24", "25", "33"}),
(True, ["2"], {"2", "5", "6", "7", "8", "9", "18", "21", "22", "23", "24", "25", "34"}),
(True, ["3"], {"37", "38"}),
(True, ["101"], {"1", "3", "4", "7", "8", "9", "17", "19", "20", "23", "24", "25", "33"}),
(True, ["102"], {"2", "5", "6", "7", "8", "9", "18", "21", "22", "23", "24", "25", "34"}),
(True, ["103"], {"37", "38"}),
(
True,
["1", "2"],
["101", "102"],
{
"1",
"2",
Expand All @@ -970,12 +978,12 @@ def test_get_all__non_admin_permissions_filter(
),
(
True,
["1", "3"],
["101", "103"],
{"1", "3", "4", "7", "8", "9", "17", "19", "20", "23", "24", "25", "33", "37", "38"},
),
(
True,
["1", "2", "3"],
["101", "102", "103"],
{
"1",
"2",
Expand All @@ -1002,12 +1010,12 @@ def test_get_all__non_admin_permissions_filter(
},
),
(False, [], set()),
(False, ["1"], set()),
(False, ["2"], set()),
(False, ["3"], set()),
(False, ["1", "2"], set()),
(False, ["1", "3"], set()),
(False, ["1", "2", "3"], set()),
(False, ["101"], set()),
(False, ["102"], set()),
(False, ["103"], set()),
(False, ["101", "102"], set()),
(False, ["101", "103"], set()),
(False, ["101", "102", "103"], set()),
],
)
def test_get_all__admin_permissions_filter(
Expand All @@ -1018,13 +1026,13 @@ def test_get_all__admin_permissions_filter(
) -> None:
icache: Mock = Mock(spec=ICache)
repository = StudyMetadataRepository(cache_service=icache, session=db_session)
user_1 = User(id=1, name="user1")
user_2 = User(id=2, name="user2")
user_3 = User(id=3, name="user3")
user_1 = User(id=101, name="user1")
user_2 = User(id=102, name="user2")
user_3 = User(id=103, name="user3")

group_1 = Group(id=1, name="group1")
group_2 = Group(id=2, name="group2")
group_3 = Group(id=3, name="group3")
group_1 = Group(id=101, name="group1")
group_2 = Group(id=102, name="group2")
group_3 = Group(id=103, name="group3")

# create variant studies for user_1 and user_2 that are part of some groups
study_1 = VariantStudy(id=1, owner=user_1, groups=[group_1])
Expand Down

0 comments on commit 78cfe03

Please sign in to comment.