Last active
August 26, 2021 04:04
-
-
Save tommorris/cd1048418cccfa346fef to your computer and use it in GitHub Desktop.
Django admin testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.test import TestCase, Client | |
from django.contrib.auth.models import User | |
class TestAdminPanel(TestCase): | |
def create_user(self): | |
self.username = "test_admin" | |
self.password = User.objects.make_random_password() | |
user, created = User.objects.get_or_create(username=self.username) | |
user.set_password(self.password) | |
user.is_staff = True | |
user.is_superuser = True | |
user.is_active = True | |
user.save() | |
self.user = user | |
def test_spider_admin(self): | |
self.create_user() | |
client = Client() | |
client.login(username=self.username, password=self.password) | |
admin_pages = [ | |
"/admin/", | |
# put all the admin pages for your models in here. | |
"/admin/auth/", | |
"/admin/auth/group/", | |
"/admin/auth/group/add/", | |
"/admin/auth/user/", | |
"/admin/auth/user/add/", | |
"/admin/password_change/" | |
] | |
for page in admin_pages: | |
resp = client.get(page) | |
assert resp.status_code == 200 | |
assert "<!DOCTYPE html" in resp.content | |
# Above code is licensed under the MIT License. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment