예제 #1
0
def test_db_tool_data_insert_with_versions(config, caplog):
    caplog.set_level(logging.DEBUG)
    test_db = ToolDatabase(config)
    ver1 = VersionInfo(**FAKE_VERSION_INFO_NO_CHECKER)
    ver2 = VersionInfo(**FAKE_VERSION_INFO_WITH_CHECKER)
    tool_obj = ToolInfo(**FAKE_TOOL_INFO)
    tool_obj.versions.append(ver1)
    tool_obj.versions.append(ver2)
    with test_db.transaction():
        test_db.insert_tool_info(tool_obj)
        n_tools = test_db.get_tools()
        assert len(n_tools) == 1
        assert len(n_tools[0].versions) == 2
        n_versions = n_tools[0].versions
        assert n_versions[0].version == FAKE_VERSION_INFO_NO_CHECKER.get(
            "version")
        assert n_versions[0].version_type == FAKE_VERSION_INFO_NO_CHECKER.get(
            "version_type")
        assert n_versions[0].source == FAKE_VERSION_INFO_NO_CHECKER.get(
            "source")
        assert n_versions[0].tags == FAKE_VERSION_INFO_NO_CHECKER.get("tags")
        # DB insert should not update time - should tell information of origin update time
        assert n_versions[0].updated == FAKE_VERSION_INFO_NO_CHECKER.get(
            "updated")
        assert n_versions[0].raw_size() == FAKE_VERSION_INFO_NO_CHECKER.get(
            "size")
        # Duplicate insert, should be handled gracefully
        test_db.insert_tool_info(tool_obj)
        n_tools = test_db.get_tools()
        # Still two versions
        assert len(n_tools[0].versions) == 2
예제 #2
0
def test_insert_meta_data(caplog, config):
    """Insert metadata of checker"""
    caplog.set_level(logging.DEBUG)
    test_db = ToolDatabase(config)
    ver1 = VersionInfo(**FAKE_VERSION_INFO_NO_CHECKER)
    ver2 = VersionInfo(**FAKE_VERSION_INFO_WITH_CHECKER)
    assert isinstance(ver2.source, UpstreamChecker)

    tool_obj = ToolInfo(**FAKE_TOOL_INFO)
    tool_obj.versions.append(ver1)
    tool_obj.versions.append(ver2)
    with test_db.transaction():
        test_db.insert_tool_info(tool_obj)
        test_db.insert_meta_info(tool_obj.name, tool_obj.location,
                                 FAKE_CHECKER_CONF)
        meta_data = test_db.get_meta_information(
            tool_obj.name, FAKE_CHECKER_CONF.get("provider"))[0]
        assert meta_data.get("uri") == FAKE_CHECKER_CONF.get("uri")
        assert meta_data.get("repository") == FAKE_CHECKER_CONF.get(
            "repository")
        assert meta_data.get("tool") == FAKE_CHECKER_CONF.get("tool")
        assert meta_data.get("provider") == FAKE_CHECKER_CONF.get("provider")
        assert meta_data.get("method") == FAKE_CHECKER_CONF.get("method")
        assert meta_data.get("suite") == FAKE_CHECKER_CONF.get("suite")
        assert meta_data.get("origin") == FAKE_CHECKER_CONF.get("origin")
        assert meta_data.get("docker_origin") == FAKE_CHECKER_CONF.get(
            "docker_origin")
예제 #3
0
def test_db_tool_data_insert(config, caplog):
    caplog.set_level(logging.DEBUG)
    test_db = ToolDatabase(config)
    tool_obj = ToolInfo(**FAKE_TOOL_INFO)
    with test_db.transaction():
        test_db.insert_tool_info(tool_obj)
        # Duplicate insert, should be handled gracefully
        test_db.insert_tool_info(tool_obj)
    # Read data
    with test_db.transaction():
        tools = test_db.get_tools()
    assert len(tools) == 1
    assert tools[0].description == FAKE_TOOL_INFO.get("description")
    assert tools[0].name == FAKE_TOOL_INFO.get("name")
    assert tools[0].updated == FAKE_TOOL_INFO.get("updated")
    assert tools[0].location == FAKE_TOOL_INFO.get("location")
