diff options
| author | 2019-02-18 21:13:21 +0100 | |
|---|---|---|
| committer | 2019-02-18 21:13:21 +0100 | |
| commit | 384925ca093037421b429119850b7b397a1e86e3 (patch) | |
| tree | 3771580e368aa4845e15a18363284072c6df6c48 /api | |
| parent | Add `# pragma: no cover` to downwards migration. (diff) | |
Add nomination API test cases.
Diffstat (limited to 'api')
| -rw-r--r-- | api/tests/test_nominations.py | 41 | 
1 files changed, 41 insertions, 0 deletions
| diff --git a/api/tests/test_nominations.py b/api/tests/test_nominations.py new file mode 100644 index 00000000..1f03d1b0 --- /dev/null +++ b/api/tests/test_nominations.py @@ -0,0 +1,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) | 
