class TestUpdatesAPI(TestBase): """Test updates api class.""" updates_api = None @pytest.fixture(autouse=True) def setup_api(self, load_cache): """Setup UpdatesAPI object.""" self.updates_api = UpdatesAPI(self.cache) def test_process_input_pkg(self): """Test filtering out unknown (or without updates) package names.""" pkgs, update_list = self.updates_api.process_input_packages(UPDATES_JSON) assert pkgs == {'my-pkg-1.1.0-1.el8.i686': {'parsed_nevra': ('my-pkg', '0', '1.1.0', '1.el8', 'i686')}} assert update_list == {'my-pkg-1.1.0-1.el8.i686': {}} def test_process_input_non_exist(self): """Test filtering out unknown non existing package.""" pkgs, update_list = self.updates_api.process_input_packages(UPDATES_JSON_NON_EXIST) assert pkgs == {} assert update_list == {'non-exist': {}} def test_schema_v1(self): """Test schema of updates api v1.""" # NOTE: use copy of dict with json input, because process_list changes this dict updates = self.updates_api.process_list(1, UPDATES_JSON_3_OPT.copy()) assert schemas.updates_top_all_schema.validate(updates) assert schemas.updates_package_schema.validate(updates["update_list"][PKG]) def test_schema_v2(self): """Test schema of updates api v2.""" # NOTE: use copy of dict with json input, because process_list changes this dict updates = self.updates_api.process_list(2, UPDATES_JSON_3_OPT.copy()) assert schemas.updates_top_all_schema.validate(updates) assert schemas.updates_package_schema_v2.validate(updates["update_list"][PKG]) def test_schema_repolist(self): """Test repolist schema of updates api v2.""" # NOTE: use copy of dict with json input, because process_list changes this dict updates = self.updates_api.process_list(2, UPDATES_JSON_REPO.copy()) assert schemas.updates_top_repolist_schema.validate(updates) def test_schema_releasever(self): """Test releasever schema of updates api v2.""" # NOTE: use copy of dict with json input, because process_list changes this dict updates = self.updates_api.process_list(2, UPDATES_JSON_RELEASE.copy()) assert schemas.updates_top_releasever_schema.validate(updates) def test_schema_basearch(self): """Test basearch schema of updates api v2.""" # NOTE: use copy of dict with json input, because process_list changes this dict updates = self.updates_api.process_list(2, UPDATES_JSON_ARCH.copy()) assert schemas.updates_top_basearch_schema.validate(updates) def test_process_list_v1(self): """Test looking for package updates api v1.""" # NOTE: use copy of dict with json input, because process_list changes this dict updates = self.updates_api.process_list(1, UPDATES_JSON_3_OPT.copy()) assert updates == UPDATES_RESPONSE_1 def test_process_list_v2(self): """Test looking for package updates api v2.""" # NOTE: use copy of dict with json input, because process_list changes this dict updates = self.updates_api.process_list(2, UPDATES_JSON_3_OPT.copy()) assert updates == UPDATES_RESPONSE_2 def test_process_list_v3(self): """Test looking for package updates api v3.""" # NOTE: use copy of dict with json input, because process_list changes this dict updates = self.updates_api.process_list(3, UPDATES_JSON_3_OPT.copy()) assert updates == UPDATES_RESPONSE_2 def test_process_list_prefix_v3(self): """Test looking for package updates api v3 with prefixed repo names.""" # NOTE: use copy of dict with json input, because process_list changes this dict updates = self.updates_api.process_list(3, UPDATES_JSON_PREFIX.copy()) assert updates == UPDATES_RESPONSE_2 def test_process_none_arch(self): """Test pkg with arch (none).""" # NOTE: use copy of dict with json input, because process_list changes this dict updates_json_none = UPDATES_JSON_3_OPT.copy() updates_json_none['package_list'] = [PKG, PKG_NONE_ARCH] updates = self.updates_api.process_list(3, updates_json_none) assert len(updates['update_list']) == 2 assert len(updates['update_list'][PKG]['available_updates']) == 1 assert len(updates['update_list'][PKG_NONE_ARCH]['available_updates']) == 0 def test_process_list_v2_unknown(self): """Test looking for unknown EVRA updates, disabled optimistic_updates.""" # NOTE: use copy of dict with json input, because process_list changes this dict updates = self.updates_api.process_list(2, UPDATES_JSON_UNKNOWN.copy()) assert updates == UPDATES_RESPONSE_2_UNKNOWN_NONE def test_optimistic_updates_1(self): """Test looking for unknown EVRA updates (module_stream: 1).""" # NOTE: use copy of dict with json input, because process_list changes this dict updates = self.updates_api.process_list(2, UPDATES_JSON_UNKNOWN_OPT_UPD.copy()) assert updates == UPDATES_RESPONSE_2_UNKNOWN def test_optimistic_updates_2(self): """Test looking for unknown EVRA updates (module_stream: 2).""" # NOTE: use copy of dict with json input, because process_list changes this dict updates = self.updates_api.process_list(2, UPDATES_JSON_UNKNOWN_OPT_UPD_2.copy()) assert updates == UPDATES_RESPONSE_2_UNKNOWN_2 def test_process_empty_pkg_list_v1(self): """Test empty package_list updates api v1.""" # NOTE: use copy of dict with json input, because process_list changes this dict updates = self.updates_api.process_list(1, UPDATES_JSON_EMPTY_LIST.copy()) assert updates == EMPTY_RESPONSE def test_process_empty_pkg_list_v2(self): """Test empty package_list updates api v2.""" # NOTE: use copy of dict with json input, because process_list changes this dict updates = self.updates_api.process_list(2, UPDATES_JSON_EMPTY_LIST.copy()) assert updates == EMPTY_RESPONSE def test_process_non_exist_v1(self): """Test non-existing package updates api v1.""" # NOTE: use copy of dict with json input, because process_list changes this dict updates = self.updates_api.process_list(1, UPDATES_JSON_NON_EXIST.copy()) assert updates == NON_EXIST_RESPONSE def test_process_non_exist_v2(self): """Test non-existing package updates api v2.""" # NOTE: use copy of dict with json input, because process_list changes this dict updates = self.updates_api.process_list(2, UPDATES_JSON_NON_EXIST.copy()) assert updates == NON_EXIST_RESPONSE
class TestModularity(TestBase): """Test /updates modularity""" updates_api = None @staticmethod def gen_pkg_json(nevra, modules=None): """Prepares a request to VMaaS""" retval = {'package_list': [nevra]} if modules is not None: retval['modules_list'] = modules return retval @pytest.fixture(autouse=True) def setup_api(self, load_cache): """Setup UpdatesAPI object.""" self.updates_api = UpdatesAPI(self.cache) @pytest.mark.parametrize('test_data', OLD_OLD, ids=[x[0] for x in OLD_OLD]) def test_old_pkg_old_module(self, test_data): """ Test with my-pkg-1.1.0-1.el8.i686 Test without modularity info provided, should find 3 updates: my-pkg-1.2.0-1.el8.i686 my-pkg-2.0.0-1.el8.i686 my-pkg-2.1.0-1.el8.i686 Test with modularity info provided, should find one update: my-pkg-1.2.0-1.el8.i686 """ pkg = PKG_NEVRAS[0] mode, modules, expected_update_pkgs = test_data # pylint:disable=unused-variable updates = self.updates_api.process_list( 2, self.gen_pkg_json(pkg, modules)) assert updates available_updates = updates['update_list'][pkg]['available_updates'] assert len(available_updates) == len(expected_update_pkgs) assert expected_update_pkgs == { rec['package'] for rec in available_updates } @pytest.mark.parametrize('test_data', NEW_OLD, ids=[x[0] for x in NEW_OLD]) def test_new_pkg_old_module(self, test_data): """Test with my-pkg-1.2.0-1.el8.i686 Test without modularity info enabled, should find two updates my-pkg-2.0.0-1.el8.i686 my-pkg-2.1.0-1.el8.i686 With correct modularity stream enabled there should be no upates Test with incorrect modularity information, should find two (incorrect) update: my-pkg-2.0.0-1.el8.i686 my-pkg-2.1.0-1.el8.i686 DNF on the client should never let this happen """ pkg = PKG_NEVRAS[1] mode, modules, expected_update_pkgs = test_data # pylint:disable=unused-variable updates = self.updates_api.process_list( 2, self.gen_pkg_json(pkg, modules)) assert updates available_updates = updates['update_list'][pkg]['available_updates'] if mode == 'correct_stream_enabled': # with correct stream enabled there should be no updates assert not available_updates return assert len(available_updates) == len(expected_update_pkgs) assert expected_update_pkgs == { rec['package'] for rec in available_updates } @pytest.mark.parametrize('test_data', NEW_MODULE, ids=[x[0] for x in NEW_MODULE]) def test_old_pkg_new_module(self, test_data): """ Test with my-pkg-2.0.0-1.el8.i686 Both tests with, or without modularity should find one update my-pkg-2.1.0-1.el8.i686 """ pkg = PKG_NEVRAS[2] mode, modules, expected_update_pkgs = test_data # pylint:disable=unused-variable updates = self.updates_api.process_list( 2, self.gen_pkg_json(pkg, modules)) assert updates available_updates = updates['update_list'][pkg]['available_updates'] assert len(available_updates) == len(expected_update_pkgs) assert expected_update_pkgs == { rec['package'] for rec in available_updates } @pytest.mark.parametrize('test_data', NEW_MODULE, ids=[x[0] for x in NEW_MODULE]) def test_new_pkg_new_module(self, test_data): """ Test with my-pkg-2.1.0-1.el8.i686 which is the latest package and has no updates There should be zero updates with or without modularity """ pkg = PKG_NEVRAS[3] mode, modules, expected_update_pkgs = test_data # pylint:disable=unused-variable updates = self.updates_api.process_list( 2, self.gen_pkg_json(pkg, modules)) assert updates assert not updates['update_list'][pkg]['available_updates'] @pytest.mark.parametrize('test_data', NO_MODULES, ids=[x[0] for x in NO_MODULES]) def test_no_enabled_modules(self, test_data): """ Tests with modularity functionaility enabled witout needed module (my-pkg 1) enabled Scenarios: no modules enabled at all, only rhn-tools module enabled, module not present in the database enabled All of these should result in no updates found """ pkg = PKG_NEVRAS[0] mode, modules = test_data # pylint:disable=unused-variable updates = self.updates_api.process_list( 2, self.gen_pkg_json(pkg, modules)) assert updates assert not updates['update_list'][pkg]['available_updates']