Пример #1
0
class TestPackagesAPI():
    """ Set of tests for the packages API. """
    db_handle = None
    packages_api = None

    def setup_class(self):
        """ Setup the database and connection to it. """
        self.db_handle = DummyDatabase()
        self.packages_api = PackagesAPI(dsn=self.db_handle.database.dsn())

    def test_empty_package_list(self):
        """ Test with empty package list inside the input JSON. """
        response = self.packages_api.process_list(PKG_EMPTY_JSON)
        assert response == PKG_EMPTY_EXPECTED

    def test_nonexisting_package(self):
        """ Test with non existing package inside the input JSON. """
        response = self.packages_api.process_list(PKG_NON_EXISTING_JSON)
        assert response == PKG_NON_EXISTING_EXPECTED

    def test_nonexisting_packages(self):
        """ Test with non existing packages inside the input JSON. """
        response = self.packages_api.process_list(PKG_NON_EXISTING_JSON2)
        assert response == PKG_NON_EXISTING_EXPECTED2

    def test_correct_pkg_empty(self):
        """ Test with legit input, legit package. """
        response = self.packages_api.process_list(PKG_LEGIT)
        assert response == PKG_LEGIT_EXPECTED
Пример #2
0
class TestPackagesAPI(TestBase):
    """Test dbchange api class."""

    pkg_api = None

    @pytest.fixture(autouse=True)
    def setup_api(self, load_cache):
        """Setup PackageAPI object."""
        self.pkg_api = PackagesAPI(self.cache)

    def test_schema(self):
        """Test pkg api response schema of valid input."""
        response = self.pkg_api.process_list(1, PKG_JSON)
        schemas.pkgs_top_schema.validate(response)
        schemas.pkgs_list_schema.validate(response["package_list"][PKG])

    def test_empty_json(self):
        """Test pkg api with empty json."""
        with pytest.raises(Exception) as context:
            self.pkg_api.process_list(1, PKG_JSON_EMPTY)
        assert "'package_list' is a required property" in str(context)

    def test_empty_pkg_list(self):
        """Test pkg api with empty package_list."""
        response = self.pkg_api.process_list(1, PKG_JSON_EMPTY_LIST)
        assert tools.match(EMPTY_RESPONSE, response) is True

    def test_non_existing_pkg(self):
        """Test pkg api with non existing package."""
        response = self.pkg_api.process_list(1, PKG_JSON_NON_EXIST)
        assert tools.match(NON_EXIST_RESPONSE, response) is True
Пример #3
0
def load_cache_to_apis():
    """Reload cache in APIs."""
    BaseHandler.updates_api = UpdatesAPI(BaseHandler.db_cache)
    BaseHandler.repo_api = RepoAPI(BaseHandler.db_cache)
    BaseHandler.cve_api = CveAPI(BaseHandler.db_cache)
    BaseHandler.errata_api = ErrataAPI(BaseHandler.db_cache)
    BaseHandler.packages_api = PackagesAPI(BaseHandler.db_cache)
    BaseHandler.vulnerabilities_api = VulnerabilitiesAPI(BaseHandler.db_cache, BaseHandler.updates_api)
    BaseHandler.dbchange_api = DBChange(BaseHandler.db_cache)
Пример #4
0
class TestPackagesAPI(TestBase):
    """Test dbchange api class."""

    pkg_api = None

    @pytest.fixture(autouse=True)
    def setup_api(self, load_cache):
        """Setup PackageAPI object."""
        self.pkg_api = PackagesAPI(self.cache)

    def test_schema(self):
        """Test pkg api response schema of valid input."""
        response = self.pkg_api.process_list(1, PKG_JSON)
        schemas.pkgs_top_schema.validate(response)
        schemas.pkgs_list_schema.validate(response["package_list"][PKG])
        assert len(response["package_list"][PKG]["repositories"]
                   ) == 1  # package is expected to be in one repo

    def test_schema_src(self):
        """Test pkg api response schema of valid input."""
        response = self.pkg_api.process_list(1, PKG_SRC_JSON)
        schemas.pkgs_top_schema.validate(response)
        schemas.pkgs_list_schema.validate(response["package_list"][PKG_SRC])
        assert response["package_list"][PKG_SRC]["package_list"] == [PKG]
        assert not response["package_list"][PKG_SRC][
            "repositories"]  # source package is assigned to no repo

    def test_empty_pkg_list(self):
        """Test pkg api with empty package_list."""
        response = self.pkg_api.process_list(1, PKG_JSON_EMPTY_LIST)
        assert tools.match(EMPTY_RESPONSE, response) is True

    def test_non_existing_pkg(self):
        """Test pkg api with non existing package."""
        response = self.pkg_api.process_list(1, PKG_JSON_NON_EXIST)
        assert tools.match(NON_EXIST_RESPONSE, response) is True
Пример #5
0
 def setup_class(self):
     """ Setup the database and connection to it. """
     self.db_handle = DummyDatabase()
     self.packages_api = PackagesAPI(dsn=self.db_handle.database.dsn())
Пример #6
0
 def setup_api(self, load_cache):
     """Setup PackageAPI object."""
     self.pkg_api = PackagesAPI(self.cache)