|
| 1 | +import inspect |
| 2 | +import unittest |
| 3 | + |
| 4 | +import jsonschema |
| 5 | + |
| 6 | +from . import docs, validate |
| 7 | + |
| 8 | + |
| 9 | +class SmokeTests(unittest.TestCase): |
| 10 | + """Tests to check that all functions, files and tests are defined |
| 11 | + in the evaluation function by the user. |
| 12 | +
|
| 13 | + Base Evaluation Function tests are no longer applied in the healthcheck, |
| 14 | + instead we only check that the necessary functions, classes and files |
| 15 | + are defined (here) and the user-defined tests pass. |
| 16 | +
|
| 17 | + Base Evaluation Function tests are only applied when pushing to Docker. |
| 18 | +
|
| 19 | + This test case also checks that all schemas are working appropriately. |
| 20 | + """ |
| 21 | + |
| 22 | + def test_import_evaluation_function(self): |
| 23 | + from .. import evaluation # type: ignore |
| 24 | + |
| 25 | + self.assertTrue(inspect.ismodule(evaluation)) |
| 26 | + self.assertIsNotNone(evaluation.evaluation_function) |
| 27 | + |
| 28 | + @unittest.skip("Ignored until all functions are updated with preview.") |
| 29 | + def test_import_preview_function(self): |
| 30 | + from .. import preview # type: ignore |
| 31 | + |
| 32 | + self.assertTrue(inspect.ismodule(preview)) |
| 33 | + self.assertIsNotNone(preview.preview_function) |
| 34 | + |
| 35 | + def test_import_evaluation_tests(self): |
| 36 | + from .. import evaluation_tests # type: ignore |
| 37 | + |
| 38 | + self.assertTrue(inspect.ismodule(evaluation_tests)) |
| 39 | + self.assertIsNotNone(evaluation_tests.TestEvaluationFunction) |
| 40 | + |
| 41 | + @unittest.skip("Ignored until all functions are updated with preview.") |
| 42 | + def test_import_preview_tests(self): |
| 43 | + from .. import preview_tests # type: ignore |
| 44 | + |
| 45 | + self.assertTrue(inspect.ismodule(preview_tests)) |
| 46 | + self.assertIsNotNone(preview_tests.TestPreviewFunction) |
| 47 | + |
| 48 | + def test_load_dev_docs(self): |
| 49 | + result = docs.dev() |
| 50 | + |
| 51 | + self.assertEqual(result["statusCode"], 200) |
| 52 | + self.assertDictEqual( |
| 53 | + result["headers"], {"Content-Type": "application/octet-stream"} |
| 54 | + ) |
| 55 | + self.assertTrue(result["isBase64Encoded"]) |
| 56 | + |
| 57 | + def test_load_user_docs(self): |
| 58 | + result = docs.user() |
| 59 | + |
| 60 | + self.assertEqual(result["statusCode"], 200) |
| 61 | + self.assertDictEqual( |
| 62 | + result["headers"], {"Content-Type": "application/octet-stream"} |
| 63 | + ) |
| 64 | + self.assertTrue(result["isBase64Encoded"]) |
| 65 | + |
| 66 | + def test_load_eval_req_schema(self): |
| 67 | + schema = validate.load_validator_from_url( |
| 68 | + validate.ReqBodyValidators.EVALUATION |
| 69 | + ) |
| 70 | + |
| 71 | + self.assertIsInstance(schema, jsonschema.Draft7Validator) |
| 72 | + |
| 73 | + def test_load_preview_req_schema(self): |
| 74 | + schema = validate.load_validator_from_url( |
| 75 | + validate.ReqBodyValidators.PREVIEW |
| 76 | + ) |
| 77 | + |
| 78 | + self.assertIsInstance(schema, jsonschema.Draft7Validator) |
| 79 | + |
| 80 | + def test_load_eval_res_schema(self): |
| 81 | + schema = validate.load_validator_from_url( |
| 82 | + validate.ResBodyValidators.EVALUATION |
| 83 | + ) |
| 84 | + |
| 85 | + self.assertIsInstance(schema, jsonschema.Draft7Validator) |
| 86 | + |
| 87 | + def test_load_preview_res_schema(self): |
| 88 | + schema = validate.load_validator_from_url( |
| 89 | + validate.ResBodyValidators.PREVIEW |
| 90 | + ) |
| 91 | + |
| 92 | + self.assertIsInstance(schema, jsonschema.Draft7Validator) |
| 93 | + |
| 94 | + def test_load_health_res_schema(self): |
| 95 | + schema = validate.load_validator_from_url( |
| 96 | + validate.ResBodyValidators.HEALTHCHECK |
| 97 | + ) |
| 98 | + |
| 99 | + self.assertIsInstance(schema, jsonschema.Draft7Validator) |
0 commit comments