def test_migrated(self, _repos_keys_migrate_drop): _repos_keys_migrate_drop.side_effect = [ ( { ( "repo-1", ( ("humanname", "repo name 1"), ("priority", 0), ("refresh", True), ), ), }, { ( "repo-2", ( ("humanname", "repo name 2"), ("priority", 0), ("refresh", True), ), ), }, {("key1", (("key", "key1"),))}, {("key2", (("key", "key2"),))}, ), (set(), set(), set(), set()), ] grains = {"os_family": "Suse"} opts = {"test": False} salt_mock = { "pkg.mod_repo": MagicMock(), "pkg.del_repo": MagicMock(), "lowpkg.import_gpg_key": MagicMock(), "lowpkg.remove_gpg_key": MagicMock(), } with patch.dict(pkgrepo.__grains__, grains), patch.dict( pkgrepo.__opts__, opts ), patch.dict(pkgrepo.__salt__, salt_mock): self.assertEqual( pkgrepo.migrated("/mnt", True, True), { "name": "/mnt", "result": True, "changes": { "repos migrated": ["repo-1"], "repos dropped": ["repo-2"], "keys migrated": ["key1"], "keys dropped": ["key2"], }, "comment": "Repositories synchronized", }, ) salt_mock["pkg.mod_repo"].assert_called_with( "repo-1", humanname="repo name 1", priority=0, refresh=True, root="/mnt" ) salt_mock["pkg.del_repo"].assert_called_with("repo-2", root="/mnt") salt_mock["lowpkg.import_gpg_key"].assert_called_with("key1", root="/mnt") salt_mock["lowpkg.remove_gpg_key"].assert_called_with("key2", root="/mnt")
def test_migrated_missing_keys_api(self): grains = {"os_family": "Suse"} with patch.dict(pkgrepo.__grains__, grains): self.assertEqual( pkgrepo.migrated("/mnt"), { "name": "/mnt", "result": False, "changes": {}, "comment": "Keys cannot be migrated for this platform", }, )
def test_migrated_non_supported_platform(self): grains = {"os_family": "Debian"} with patch.dict(pkgrepo.__grains__, grains): self.assertEqual( pkgrepo.migrated("/mnt"), { "name": "/mnt", "result": False, "changes": {}, "comment": "Migration not supported for this platform", }, )
def test_migrated_wrong_method(self): grains = {"os_family": "Suse"} salt_mock = { "lowpkg.import_gpg_key": True, } with patch.dict(pkgrepo.__grains__, grains), patch.dict( pkgrepo.__salt__, salt_mock ): self.assertEqual( pkgrepo.migrated("/mnt", method="magic"), { "name": "/mnt", "result": False, "changes": {}, "comment": "Migration method not supported", }, )
def test_migrated_empty(self, _repos_keys_migrate_drop): _repos_keys_migrate_drop.return_value = (set(), set(), set(), set()) grains = {"os_family": "Suse"} salt_mock = { "lowpkg.import_gpg_key": True, } with patch.dict(pkgrepo.__grains__, grains), patch.dict( pkgrepo.__salt__, salt_mock ): self.assertEqual( pkgrepo.migrated("/mnt"), { "name": "/mnt", "result": True, "changes": {}, "comment": "Repositories are already migrated", }, )
def test_migrated_test(self, _repos_keys_migrate_drop): _repos_keys_migrate_drop.return_value = ( { ( "repo-1", (("humanname", "repo name 1"), ("priority", 0), ("refresh", True)), ), }, { ( "repo-2", (("humanname", "repo name 2"), ("priority", 0), ("refresh", True)), ), }, {("key1", (("key", "key1"),))}, {("key2", (("key", "key2"),))}, ) grains = {"os_family": "Suse"} opts = {"test": True} salt_mock = { "lowpkg.import_gpg_key": True, } with patch.dict(pkgrepo.__grains__, grains), patch.dict( pkgrepo.__opts__, opts ), patch.dict(pkgrepo.__salt__, salt_mock): self.assertEqual( pkgrepo.migrated("/mnt", True, True), { "name": "/mnt", "result": None, "changes": { "repos to migrate": ["repo-1"], "repos to drop": ["repo-2"], "keys to migrate": ["key1"], "keys to drop": ["key2"], }, "comment": "There are keys or repositories to migrate or drop", }, )