Example #1
0
 def test_get_results_by_id(self, get_table_responses_mock):
     # Given
     get_table_responses_mock.return_value = {"id": 1, "responses": []}
     # When
     with app.app_context():
         result = api.get_result_by_id(1)
     # Then
     self.assertEqual({"id": 1, "responses": []}, result.get_json())
Example #2
0
 def test_get_question_by_id(self, get_questions_mock):
     # Given
     the_question = "?"
     get_questions_mock.return_value = [{"id": 1, "question": the_question}]
     # When
     with app.app_context():
         result = api.get_question_by_id("1")
     # Then
     self.assertEqual({"id": 1, "question": "?"}, result.get_json())
Example #3
0
 def test_api_root(self, get_table_responses_mock):
     # Given
     get_table_responses_mock.return_value = {"id": 1, "responses": []}
     # When
     with app.app_context():
         result = api.get_api_root()
     # Then
     endpoints = result.get_json()["endpoints"]
     with app.test_client() as client:
         for url in endpoints.values():
             self.assertIsNotNone(client.get(url).get_json())
Example #4
0
 def test_get_songs(self, get_song_name_mock, get_song_lyrics_mock):
     # Given
     get_song_name_mock.return_value = "hej"
     get_song_lyrics_mock.return_value = "boll"
     expected_rsp = {str(i): {
         "name": "hej",
         "lyrics": "boll"
     } for i in range(1, 10)}
     # When
     with app.app_context():
         result = api.get_songs()
     # Then
     self.assertEqual(expected_rsp, result.get_json())
Example #5
0
 def test_get_song_by_id(self, get_song_name_mock, get_song_lyrics_mock):
     # Given
     get_song_name_mock.return_value = "hej"
     get_song_lyrics_mock.return_value = "boll"
     # When
     with app.app_context():
         result = api.get_songs_by_id(1)
     # Then
     self.assertEqual(
         {
             "id": 1,
             "song": {
                 "name": "hej",
                 "lyrics": "boll"
             }
         }, result.get_json())
Example #6
0
 def verify_rendering(self, endpoint):
     with app.app_context():
         page = endpoint()
     self.assertIsNotNone(page)
     return page