From e7e354221679f4d132a41286448a3daf09f452ac Mon Sep 17 00:00:00 2001 From: Carmeli Tamir Date: Thu, 9 Apr 2020 05:35:42 -0400 Subject: [PATCH] 1. Testing results for existing identifiers. 2. Testing version parameter options --- t/api_test.py | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/t/api_test.py b/t/api_test.py index a7fafb8..52e5d6d 100644 --- a/t/api_test.py +++ b/t/api_test.py @@ -2,6 +2,7 @@ import os import sys +import falcon from falcon import testing api_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..','api')) @@ -15,9 +16,43 @@ class APITest(testing.TestCase): self.app = create_ident_getter() -class TestMyApp(APITest): def test_identifier_not_found(self): result = self.simulate_get('/ident/tree/SOME_NONEXISTENT_IDENTIFIER', query_string="version=latest") self.assertEqual(result.status_code, 200) - self.assertEqual(result.json, {'definitions': [], 'references':[]}) \ No newline at end of file + self.assertEqual(result.json, {'definitions': [], 'references':[]}) + + def test_missing_version(self): + # A get request without a version query string + result = self.simulate_get('/ident/tree/of_i2c_get_board_info') + + self.assertEqual(result.status_code, 400) + + required_response = falcon.HTTPMissingParam('version') + self.assertEqual(result.json["title"], required_response.title) + self.assertEqual(result.json["description"], required_response.description) + + def test_existing_identifier(self): + result_for_specific_version = self.simulate_get('/ident/tree/of_i2c_get_board_info', query_string="version=v5.4") + result_for_latest_version = self.simulate_get('/ident/tree/of_i2c_get_board_info', query_string="version=latest") + + expected_json = { + 'definitions': + [ + {'path': 'drivers/i2c/i2c-core-of.c', 'line': 22, 'type': 'function'}, + {'path': 'drivers/i2c/i2c-core-of.c', 'line': 62, 'type': 'variable'}, + {'path': 'include/linux/i2c.h', 'line': 968, 'type': 'function'}, + {'path': 'include/linux/i2c.h', 'line': 941, 'type': 'prototype'} + ], + 'references': + [ + {'path': 'drivers/i2c/i2c-core-of.c', 'line': '22,62,73', 'type': None}, + {'path': 'include/linux/i2c.h', 'line': '941,968', 'type': None} + ] + } + + self.assertEqual(result_for_specific_version.status_code, 200) + self.assertEqual(result_for_latest_version.status_code, 200) + + self.assertEqual(result_for_specific_version.json, expected_json) + self.assertEqual(result_for_latest_version.json, expected_json) \ No newline at end of file