aboutsummaryrefslogtreecommitdiffstats
path: root/app_test.py
diff options
context:
space:
mode:
authorGravatar Leon Sandøy <[email protected]>2018-05-19 20:13:51 +0200
committerGravatar GitHub <[email protected]>2018-05-19 20:13:51 +0200
commit4bba9d0cdf8361e5529281a98d14bc4bb0ceb669 (patch)
tree5747395e8dae9a42f6935da1979bb2a88abaef75 /app_test.py
parent[Jams] Some amount of public display, but links not ready yet (diff)
Snake cog (#71)
* Tables that are initialized with JSON files in the table_init folder will now sync properly if the JSON file is changed after initialization. Any lines that are either added or removed will be updated whenever site is rebooted. * Initial API endpoint for snake_quiz * reverting database.py * I WILL KILL YOU * Added the snake_fact API endpoint * Moving snake tables to the new migrations system * Set up initial data for all new tables, added table objects, wrote endpoints, and wrote tests for the new endpoints. * Removing the snake_movies endpoint. That idea didn't pan out. * Added an endpoint for getting special snake cases * broken json * Fixing the initial data slightly, better picture of bob. * Changing JSON indentation to be 4 spaces consistently in all initial_data, to address Aperture's review. Also changing all the endpoints to have correct namespacing, addressing gdude's review. * Fixing tests to point to new API endpoints
Diffstat (limited to 'app_test.py')
-rw-r--r--app_test.py66
1 files changed, 52 insertions, 14 deletions
diff --git a/app_test.py b/app_test.py
index 150dd0b5..bc565112 100644
--- a/app_test.py
+++ b/app_test.py
@@ -161,6 +161,44 @@ class ApiEndpoints(SiteTest):
self.assertEqual(response.json, {'status': 'ok'})
self.assertEqual(response.status_code, 200)
+ def test_snake_endpoints(self):
+ """
+ Tests the following endpoints:
+ - snake_movies
+ - snake_quiz
+ - snake_names
+ - snake_idioms
+ - snake_facts
+ """
+
+ os.environ['BOT_API_KEY'] = 'abcdefg'
+ headers = {'X-API-Key': 'abcdefg', 'Content-Type': 'application/json'}
+
+ # GET method - get snake fact
+ response = self.client.get('/bot/snake_facts', app.config['API_SUBDOMAIN'], headers=headers)
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(type(response.json), str)
+
+ # GET method - get snake idiom
+ response = self.client.get('/bot/snake_idioms', app.config['API_SUBDOMAIN'], headers=headers)
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(type(response.json), str)
+
+ # GET method - get snake quiz
+ response = self.client.get('/bot/snake_quiz', app.config['API_SUBDOMAIN'], headers=headers)
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(type(response.json), dict)
+
+ # GET method - get snake name
+ response = self.client.get('/bot/snake_names', app.config['API_SUBDOMAIN'], headers=headers)
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(type(response.json), dict)
+
+ # GET method - get all snake names
+ response = self.client.get('/bot/snake_names?get_all=True', app.config['API_SUBDOMAIN'], headers=headers)
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(type(response.json), list)
+
def test_api_tags(self):
""" Check tag API """
os.environ['BOT_API_KEY'] = 'abcdefg'
@@ -180,33 +218,33 @@ class ApiEndpoints(SiteTest):
})
# POST method - no headers
- response = self.client.post('/tags', app.config['API_SUBDOMAIN'])
+ response = self.client.post('/bot/tags', app.config['API_SUBDOMAIN'])
self.assertEqual(response.status_code, 401)
# POST method - no data
- response = self.client.post('/tags', app.config['API_SUBDOMAIN'], headers=headers)
+ response = self.client.post('/bot/tags', app.config['API_SUBDOMAIN'], headers=headers)
self.assertEqual(response.status_code, 400)
# POST method - bad data
- response = self.client.post('/tags', app.config['API_SUBDOMAIN'], headers=headers, data=bad_data)
+ response = self.client.post('/bot/tags', app.config['API_SUBDOMAIN'], headers=headers, data=bad_data)
self.assertEqual(response.status_code, 400)
# POST method - save tag
- response = self.client.post('/tags', app.config['API_SUBDOMAIN'], headers=headers, data=post_data)
+ response = self.client.post('/bot/tags', app.config['API_SUBDOMAIN'], headers=headers, data=post_data)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json, {"success": True})
# GET method - no headers
- response = self.client.get('/tags', app.config['API_SUBDOMAIN'])
+ response = self.client.get('/bot/tags', app.config['API_SUBDOMAIN'])
self.assertEqual(response.status_code, 401)
# GET method - get all tags
- response = self.client.get('/tags', app.config['API_SUBDOMAIN'], headers=headers)
+ response = self.client.get('/bot/tags', app.config['API_SUBDOMAIN'], headers=headers)
self.assertEqual(response.status_code, 200)
self.assertEqual(type(response.json), list)
# GET method - get specific tag
- response = self.client.get('/tags?tag_name=testing', app.config['API_SUBDOMAIN'], headers=headers)
+ response = self.client.get('/bot/tags?tag_name=testing', app.config['API_SUBDOMAIN'], headers=headers)
self.assertEqual(response.json, {
'tag_content': 'testing',
'tag_name': 'testing'
@@ -214,19 +252,19 @@ class ApiEndpoints(SiteTest):
self.assertEqual(response.status_code, 200)
# DELETE method - no headers
- response = self.client.delete('/tags', app.config['API_SUBDOMAIN'])
+ response = self.client.delete('/bot/tags', app.config['API_SUBDOMAIN'])
self.assertEqual(response.status_code, 401)
# DELETE method - no data
- response = self.client.delete('/tags', app.config['API_SUBDOMAIN'], headers=headers)
+ response = self.client.delete('/bot/tags', app.config['API_SUBDOMAIN'], headers=headers)
self.assertEqual(response.status_code, 400)
# DELETE method - bad data
- response = self.client.delete('/tags', app.config['API_SUBDOMAIN'], headers=headers, data=bad_data)
+ response = self.client.delete('/bot/tags', app.config['API_SUBDOMAIN'], headers=headers, data=bad_data)
self.assertEqual(response.status_code, 400)
# DELETE method - delete the testing tag
- response = self.client.delete('/tags', app.config['API_SUBDOMAIN'], headers=headers, data=get_data)
+ response = self.client.delete('/bot/tags', app.config['API_SUBDOMAIN'], headers=headers, data=get_data)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json, {"success": True})
@@ -238,13 +276,13 @@ class ApiEndpoints(SiteTest):
single_data = json.dumps({'user_id': "1234", 'roles': ["5678"], "username": "test", "discriminator": "0000"})
list_data = json.dumps([{'user_id': "1234", 'roles': ["5678"], "username": "test", "discriminator": "0000"}])
- response = self.client.get('/user', app.config['API_SUBDOMAIN'], headers=headers)
+ response = self.client.get('/bot/users', app.config['API_SUBDOMAIN'], headers=headers)
self.assertEqual(response.status_code, 405)
- response = self.client.post('/user', app.config['API_SUBDOMAIN'], headers=headers, data=single_data)
+ response = self.client.post('/bot/users', app.config['API_SUBDOMAIN'], headers=headers, data=single_data)
self.assertTrue("inserted" in response.json)
- response = self.client.post('/user', app.config['API_SUBDOMAIN'], headers=headers, data=list_data)
+ response = self.client.post('/bot/users', app.config['API_SUBDOMAIN'], headers=headers, data=list_data)
self.assertTrue("inserted" in response.json)
def test_api_route_errors(self):