tests.py
5.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
from django.test import TestCase
from rest_framework.test import APITestCase
from rest_framework.authtoken.models import Token
from user_mgmt.models import *
from seq_submit.models import *
from django.urls import reverse
# Create your tests here.
class APITests(APITestCase):
fixtures = ['tests/complete_fixture.json']
def test_login_successful(self):
user = PyrosUser.objects.first()
test_password = "testpassword"
user.set_password(test_password)
user.save()
url = reverse("api_token_auth")
response = self.client.post(
url, data={"username": user.username, "password": test_password})
self.assertEqual(response.status_code, 200)
self.assertEqual(["token"],list(response.data.keys()))
def test_login_unsuccessful(self):
user = PyrosUser.objects.first()
test_password = "testpassword"
url = reverse("api_token_auth")
response = self.client.post(
url, data={"username": user.username, "password": test_password})
self.assertEqual(response.status_code, 400)
def test_logout_successful(self):
user = PyrosUser.objects.get(username="pyros")
test_password = "testpassword"
user.set_password(test_password)
user.save()
url = reverse("api_token_auth")
response = self.client.post(
url, data={"username": user.username, "password": test_password})
token = response.data["token"]
self.client.credentials(HTTP_AUTHORIZATION='Token ' + token)
url = reverse("logout")
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
def test_user_view_list(self):
user = PyrosUser.objects.get(username="pyros")
self.client.force_authenticate(user=user)
url = '/api/users/'
response = self.client.get(url,follow=True)
self.assertEqual(response.status_code,200)
self.assertEqual(len(response.data),PyrosUser.objects.all().count())
def test_user_view_detail(self):
user = PyrosUser.objects.get(username="pyros")
self.client.force_authenticate(user=user)
url = '/api/users/1'
response = self.client.get(url,follow=True)
self.assertEqual(response.status_code,200)
self.assertEqual(response.data["username"],PyrosUser.objects.get(id=1).username)
def test_sequence_list(self):
user = PyrosUser.objects.get(username="pyros")
self.client.force_authenticate(user=user)
url = '/api/sequences/'
response = self.client.get(url,follow=True)
self.assertEqual(response.status_code,200)
self.assertEqual(len(response.data),Sequence.objects.all().count())
def test_sequence_detail(self):
user = PyrosUser.objects.get(username="pyros")
self.client.force_authenticate(user=user)
url = '/api/sequences/1'
response = self.client.get(url,follow=True)
self.assertEqual(response.status_code,200)
self.assertEqual(response.data.get("name"),Sequence.objects.get(id=1).name)
def test_album_list(self):
user = PyrosUser.objects.get(username="pyros")
self.client.force_authenticate(user=user)
url = '/api/albums/'
response = self.client.get(url,follow=True)
self.assertEqual(response.status_code,200)
self.assertEqual(len(response.data),Album.objects.all().count())
def test_album_detail(self):
user = PyrosUser.objects.get(username="pyros")
self.client.force_authenticate(user=user)
url = '/api/albums/1'
response = self.client.get(url,follow=True)
self.assertEqual(response.status_code,200)
self.assertEqual(response.data.get("name"),Album.objects.get(id=1).name)
def test_plan_list(self):
user = PyrosUser.objects.get(username="pyros")
self.client.force_authenticate(user=user)
url = '/api/plans/'
response = self.client.get(url,follow=True)
self.assertEqual(response.status_code,200)
self.assertEqual(len(response.data),Plan.objects.all().count())
def test_plan_detail(self):
user = PyrosUser.objects.get(username="pyros")
self.client.force_authenticate(user=user)
url = '/api/plans/1'
response = self.client.get(url,follow=True)
self.assertEqual(response.status_code,200)
self.assertEqual(response.data.get("id"),Plan.objects.get(id=1).id)
def test_full_sequence_list(self):
user = PyrosUser.objects.get(username="pyros")
self.client.force_authenticate(user=user)
url = '/api/full_sequences/'
response = self.client.get(url,follow=True)
self.assertEqual(response.status_code,200)
self.assertEqual(len(response.data),Sequence.objects.all().count())
def test_full_sequence_detail(self):
user = PyrosUser.objects.get(username="pyros")
self.client.force_authenticate(user=user)
url = '/api/full_sequences/1'
response = self.client.get(url,follow=True)
self.assertEqual(response.status_code,200)
self.assertEqual(response.data.get("name"),Sequence.objects.get(id=1).name)
def test_scientific_program_list(self):
user = PyrosUser.objects.get(username="pyros")
self.client.force_authenticate(user=user)
url = '/api/scientific_programs/'
response = self.client.get(url,follow=True)
self.assertEqual(response.status_code,200)
self.assertEqual(len(response.data),ScientificProgram.objects.all().count())
def test_full_sequence_detail(self):
user = PyrosUser.objects.get(username="pyros")
self.client.force_authenticate(user=user)
url = '/api/scientific_programs/1'
response = self.client.get(url,follow=True)
self.assertEqual(response.status_code,200)
self.assertEqual(response.data.get("name"),ScientificProgram.objects.get(id=1).name)