Skip to content

Commit

Permalink
Fixed tests for changlist editable dashboards, refs #130, refs #131
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Jul 1, 2021
1 parent 1fb3f15 commit 4c1951e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion django_sql_dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def get_editable_by_user(cls, user):
cls.objects.filter(
models.Q(owned_by=user)
| models.Q(edit_policy__in=allowed_policies)
| models.Q(view_policy=cls.EditPolicies.GROUP, edit_group__user=user)
| models.Q(edit_policy=cls.EditPolicies.GROUP, edit_group__user=user)
)
).distinct()

Expand Down
18 changes: 18 additions & 0 deletions test_project/test_dashboard_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,24 @@ def test_user_can_edit(
user.save()
assert dashboard_obj.user_can_edit(user) == expected_if_staff
assert can_user_edit_using_admin(client, user, dashboard_obj) == expected_if_staff

# Confirm that staff user can see the correct dashboards listed
client.force_login(user)
dashboard_change_list_response = client.get(
"/admin/django_sql_dashboard/dashboard/"
)
change_list_soup = BeautifulSoup(dashboard_change_list_response.content, "html5lib")
visible_in_change_list = [
a.text for a in change_list_soup.select("th.field-slug a")
]
assert set(visible_in_change_list) == {
"owned_by_other_staff",
"owned_by_other_group_member",
"owned_by_other_loggedin",
"owned_by_user",
}

# Promote to superuser
user.is_superuser = True
user.save()
assert dashboard_obj.user_can_edit(user) == expected_if_superuser
Expand Down

0 comments on commit 4c1951e

Please sign in to comment.