1
|
|
|
#!/usr/bin/env python3 |
2
|
|
|
# -*- coding: utf-8 -*- |
3
|
|
|
""" |
4
|
|
|
Created on Sat Jan 25 17:19:00 2020 |
5
|
|
|
|
6
|
|
|
@author: Paolo Cozzi <[email protected]> |
7
|
|
|
""" |
8
|
|
|
|
9
|
|
|
from django.test import Client, TestCase |
10
|
|
|
from django.contrib.auth import get_user_model |
11
|
|
|
from django.urls import reverse |
12
|
|
|
|
13
|
|
|
from .mixins import PersonMixinTestCase |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
class AdminTestCase(PersonMixinTestCase, TestCase): |
17
|
|
|
"""With this module, I want to test custom admin classes. See: |
18
|
|
|
|
19
|
|
|
https://docs.djangoproject.com/en/2.2/ref/contrib/admin/#admin-reverse-urls |
20
|
|
|
|
21
|
|
|
to have a list of admin views |
22
|
|
|
""" |
23
|
|
|
|
24
|
|
|
fixtures = [ |
25
|
|
|
'uid/animal', |
26
|
|
|
'uid/dictbreed', |
27
|
|
|
'uid/dictcountry', |
28
|
|
|
'uid/dictrole', |
29
|
|
|
'uid/dictsex', |
30
|
|
|
'uid/dictspecie', |
31
|
|
|
'uid/dictstage', |
32
|
|
|
'uid/dictuberon', |
33
|
|
|
'uid/ontology', |
34
|
|
|
'uid/organization', |
35
|
|
|
'uid/publication', |
36
|
|
|
'uid/sample', |
37
|
|
|
'uid/speciesynonym', |
38
|
|
|
'uid/submission', |
39
|
|
|
'uid/user' |
40
|
|
|
] |
41
|
|
|
|
42
|
|
|
@classmethod |
43
|
|
|
def setUpClass(cls): |
44
|
|
|
# calling my base class setup |
45
|
|
|
super().setUpClass() |
46
|
|
|
|
47
|
|
|
# create an admin user |
48
|
|
|
User = get_user_model() |
49
|
|
|
User.objects.create_superuser( |
50
|
|
|
username='admin', |
51
|
|
|
password='test', |
52
|
|
|
email='[email protected]') |
53
|
|
|
|
54
|
|
|
def setUp(self): |
55
|
|
|
self.client = Client() |
56
|
|
|
self.client.login(username='admin', password='test') |
57
|
|
|
|
58
|
|
|
def check_response(self, url): |
59
|
|
|
response = self.client.get(url) |
60
|
|
|
self.assertEqual(response.status_code, 200) |
61
|
|
|
|
62
|
|
|
def test_dictbreedadmin(self): |
63
|
|
|
url = reverse('admin:uid_dictbreed_changelist') |
64
|
|
|
self.check_response(url) |
65
|
|
|
|
66
|
|
|
def test_sampleadmin(self): |
67
|
|
|
url = reverse('admin:uid_sample_changelist') |
68
|
|
|
self.check_response(url) |
69
|
|
|
|
70
|
|
|
def test_animaladmin(self): |
71
|
|
|
url = reverse('admin:uid_animal_changelist') |
72
|
|
|
self.check_response(url) |
73
|
|
|
|
74
|
|
|
def test_animaladminchange(self): |
75
|
|
|
url = reverse('admin:uid_animal_change', kwargs={'object_id': 1}) |
76
|
|
|
self.check_response(url) |
77
|
|
|
|
78
|
|
|
def test_submissionadmin(self): |
79
|
|
|
url = reverse('admin:uid_submission_changelist') |
80
|
|
|
self.check_response(url) |
81
|
|
|
|
82
|
|
|
def test_personadmin(self): |
83
|
|
|
url = reverse('admin:uid_person_changelist') |
84
|
|
|
self.check_response(url) |
85
|
|
|
|
86
|
|
|
def test_useradmin(self): |
87
|
|
|
url = reverse('admin:auth_user_changelist') |
88
|
|
|
self.check_response(url) |
89
|
|
|
|
90
|
|
|
def test_useradminchange(self): |
91
|
|
|
url = reverse('admin:auth_user_change', kwargs={'object_id': 1}) |
92
|
|
|
self.check_response(url) |
93
|
|
|
|