def example(): return { "GLOBAL_VARIABLE": GLOBAL_VARIABLE, "GLOBAL_VARIABLE2": GLOBAL_VARIABLE2, "test1": config().test1, "test2": config().test2, }
def test_configreload(self): os.environ[CONFIGMAP_FILE_ENVIRONMENT] = os.path.join( os.path.dirname(os.path.abspath(__file__)), self.file2) response = self.client.post("/reload-config") self.assertEqual(b"OK", response.data) self.assertEqual(200, response.status_code) self.assertEqual("reload2", config()["APP_NAME"])
import json import os import unittest from typing import Dict, List, Union, Text from pyms.constants import CONFIGMAP_FILE_ENVIRONMENT from pyms.flask.app import config from project.app import MyMicroservice backup_config = config() def _format_response(response: Text = "") -> Union[List, Dict]: # python3.5 compatibility if isinstance(response, bytes): response = str(response, encoding="utf-8") return json.loads(response) class ProjectTestCase(unittest.TestCase): BASE_DIR = os.path.dirname(os.path.abspath(__file__)) def setUp(self): os.environ[CONFIGMAP_FILE_ENVIRONMENT] = os.path.join( self.BASE_DIR, "config-tests.yml") ms = MyMicroservice( path=os.path.join(os.path.dirname(os.path.dirname(__file__)), "project", "test_views.py")) self.app = ms.create_app() self.base_url = self.app.config["APPLICATION_ROOT"]
from pyms.flask.app import config GLOBAL_VARIABLE = config().request_variable_test GLOBAL_VARIABLE2 = config().MyVar def example(): return { "GLOBAL_VARIABLE": GLOBAL_VARIABLE, "GLOBAL_VARIABLE2": GLOBAL_VARIABLE2, "test1": config().test1, "test2": config().test2, }
def test_config_singleton(self): conf_one = config().subservice1 conf_two = config().subservice1 assert conf_one == conf_two
def test_import_config_without_create_app(self): ms1 = MyMicroservice(path=__file__) self.assertEqual(ms1.config.subservice1, config().subservice1)