Beispiel #1
0
def _test_schema(schema, response):
    start_t = time()

    if isinstance(schema, type):
        assert isinstance(response, schema)
    else:
        assert isinstance(response, type(schema))

    if response and isinstance(response, list):
        schema = schema[0]  # schema describe only one element
        for element in response:
            assert isinstance(element, type(schema))
            for key, value in element.items():
                try:
                    assert isinstance(value, schema[key])
                except AssertionError as err:
                    logging.debug("param::%s", key)
                    raise err
            # check missing keys (difference between schema and response)
            if element.keys() != schema.keys():
                if len(element.keys()) > len(schema.keys()):
                    missed_keys = set(element.keys()) - set(schema.keys())
                else:
                    missed_keys = set(schema.keys()) - set(element.keys())
                logging.warning("missed keys::%s", missed_keys)
    elif response and isinstance(response, dict):
        for key, value in response.items():
            _test_schema(schema[key], value)

    logging.info("Test run takes: %s seconds", time() - start_t)
def use_mock_loader() -> Generator:
    original_loader = ENV.loader
    logging.debug("Change original loader to mock")
    ENV.loader = FileSystemLoader(MOCK_DIR, encoding="utf-8")
    yield
    logging.debug("Rollback to original loader")
    ENV.loader = original_loader
 def create_file(path: str) -> bool:
     logging.debug("Create file: %s", path)
     with open(path, 'wb') as fout:
         pass
     return os.path.exists(path)
 def make_params(self, filetype: str) -> dict:
     params = {'project_name': "test-proj"}
     params.update(self.config[filetype])
     logging.debug("Make params: %s", params)
     return params
 def _check_rendered(render_res: str, params: dict) -> NoReturn:
     assert render_res and isinstance(render_res, str)
     for val in params.values():
         if not isinstance(val, (dict, list)):
             logging.debug("Check rendered value: %s", val)
             assert val in render_res