diff options
author | 2019-04-25 23:19:21 +0200 | |
---|---|---|
committer | 2019-04-25 23:19:21 +0200 | |
commit | 3013eaa9db61472ddf52b8f75219e8a908f30f7e (patch) | |
tree | 7361e78cf2aec8a2af8882e8c4fedf2e797867ca /pydis_site/apps/api/tests | |
parent | Resolving merge conflict with master (diff) |
Adding CreationTests to test_nomination and making related changes in the ViewSet
Diffstat (limited to 'pydis_site/apps/api/tests')
-rw-r--r-- | pydis_site/apps/api/tests/test_nominations.py | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/pydis_site/apps/api/tests/test_nominations.py b/pydis_site/apps/api/tests/test_nominations.py index 99a3fe69..258c2cd7 100644 --- a/pydis_site/apps/api/tests/test_nominations.py +++ b/pydis_site/apps/api/tests/test_nominations.py @@ -70,3 +70,134 @@ class CreationTests(APISubdomainTestCase): dt.now(timezone.utc), delta=timedelta(seconds=2) ) + self.assertEqual(nomination.user.id, data['user']) + self.assertEqual(nomination.actor.id, data['actor']) + self.assertEqual(nomination.reason, data['reason']) + self.assertEqual(nomination.active, True) + + def test_returns_400_for_missing_user(self): + url = reverse('bot:nomination-list', host='api') + data = { + 'actor': self.user.id, + 'reason': 'Joe Dart on Fender Bass', + } + + response = self.client.post(url, data=data) + self.assertEqual(response.status_code, 400) + self.assertEqual(response.json(), { + 'user': ['This field is required.'] + }) + + def test_returns_400_for_missing_actor(self): + url = reverse('bot:nomination-list', host='api') + data = { + 'user': self.user.id, + 'reason': 'Joe Dart on Fender Bass', + } + + response = self.client.post(url, data=data) + self.assertEqual(response.status_code, 400) + self.assertEqual(response.json(), { + 'actor': ['This field is required.'] + }) + + def test_returns_400_for_missing_reason(self): + url = reverse('bot:nomination-list', host='api') + data = { + 'user': self.user.id, + 'actor': self.user.id, + } + + response = self.client.post(url, data=data) + self.assertEqual(response.status_code, 400) + self.assertEqual(response.json(), { + 'reason': ['This field is required.'] + }) + + def test_returns_400_for_bad_user(self): + url = reverse('bot:nomination-list', host='api') + data = { + 'user': 1024, + 'reason': 'Joe Dart on Fender Bass', + 'actor': self.user.id, + } + + response = self.client.post(url, data=data) + self.assertEqual(response.status_code, 400) + self.assertEqual(response.json(), { + 'user': ['Invalid pk "1024" - object does not exist.'] + }) + + def test_returns_400_for_bad_actor(self): + url = reverse('bot:nomination-list', host='api') + data = { + 'user': self.user.id, + 'reason': 'Joe Dart on Fender Bass', + 'actor': 1024, + } + + response = self.client.post(url, data=data) + self.assertEqual(response.status_code, 400) + self.assertEqual(response.json(), { + 'actor': ['Invalid pk "1024" - object does not exist.'] + }) + + def test_returns_400_for_unnominate_reason_at_creation(self): + url = reverse('bot:nomination-list', host='api') + data = { + 'user': self.user.id, + 'reason': 'Joe Dart on Fender Bass', + 'actor': self.user.id, + 'unnominate_reason': "Joe Dart on the Joe Dart Bass" + } + + response = self.client.post(url, data=data) + self.assertEqual(response.status_code, 400) + self.assertEqual(response.json(), { + 'unnominate_reason': ['This field cannot be set at creation.'] + }) + + def test_returns_400_for_unwatched_at_at_creation(self): + url = reverse('bot:nomination-list', host='api') + data = { + 'user': self.user.id, + 'reason': 'Joe Dart on Fender Bass', + 'actor': self.user.id, + 'unwatched_at': "Joe Dart on the Joe Dart Bass" + } + + response = self.client.post(url, data=data) + self.assertEqual(response.status_code, 400) + self.assertEqual(response.json(), { + 'unwatched_at': ['This field cannot be set at creation.'] + }) + + def test_returns_400_for_inserted_at_at_creation(self): + url = reverse('bot:nomination-list', host='api') + data = { + 'user': self.user.id, + 'reason': 'Joe Dart on Fender Bass', + 'actor': self.user.id, + 'inserted_at': "Joe Dart on the Joe Dart Bass" + } + + response = self.client.post(url, data=data) + self.assertEqual(response.status_code, 400) + self.assertEqual(response.json(), { + 'inserted_at': ['This field cannot be set at creation.'] + }) + + def test_returns_400_for_active_at_creation(self): + url = reverse('bot:nomination-list', host='api') + data = { + 'user': self.user.id, + 'reason': 'Joe Dart on Fender Bass', + 'actor': self.user.id, + 'active': False + } + + response = self.client.post(url, data=data) + self.assertEqual(response.status_code, 400) + self.assertEqual(response.json(), { + 'active': ['This field cannot be set at creation.'] + }) |