예제 #4
0
 def __init__(self,
              config_path: str = "",
              tools_repo_path: str = "",
              version_var: str = "TOOL_VERSION",
              configuration: Configuration = None):
     self.logger: logging.Logger = logging.getLogger("registry")
     self.registry_name: str = ""
     if not configuration:
         self.config: Configuration = Configuration(config_path,
                                                    tools_repo_path)
     else:
         self.config = configuration
     self.version_var: str = version_var
     self.tool_cache: pathlib.Path = self.config.tool_cache
     self.tool_cache_version: str = self.config.tool_cache_version
     self.tools_repo_path: pathlib.Path = self.config.tools_repo_path
     self.db = ToolDatabase(self.config)
예제 #5
0
def base_db(caplog, config):
    caplog.set_level(logging.DEBUG)
    # Make sample database for other tests
    test_db = ToolDatabase(config)
    ver1 = VersionInfo(**FAKE_VERSION_INFO_NO_CHECKER)
    ver2 = VersionInfo(**FAKE_VERSION_INFO_WITH_CHECKER)
    tool_obj = ToolInfo(**FAKE_TOOL_INFO)
    tool_obj.versions.append(ver1)
    tool_obj.versions.append(ver2)
    with test_db.transaction():
        test_db.insert_tool_info(tool_obj)
        tool_obj2 = ToolInfo(**FAKE_TOOL_INFO2)
        tool_obj2.versions.append(ver1)
        tool_obj2.versions.append(ver2)
        test_db.insert_tool_info(tool_obj2)
    yield test_db
예제 #6
0
def test_insert_tool_list(config, caplog):
    caplog.set_level(logging.DEBUG)
    test_db = ToolDatabase(config)
    tools = [ToolInfo(**FAKE_TOOL_INFO), ToolInfo(**FAKE_TOOL_INFO2)]
    with test_db.transaction():
        test_db.insert_tool_info(tools)
    # Read values
    with test_db.transaction():
        tools_from_db = test_db.get_tools()
    assert len(tools_from_db) == 2
    assert tools[0].description == FAKE_TOOL_INFO.get("description")
    assert tools[0].name == FAKE_TOOL_INFO.get("name")
    assert tools[0].updated == FAKE_TOOL_INFO.get("updated")
    assert tools[0].location == FAKE_TOOL_INFO.get("location")
    assert tools[1].description == FAKE_TOOL_INFO2.get("description")
    assert tools[1].name == FAKE_TOOL_INFO2.get("name")
    assert tools[1].updated == FAKE_TOOL_INFO2.get("updated")
    assert tools[1].location == FAKE_TOOL_INFO2.get("location")
예제 #7
0
def test_db_insert_duplicate_version(caplog, config):
    caplog.set_level(logging.DEBUG)
    test_db = ToolDatabase(config)
    ver1 = VersionInfo(**FAKE_VERSION_INFO_NO_CHECKER)
    ver2 = VersionInfo(**FAKE_VERSION_INFO_NO_CHECKER)
    cp_FAKE_VERSION_INFO_NO_CHECKER = deepcopy(FAKE_VERSION_INFO_NO_CHECKER)
    cp_FAKE_VERSION_INFO_NO_CHECKER["version"] = "1.1"
    ver3 = VersionInfo(**cp_FAKE_VERSION_INFO_NO_CHECKER)
    tool_obj = ToolInfo(**FAKE_TOOL_INFO)
    tool_obj.versions.append(ver1)
    tool_obj.versions.append(ver2)
    tool_obj.versions.append(ver3)
    with test_db.transaction():
        test_db.insert_tool_info(tool_obj)
        tools_db = test_db.get_tools()
        assert len(tools_db[0].versions) == 2
예제 #8
0
def test_configure(config, caplog):
    caplog.set_level(logging.DEBUG)
    test_db = ToolDatabase(config)
    logs = [l.message for l in caplog.records]
    assert "Creating new database file..." in logs
    assert config.tool_db.is_file()