diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_api_bot_snake.py | 62 | ||||
| -rw-r--r-- | tests/test_api_bot_tags.py | 2 | ||||
| -rw-r--r-- | tests/test_clean_logs.py | 88 | ||||
| -rw-r--r-- | tests/test_roots.py | 1 | 
4 files changed, 132 insertions, 21 deletions
diff --git a/tests/test_api_bot_snake.py b/tests/test_api_bot_snake.py index b5aa3bab..fcc18409 100644 --- a/tests/test_api_bot_snake.py +++ b/tests/test_api_bot_snake.py @@ -1,42 +1,64 @@ -import os +"""Tests the `/api/bot/snake_` endpoints.""" +  from tests import SiteTest, app -class ApiBotSnakeEndpoints(SiteTest): -    """ -    Tests the following endpoints: -        - snake_movies -        - snake_quiz -        - snake_names -        - snake_idioms -        - snake_facts -    """ + +class TestSnakeFactsAPI(SiteTest): +    """GET method - get snake fact"""      def test_snake_facts(self): -        # GET method - get snake fact -        response = self.client.get('/bot/snake_facts', app.config['API_SUBDOMAIN'], headers=app.config['TEST_HEADER']) +        response = self.client.get( +            '/bot/snake_facts', +            app.config['API_SUBDOMAIN'], +            headers=app.config['TEST_HEADER'] +        )          self.assertEqual(response.status_code, 200)          self.assertEqual(type(response.json), str) + +class TestSnakeIdiomAPI(SiteTest): +    """GET method - get snake idiom""" +      def test_snake_idiom(self): -        # GET method - get snake idiom -        response = self.client.get('/bot/snake_idioms', app.config['API_SUBDOMAIN'], headers=app.config['TEST_HEADER']) +        response = self.client.get( +            '/bot/snake_idioms', +            app.config['API_SUBDOMAIN'], +            headers=app.config['TEST_HEADER'] +        )          self.assertEqual(response.status_code, 200)          self.assertEqual(type(response.json), str) + +class TestSnakeQuizAPI(SiteTest): +    """GET method - get snake quiz""" +      def test_snake_quiz(self): -        # GET method - get snake quiz -        response = self.client.get('/bot/snake_quiz', app.config['API_SUBDOMAIN'], headers=app.config['TEST_HEADER']) +        response = self.client.get( +            '/bot/snake_quiz', +            app.config['API_SUBDOMAIN'], +            headers=app.config['TEST_HEADER'] +        )          self.assertEqual(response.status_code, 200)          self.assertEqual(type(response.json), dict) + +class TestSnakeNameAPI(SiteTest): +    """GET method - get a single snake name, or all of them.""" +      def test_snake_names(self): -        # GET method - get snake name -        response = self.client.get('/bot/snake_names', app.config['API_SUBDOMAIN'], headers=app.config['TEST_HEADER']) +        response = self.client.get( +            '/bot/snake_names', +            app.config['API_SUBDOMAIN'], +            headers=app.config['TEST_HEADER'] +        )          self.assertEqual(response.status_code, 200)          self.assertEqual(type(response.json), dict)      def test_snake_names_all(self): -        # GET method - get all snake names -        response = self.client.get('/bot/snake_names?get_all=True', app.config['API_SUBDOMAIN'], headers=app.config['TEST_HEADER']) +        response = self.client.get( +            '/bot/snake_names?get_all=True', +            app.config['API_SUBDOMAIN'], +            headers=app.config['TEST_HEADER'] +        )          self.assertEqual(response.status_code, 200)          self.assertEqual(type(response.json), list) diff --git a/tests/test_api_bot_tags.py b/tests/test_api_bot_tags.py index 66940f7e..fa06e0fa 100644 --- a/tests/test_api_bot_tags.py +++ b/tests/test_api_bot_tags.py @@ -1,7 +1,7 @@ -import os  import json  from tests import SiteTest, app +  class ApiBotTagsEndpoint(SiteTest):      def test_api_tags(self): diff --git a/tests/test_clean_logs.py b/tests/test_clean_logs.py new file mode 100644 index 00000000..fe0c5ac7 --- /dev/null +++ b/tests/test_clean_logs.py @@ -0,0 +1,88 @@ +"""Tests the `/api/bot/clean` endpoint.""" +import json + +from tests import SiteTest, app + + +class TestCleanLogAPI(SiteTest): +    """ +    Tests submitting a clean log and +    verifies that we get a UUID in return. + +    Then tests that +    """ + +    def test_returns_400_on_bad_data(self): +        bad_data = json.dumps({ +            "scubfire": "testiclaes" +        }) + +        response = self.client.post( +            '/bot/clean', +            app.config['API_SUBDOMAIN'], +            headers=app.config['TEST_HEADER'], +            data=bad_data +        ) +        self.assert400(response) + +    def test_submit_clean_log(self): +        good_data = json.dumps({ +            "log_data": [ +                { +                    "author":    "something", +                    "content":   "testy", +                    "timestamp": "this way comes" +                } +            ] +        }) + +        response = self.client.post( +            '/bot/clean', +            app.config['API_SUBDOMAIN'], +            headers=app.config['TEST_HEADER'], +            data=good_data +        ) + +        log_id = response.json.get("log_id") + +        self.assert200(response) +        self.assertIsNotNone(log_id) +        self.assertGreater(len(log_id), 2) +        self.assertEqual(type(log_id), str) + + +class TestCleanLogFrontEnd(SiteTest): +    """ +    Tests the frontend for +    viewing the clean logs. +    """ + +    def test_clean_log_frontend_returns_200(self): + +        # Get a log ID +        good_data = json.dumps({ +            "log_data": [ +                { +                    "author":    "something", +                    "content":   "testy", +                    "timestamp": "this way comes" +                } +            ] +        }) + +        response = self.client.post( +            '/bot/clean', +            app.config['API_SUBDOMAIN'], +            headers=app.config['TEST_HEADER'], +            data=good_data +        ) + +        log_id = response.json.get("log_id") + +        # Now try to access it. +        response = self.client.get( +            f'/bot/clean_logs/{log_id}' +        ) + +        self.assert200(response) +        self.assertIn("testy", response.text)
\ No newline at end of file diff --git a/tests/test_roots.py b/tests/test_roots.py index 0b7b129c..1b270178 100644 --- a/tests/test_roots.py +++ b/tests/test_roots.py @@ -3,6 +3,7 @@ from pysite.constants import DISCORD_OAUTH_REDIRECT  from pysite.constants import DISCORD_OAUTH_AUTHORIZED  from pysite.constants import ERROR_DESCRIPTIONS +  class RootEndpoint(SiteTest):      """ Test cases for the root endpoint and error handling """  |