Ensure seat usage calculator returns free for trashed groups
@pytest.mark.django_db
@override_settings(DEBUG=True)
def test_a_trashed_group_is_all_free(
enterprise_data_fixture, data_fixture, synced_roles
):
enterprise_data_fixture.enable_enterprise()
user1_paid_in_grp1 = data_fixture.create_user()
user2_free_in_grp1_paid_grp2 = data_fixture.create_user()
user3_free_both_grps = data_fixture.create_user()
group1 = data_fixture.create_group()
data_fixture.create_user_group(
user=user1_paid_in_grp1, group=group1, permissions="ADMIN"
)
data_fixture.create_user_group(
user=user2_free_in_grp1_paid_grp2, group=group1, permissions=FREE_VIEWER_ROLE
)
data_fixture.create_user_group(
user=user3_free_both_grps, group=group1, permissions=FREE_VIEWER_ROLE
)
database1 = data_fixture.create_database_application(group=group1)
table1 = data_fixture.create_database_table(database=database1)
grp1_team_with_paid_role_on_db = enterprise_data_fixture.create_team(group=group1)
grp1_team_with_no_roles = enterprise_data_fixture.create_team(group=group1)
enterprise_data_fixture.create_subject(
team=grp1_team_with_paid_role_on_db, subject=user1_paid_in_grp1
)
enterprise_data_fixture.create_subject(
team=grp1_team_with_paid_role_on_db, subject=user2_free_in_grp1_paid_grp2
)
enterprise_data_fixture.create_subject(
team=grp1_team_with_no_roles, subject=user2_free_in_grp1_paid_grp2
)
RoleAssignmentHandler().assign_role(
grp1_team_with_paid_role_on_db,
group1,
role=Role.objects.get(uid=FREE_VIEWER_ROLE),
scope=database1,
)
RoleAssignmentHandler().assign_role(
grp1_team_with_paid_role_on_db,
group1,
role=Role.objects.get(uid=PAID_COMMENTER_ROLE),
scope=table1,
)
assert RoleBasedSeatUsageSummaryCalculator.get_seat_usage_for_group(
group1
) == SeatUsageSummary(
seats_taken=2,
free_users_count=1,
num_users_with_highest_role={
"ADMIN": 1,
"BUILDER": 0,
"EDITOR": 0,
"COMMENTER": 2,
"VIEWER": 1,
"NO_ACCESS": 0,
"NO_ROLE_LOW_PRIORITY": 0,
},
)
TrashHandler.trash(user1_paid_in_grp1, group1, None, group1)
assert RoleBasedSeatUsageSummaryCalculator.get_seat_usage_for_group(
group1
) == SeatUsageSummary(
seats_taken=2,
free_users_count=1,
num_users_with_highest_role={
"ADMIN": 0,
"BUILDER": 0,
"EDITOR": 0,
"COMMENTER": 2,
"VIEWER": 1,
"NO_ACCESS": 0,
"NO_ROLE_LOW_PRIORITY": 0,
},
)
Edited by Nigel Gott