Newer
Older
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
from rest_framework.test import APITransactionTestCase
from program.tests import HostMixin, ImageMixin, SteeringTestCaseMixin, UserMixin
class HostViewTestCase(
HostMixin, ImageMixin, UserMixin, SteeringTestCaseMixin, APITransactionTestCase
):
reset_sequences = True
def test_create_host(self):
client = self._get_client(self.user_admin)
url = self._url("hosts")
host_data = {"name": "NAME"}
response = client.post(url, data=host_data)
self.assertEqual(response.status_code, 201)
self.assertEqual(response.data["name"], host_data["name"])
def test_create_host_forbidden_for_common_user(self):
client = self._get_client()
url = self._url("hosts")
response = client.post(url, data={"name": "NAME"})
self.assertEqual(response.status_code, 403)
def test_destroy_host(self):
host = self._create_host()
client = self._get_client(self.user_admin)
url = self._url("hosts", host.id)
response = client.delete(url)
self.assertEqual(response.status_code, 204)
def test_destroy_host_forbidden_for_common_user(self):
host = self._create_host()
client = self._get_client(self.user_common)
url = self._url("hosts", host.id)
response = client.delete(url)
self.assertEqual(response.status_code, 403)
def test_list_hosts(self):
client = self._get_client()
url = self._url("hosts")
for _ in range(3):
self._create_host()
response = client.get(url)
self.assertEqual(len(response.data), 3)
def test_retrieve_host(self):
data = {"biography": "BIOGRAPHY", "email": "host@aura.radio", "name": "NAME"}
host = self._create_host(**data)
client = self._get_client()
url = self._url("hosts", host.id)
response = client.get(url)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data["biography"], data["biography"])
self.assertEqual(response.data["email"], data["email"])
self.assertEqual(response.data["name"], data["name"])
def test_update_biography(self):
host = self._create_host()
client = self._get_client(self.user_admin)
url = self._url("hosts", host.id)
update = {"biography": "BIOGRAPHY"}
response = client.patch(url, data=update)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data["biography"], update["biography"])
def test_update_email(self):
host = self._create_host()
client = self._get_client(self.user_admin)
url = self._url("hosts", host.id)
update = {"email": "host@aura.radio"}
response = client.patch(url, data=update)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data["email"], update["email"])
def test_update_image(self):
host = self._create_host()
image = self._create_image(owner=self.user_admin)
client = self._get_client(self.user_admin)
url = self._url("hosts", host.id)
update = {"image": image.id}
response = client.patch(url, data=update)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data["image"], image.id)
def test_update_is_active(self):
host = self._create_host()
client = self._get_client(self.user_admin)
url = self._url("hosts", host.id)
update = {"is_active": False}
response = client.patch(url, data=update)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data["is_active"], update["is_active"])
def test_update_name(self):
host = self._create_host()
client = self._get_client(self.user_admin)
url = self._url("hosts", host.id)
update = {"name": "HOST"}
response = client.patch(url, data=update)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data["name"], update["name"])
def test_update_host_forbidden_for_common_user(self):
host = self._create_host()
client = self._get_client(self.user_common)
url = self._url("hosts", host.id)
response = client.patch(url, data={"email": "host@aura.radio"})
self.assertEqual(response.status_code, 403)