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
|
from django_hosts.resolvers import reverse
from .base import APISubdomainTestCase
from ..models import Nomination, User
class NominationTests(APISubdomainTestCase):
@classmethod
def setUpTestData(cls): # noqa
cls.author = User.objects.create(
id=5152,
name='Ro Bert',
discriminator=256,
avatar_hash=None
)
cls.user = cls.author
cls.nomination = Nomination.objects.create(
author=cls.author,
reason="he's good",
user=cls.author
)
def test_returns_400_on_attempt_to_update_frozen_field(self):
url = reverse('bot:nomination-detail', args=(self.user.id,), host='api')
response = self.client.put(
url,
data={'inserted_at': 'something bad'}
)
self.assertEqual(response.status_code, 400)
self.assertEqual(response.json(), {
'inserted_at': ['This field cannot be updated.']
})
def test_returns_200_on_successful_update(self):
url = reverse('bot:nomination-detail', args=(self.user.id,), host='api')
response = self.client.patch(
url,
data={'reason': 'there are many like it, but this test is mine'}
)
self.assertEqual(response.status_code, 200)
|