Exemplo n.º 1
0
 def loadEnv(self):
     TEST_ENV = os.environ.get('TEST_ENV', TEST1)
     PATH = 'env' + os.sep + TEST_ENV
     dirname = os.getcwd()
     os.environ['ENV_PATH'] = os.path.join(dirname, PATH, 'host.env')
     os.environ["DATA_PATH"] = os.path.join(dirname, PATH, 'database.ini')
     os.environ['REDIS_PATH'] = os.path.join(dirname, PATH, 'redis.ini')
     envpath = os.environ['ENV_PATH']
     load_dot_env_file(envpath)
Exemplo n.º 2
0
 def test_load_custom_dot_env_file(self):
     dot_env_path = os.path.join(os.getcwd(), "tests", "data", "test.env")
     env_variables_mapping = load.load_dot_env_file(dot_env_path)
     self.assertIn("PROJECT_KEY", env_variables_mapping)
     self.assertEqual(env_variables_mapping["UserName"], "test")
     self.assertEqual(env_variables_mapping["content_type"],
                      "application/json; charset=UTF-8")
Exemplo n.º 3
0
 def test_load_env_path_not_exist(self):
     dot_env_path = os.path.join(
         os.getcwd(),
         "tests",
         "data",
     )
     env_variables_mapping = load.load_dot_env_file(dot_env_path)
     self.assertEqual(env_variables_mapping, {})
Exemplo n.º 4
0
def load_project_data(test_path, dot_env_path=None):
    """ load api, testcases, .env, debugtalk.py functions.
        api/testcases folder is relative to project_working_directory

    Args:
        test_path (str): test file/folder path, locate pwd from this path.
        dot_env_path (str): specified .env file path

    Returns:
        dict: project loaded api/testcases definitions,
            environments and debugtalk.py functions.

    """
    debugtalk_path, project_working_directory = init_project_working_directory(
        test_path)

    project_mapping = {}

    # load .env file
    # NOTICE:
    # environment variable maybe loaded in debugtalk.py
    # thus .env file should be loaded before loading debugtalk.py
    dot_env_path = dot_env_path or os.path.join(project_working_directory,
                                                ".env")
    project_mapping["env"] = load_dot_env_file(dot_env_path)

    if debugtalk_path:
        # load debugtalk.py functions
        debugtalk_functions = load_debugtalk_functions()
    else:
        debugtalk_functions = {}

    # locate PWD and load debugtalk.py functions

    project_mapping["PWD"] = project_working_directory
    functions.PWD = project_working_directory  # TODO: remove
    project_mapping["functions"] = debugtalk_functions
    project_mapping["test_path"] = test_path

    # load api
    tests_def_mapping["api"] = load_api_folder(
        os.path.join(project_working_directory, "api"))

    return project_mapping
Exemplo n.º 5
0
 def test_load_dot_env_file(self):
     dot_env_path = os.path.join(os.getcwd(), "tests", ".env")
     env_variables_mapping = load.load_dot_env_file(dot_env_path)
     self.assertIn("PROJECT_KEY", env_variables_mapping)
     self.assertEqual(env_variables_mapping["UserName"], "debugtalk")