diff options
author | 2018-07-02 19:27:19 +0000 | |
---|---|---|
committer | 2018-07-02 19:27:19 +0000 | |
commit | c24c1f1d5569e7bd5d76005f02629cc12cf5a9bd (patch) | |
tree | a8fe7d8ea8a2c754830014bc9b24a0ae216b39fa /tests | |
parent | Merge branch 'momo/optimize-team-list-v2' into 'master' (diff) |
Add a simple API for off-topic category names.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_api_bot_off_topic_names.py | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/tests/test_api_bot_off_topic_names.py b/tests/test_api_bot_off_topic_names.py new file mode 100644 index 00000000..4c9c782b --- /dev/null +++ b/tests/test_api_bot_off_topic_names.py @@ -0,0 +1,90 @@ +"""Tests the `/api/bot/off-topic-names` endpoint.""" + +from tests import SiteTest, app + + +class EmptyDatabaseOffTopicEndpointTests(SiteTest): + """Tests fetching all entries from the endpoint with an empty database.""" + + def test_get_returns_empty_list(self): + response = self.client.get( + '/bot/off-topic-names', + app.config['API_SUBDOMAIN'], + headers=app.config['TEST_HEADER'] + ) + self.assert200(response) + self.assertEqual(response.json, []) + + +class AddingANameOffTopicEndpointTests(SiteTest): + """Tests adding a channel name to the database.""" + + def test_returns_400_on_bad_data(self): + response = self.client.post( + '/bot/off-topic-names?name=my%20TOTALLY%20VALID%20CHANNE%20NAME', + app.config['API_SUBDOMAIN'], + headers=app.config['TEST_HEADER'] + ) + self.assert400(response) + + def test_can_add_new_package(self): + response = self.client.post( + '/bot/off-topic-names?name=lemons-lemon-shop', + app.config['API_SUBDOMAIN'], + headers=app.config['TEST_HEADER'] + ) + self.assert200(response) + + +class AddingChannelNameToDatabaseEndpointTests(SiteTest): + """Tests fetching names from the database with GET.""" + + CHANNEL_NAME = 'bisks-disks' + + def setUp(self): + response = self.client.post( + f'/bot/off-topic-names?name={self.CHANNEL_NAME}', + app.config['API_SUBDOMAIN'], + headers=app.config['TEST_HEADER'] + ) + self.assert200(response) + + def test_name_is_in_all_entries(self): + response = self.client.get( + '/bot/off-topic-names', + app.config['API_SUBDOMAIN'], + headers=app.config['TEST_HEADER'] + ) + self.assert200(response) + self.assertIn(self.CHANNEL_NAME, response.json) + + +class RandomSampleEndpointTests(SiteTest): + """Tests fetching random names from the website with GET.""" + + CHANNEL_NAME_1 = 'chicken-shed' + CHANNEL_NAME_2 = 'robot-kindergarten' + + def setUp(self): + response = self.client.post( + f'/bot/off-topic-names?name={self.CHANNEL_NAME_1}', + app.config['API_SUBDOMAIN'], + headers=app.config['TEST_HEADER'] + ) + self.assert200(response) + + response = self.client.post( + f'/bot/off-topic-names?name={self.CHANNEL_NAME_2}', + app.config['API_SUBDOMAIN'], + headers=app.config['TEST_HEADER'] + ) + self.assert200(response) + + def test_returns_limited_names_with_random_query_param(self): + response = self.client.get( + '/bot/off-topic-names?random_items=1', + app.config['API_SUBDOMAIN'], + headers=app.config['TEST_HEADER'] + ) + self.assert200(response) + self.assertEqual(len(response.json), 1) |