def test_term_actions(users, user, action, term, rf): model_admin = admin.TermAdmin(models.Term, site) if action == "add": url = reverse("admin:letsagree_term_{0}".format(action)) else: url = reverse("admin:letsagree_term_{0}".format(action), args=(term.id, )) request = rf.get(url) request.user = users(user) view_obj = getattr(model_admin, "{0}_view".format(action)) # No one can delete if action == "delete": with pytest.raises(PermissionDenied): view_obj(request, object_id=str(term.id)) # Every admin user with permissions can view but cannot change elif action == "change": view = view_obj(request, object_id=str(term.id)) assert view.status_code == 200 assert "delete" not in view.rendered_content assert "readonly" in view.rendered_content assert '<input type="submit"' not in view.rendered_content # Every admin user with permissions can add elif action == "add": view = view_obj(request) assert view.status_code == 200
def test_view_user_term_changelist(many_terms_one_view_user, rf): model_admin = admin.TermAdmin(models.Term, site) url = reverse("admin:letsagree_term_changelist") request = rf.get(url) request.user = many_terms_one_view_user qs = model_admin.get_queryset(request) assert models.Term.objects.count() > 1 assert qs.count() == 1
def test_term_changelist(users, many_terms, rf, django_assert_num_queries): model_admin = admin.TermAdmin(models.Term, site) url = reverse("admin:letsagree_term_changelist") request = rf.get(url) request.user = users("staff") with django_assert_num_queries(3): qs = model_admin.get_queryset(request) assert qs.count() == len(many_terms) with django_assert_num_queries(3): view = model_admin.changelist_view(request) assert view.status_code == 200