|
| 1 | +import os |
| 2 | +import unittest |
| 3 | +from lambda_app.boot import load_dot_env, reset, is_loaded, load_env |
| 4 | +from tests.unit.testutils import BaseUnitTestCase, get_function_name |
| 5 | +from unittest_data_provider import data_provider |
| 6 | + |
| 7 | + |
| 8 | +def get_env(): |
| 9 | + return (None, True), ('dev', True), ('development', True), ('integration', True), ('staging', True), ( |
| 10 | + 'production', True) |
| 11 | + |
| 12 | + |
| 13 | +def get_load_dot_env(): |
| 14 | + return (None, True), ('dev', True), ('development', True), ('integration', False), ('staging', False), ( |
| 15 | + 'production', False) |
| 16 | + |
| 17 | + |
| 18 | +class BootTestCase(BaseUnitTestCase): |
| 19 | + |
| 20 | + @data_provider(get_env) |
| 21 | + def test_load_env(self, env, expected): |
| 22 | + self.logger.info('Running test: %s - %s', get_function_name(__name__), env) |
| 23 | + APP_TYPE = os.environ['APP_TYPE'] |
| 24 | + self.logger.info("APP_TYPE: {}".format(APP_TYPE)) |
| 25 | + if APP_TYPE == 'Chalice': |
| 26 | + reset() |
| 27 | + load_env(env) |
| 28 | + self.assertEqual(is_loaded(), expected) |
| 29 | + else: |
| 30 | + self.skipTest('test_load_env - Ignored because the APP_TYPE {}'.format(APP_TYPE)) |
| 31 | + |
| 32 | + @data_provider(get_load_dot_env) |
| 33 | + def test_load_dot_env(self, env, expected): |
| 34 | + self.logger.info('Running test: %s - %s', get_function_name(__name__), env) |
| 35 | + APP_TYPE = os.environ['APP_TYPE'] |
| 36 | + self.logger.info("APP_TYPE: {}".format(APP_TYPE)) |
| 37 | + |
| 38 | + if APP_TYPE == 'Flask': |
| 39 | + # AWS Image condition |
| 40 | + if 'ENVIRONMENT_NAME' in os.environ: |
| 41 | + if env == os.environ['ENVIRONMENT_NAME']: |
| 42 | + expected = True |
| 43 | + reset() |
| 44 | + load_dot_env(env) |
| 45 | + self.assertEqual(is_loaded(), expected) |
| 46 | + else: |
| 47 | + self.skipTest('test_load_dot_env - Ignored because the APP_TYPE {}'.format(APP_TYPE)) |
| 48 | + |
| 49 | + |
| 50 | +if __name__ == '__main__': |
| 51 | + unittest.main() |
0 commit comments