From af54db6c136138c66cf5ca72419989525a0baa5c Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Tue, 7 Aug 2018 15:09:08 +0100 Subject: Initial project layout for django --- tests/test_api_bot_bigbrother.py | 152 --------------------------------------- 1 file changed, 152 deletions(-) delete mode 100644 tests/test_api_bot_bigbrother.py (limited to 'tests/test_api_bot_bigbrother.py') diff --git a/tests/test_api_bot_bigbrother.py b/tests/test_api_bot_bigbrother.py deleted file mode 100644 index b1060e72..00000000 --- a/tests/test_api_bot_bigbrother.py +++ /dev/null @@ -1,152 +0,0 @@ -import json - -from tests import SiteTest, app - - -class EmptyDatabaseEndpointTests(SiteTest): - def test_api_docs_get_all(self): - response = self.client.get( - '/bot/bigbrother', - app.config['API_SUBDOMAIN'], - headers=app.config['TEST_HEADER'] - ) - self.assert200(response) - self.assertIsInstance(response.json, list) - - def test_fetching_single_entry_returns_404(self): - response = self.client.get( - '/bot/bigbrother?user_id=01932', - app.config['API_SUBDOMAIN'], - headers=app.config['TEST_HEADER'] - ) - self.assert404(response) - self.assertIsInstance(response.json['error_message'], str) - - -class AddingAnEntryEndpointTests(SiteTest): - GOOD_DATA = { - 'user_id': '42', - 'channel_id': '55' - } - GOOD_DATA_JSON = json.dumps(GOOD_DATA) - - def setUp(self): - response = self.client.post( - '/bot/bigbrother', - app.config['API_SUBDOMAIN'], - headers=app.config['TEST_HEADER'], - data=self.GOOD_DATA_JSON - ) - self.assertEqual(response.status_code, 204) - - def test_entry_is_in_all_entries(self): - response = self.client.get( - '/bot/bigbrother', - app.config['API_SUBDOMAIN'], - headers=app.config['TEST_HEADER'] - ) - self.assert200(response) - self.assertIn(self.GOOD_DATA, response.json) - - def test_can_fetch_entry_with_param_lookup(self): - response = self.client.get( - f'/bot/bigbrother?user_id={self.GOOD_DATA["user_id"]}', - app.config['API_SUBDOMAIN'], - headers=app.config['TEST_HEADER'] - ) - self.assert200(response) - self.assertEqual(response.json, self.GOOD_DATA) - - -class UpdatingAnEntryEndpointTests(SiteTest): - ORIGINAL_DATA = { - 'user_id': '300', - 'channel_id': '400' - } - ORIGINAL_DATA_JSON = json.dumps(ORIGINAL_DATA) - UPDATED_DATA = { - 'user_id': '300', - 'channel_id': '500' - } - UPDATED_DATA_JSON = json.dumps(UPDATED_DATA) - - def setUp(self): - response = self.client.post( - '/bot/bigbrother', - app.config['API_SUBDOMAIN'], - headers=app.config['TEST_HEADER'], - data=self.ORIGINAL_DATA_JSON - ) - self.assertEqual(response.status_code, 204) - - def test_can_update_data(self): - response = self.client.post( - '/bot/bigbrother', - app.config['API_SUBDOMAIN'], - headers=app.config['TEST_HEADER'], - data=self.UPDATED_DATA_JSON - ) - self.assertEqual(response.status_code, 204) - - -class DeletingAnEntryEndpointTests(SiteTest): - SAMPLE_DATA = { - 'user_id': '101', - 'channel_id': '202' - } - SAMPLE_DATA_JSON = json.dumps(SAMPLE_DATA) - - def setUp(self): - response = self.client.post( - '/bot/bigbrother', - app.config['API_SUBDOMAIN'], - headers=app.config['TEST_HEADER'], - data=self.SAMPLE_DATA_JSON - ) - self.assertEqual(response.status_code, 204) - - def test_delete_entry_returns_204(self): - response = self.client.delete( - f'/bot/bigbrother?user_id={self.SAMPLE_DATA["user_id"]}', - app.config['API_SUBDOMAIN'], - headers=app.config['TEST_HEADER'] - ) - self.assertEqual(response.status_code, 204) - - -class SchemaValidationTests(SiteTest): - def test_get_with_invalid_user_id_param_returns_400(self): - response = self.client.get( - '/bot/bigbrother?user_id=lemon-is-not-a-number', - app.config['API_SUBDOMAIN'], - headers=app.config['TEST_HEADER'] - ) - - self.assert400(response) - self.assertIsInstance(response.json['error_message'], str) - - def test_post_with_invalid_data_returns_400(self): - bad_data_json = json.dumps({ - 'user_id': "I'M A NUMBER I SWEAR", - 'channel_id': '42' - }) - - response = self.client.post( - '/bot/bigbrother', - app.config['API_SUBDOMAIN'], - headers=app.config['TEST_HEADER'], - data=bad_data_json - ) - - self.assert400(response) - self.assertIsInstance(response.json['error_message'], str) - - def test_delete_with_invalid_user_id_param_returns_400(self): - response = self.client.delete( - '/bot/bigbrother?user_id=totally-a-valid-number', - app.config['API_SUBDOMAIN'], - headers=app.config['TEST_HEADER'] - ) - - self.assert400(response) - self.assertIsInstance(response.json['error_message'], str) -- cgit v1.2.3