Skip to content

Commit

Permalink
Add tests, remove unused imports
Browse files Browse the repository at this point in the history
  • Loading branch information
tortila authored and mrchrisadams committed Jul 12, 2023
1 parent 0ee2832 commit 996d5a2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 0 additions & 2 deletions apps/accounts/admin.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from typing import Optional
from django.db import models
from django.core.mail import send_mail
from django.core.exceptions import PermissionDenied
from django.conf import settings
from django.contrib import messages
from django.contrib import admin
from django.http.request import HttpRequest
from django.urls import reverse
from django.http import HttpResponseRedirect
from django.contrib.auth.admin import UserAdmin, GroupAdmin, Group
Expand Down
21 changes: 16 additions & 5 deletions apps/accounts/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,15 +527,26 @@ def test_user_admin_displays_managed_providers_and_dcs(
assert datacenter.name in user_admin.managed_datacenters(sample_hoster_user)

def test_user_cannot_access_another_user_change_view(
self, db, sample_hoster_user, greenweb_staff_user
self, db, client, sample_hoster_user, greenweb_staff_user
):
user_admin = ac_admin.CustomUserAdmin(ac_models.User, admin_site.greenweb_admin)
request = MagicMock()
request.user = sample_hoster_user
response = user_admin.change_view(request, str(greenweb_staff_user.id))
client.force_login(sample_hoster_user)
change_user_url = urls.reverse(
"greenweb_admin:accounts_user_change", args=[greenweb_staff_user.id]
)
response = client.get(change_user_url)
assert response.status_code == 302
assert response.url == "/admin/"

def test_staff_can_access_another_user_change_view(
self, db, client, sample_hoster_user, greenweb_staff_user
):
client.force_login(greenweb_staff_user)
change_user_url = urls.reverse(
"greenweb_admin:accounts_user_change", args=[sample_hoster_user.id]
)
response = client.get(change_user_url)
assert response.status_code == 200


def test_provider_request_accessible_by_admin(
db,
Expand Down

0 comments on commit 996d5a2

Please sign in to comment.