def test_update_when_repo_modified_on_mutable(self, mock_file):
        self._inject_mock_invalid_consumer()
        mock_file = mock_file.return_value
        modified_repo = Repo('x', [('gpgcheck', 'unoriginal'),
                                   ('gpgkey', 'some_key')])
        server_repo = Repo('x', [('gpgcheck', 'original')])
        mock_file.section = MagicMock(side_effect=[modified_repo, server_repo])

        def stub_content():
            return [
                Repo('x', [('gpgcheck', 'new'), ('gpgkey', 'new_key'),
                           ('name', 'test')])
            ]

        update_action = RepoUpdateActionCommand()
        update_action.get_unique_content = stub_content
        current = update_action.perform()
        # confirming that the assessed value does not change when repo file
        # is different from the server value file.
        self.assertEqual('unoriginal', current.repo_updates[0]['gpgcheck'])

        # this is the ending server value file
        written_repo = mock_file.update.call_args[0][0]
        self.assertEqual('new', written_repo['gpgcheck'])
        self.assertEqual(None, written_repo['gpgkey'])
Example #2
0
    def test_set_repo_status_enable_all_disable_all(self, mock_repolib):
        repolib_instance = mock_repolib.return_value
        self._inject_mock_valid_consumer('fake_id')

        repos = [Repo('zoo'), Repo('zebra'), Repo('zip')]
        items = [('1', '*'), ('0', '*')]
        self.cc.use_overrides = True
        self.cc._set_repo_status(repos, repolib_instance, items)

        expected_overrides = [{
            'contentLabel': 'zebra',
            'name': 'enabled',
            'value': '0'
        }, {
            'contentLabel': 'zoo',
            'name': 'enabled',
            'value': '0'
        }, {
            'contentLabel': 'zip',
            'name': 'enabled',
            'value': '0'
        }]
        match_dict_list = Matcher(self.assert_items_equals, expected_overrides)
        self.cc.cp.setContentOverrides.assert_called_once_with(
            'fake_id', match_dict_list)
        repolib_instance.update.assert_called()
Example #3
0
 def test_set_immutable_property_now_empty(self):
     self._inject_mock_invalid_consumer()
     update_action = RepoUpdateActionCommand()
     existing_repo = Repo('testrepo')
     existing_repo['proxy_username'] = "******"
     incoming_repo = {}
     update_action.update_repo(existing_repo, incoming_repo)
     self.assertFalse("proxy_username" in existing_repo.keys())
 def test_set_immutable_property_now_empty(self):
     self._inject_mock_invalid_consumer()
     update_action = RepoUpdateActionCommand()
     existing_repo = Repo('testrepo')
     existing_repo['proxy_username'] = "******"
     incoming_repo = {}
     update_action.update_repo(existing_repo, incoming_repo)
     self.assertFalse("proxy_username" in list(existing_repo.keys()))
Example #5
0
 def test_set_immutable_property_now_not_in_cert(self):
     existing_repo = Repo('testrepo')
     existing_repo['proxy_username'] = "******"
     incoming_repo = {}
     existing_repo.update(incoming_repo)
     # Immutable properties should be always be added/updated,
     # and removed if undefined in the new repo definition.
     self.assertFalse("proxy_username" in existing_repo.keys())
Example #6
0
 def test_set_mutable_property_now_empty_value(self):
     existing_repo = Repo('testrepo')
     existing_repo['metadata_expire'] = "blah"
     incoming_repo = {'metadata_expire': ''}
     existing_repo.update(incoming_repo)
     # re comments in repolib
     # Mutable properties should be added if not currently defined,
     # otherwise left alone.
     self.assertTrue("metadata_expire" in existing_repo.keys())
Example #7
0
 def test_set_immutable_property_now_not_in_cert(self):
     self._inject_mock_invalid_consumer()
     update_action = RepoUpdateActionCommand()
     existing_repo = Repo('testrepo')
     existing_repo['proxy_username'] = "******"
     incoming_repo = {}
     update_action.update_repo(existing_repo, incoming_repo)
     # Immutable properties should be always be added/updated,
     # and removed if undefined in the new repo definition.
     self.assertFalse("proxy_username" in existing_repo.keys())
 def test_set_immutable_property_now_not_in_cert(self):
     self._inject_mock_invalid_consumer()
     update_action = RepoUpdateActionCommand()
     existing_repo = Repo('testrepo')
     existing_repo['proxy_username'] = "******"
     incoming_repo = {}
     update_action.update_repo(existing_repo, incoming_repo)
     # Immutable properties should be always be added/updated,
     # and removed if undefined in the new repo definition.
     self.assertFalse("proxy_username" in list(existing_repo.keys()))
 def test_mutable_property_is_server(self):
     update_action = RepoUpdateActionCommand()
     self._inject_mock_invalid_consumer()
     existing_repo = Repo('testrepo')
     server_val_repo = Repo('servertestrepo')
     existing_repo['metadata_expire'] = 1000
     server_val_repo['metadata_expire'] = 1000
     incoming_repo = {'metadata_expire': 2000}
     update_action.update_repo(existing_repo, incoming_repo, server_val_repo)
     self.assertEqual(2000, existing_repo['metadata_expire'])
Example #10
0
 def test_set_mutable_property_now_not_in_cert(self):
     self._inject_mock_invalid_consumer()
     update_action = RepoUpdateActionCommand()
     existing_repo = Repo('testrepo')
     existing_repo['metadata_expire'] = "blah"
     incoming_repo = {}
     update_action.update_repo(existing_repo, incoming_repo)
     # re comments in repolib
     # Mutable properties should be added if not currently defined,
     # otherwise left alone.
     self.assertTrue("metadata_expire" in existing_repo.keys())
 def test_set_mutable_property_now_not_in_cert(self):
     self._inject_mock_invalid_consumer()
     update_action = RepoUpdateActionCommand()
     existing_repo = Repo('testrepo')
     existing_repo['metadata_expire'] = "blah"
     incoming_repo = {}
     update_action.update_repo(existing_repo, incoming_repo)
     # re comments in repolib
     # Mutable properties should be added if not currently defined,
     # otherwise left alone.
     self.assertTrue("metadata_expire" in list(existing_repo.keys()))
Example #12
0
 def test_overrides_trump_existing(self):
     update_action = RepoUpdateActionCommand()
     update_action.overrides = {'x': {'gpgcheck': 'blah'}}
     values = [('gpgcheck', 'original'), ('gpgkey', 'some_key')]
     old_repo = Repo('x', values)
     new_repo = Repo(old_repo.id, values)
     update_action._set_override_info(new_repo)
     self.assertEquals('original', old_repo['gpgcheck'])
     update_action.update_repo(old_repo, new_repo)
     self.assertEquals('blah', old_repo['gpgcheck'])
     self.assertEquals('some_key', old_repo['gpgkey'])
    def test_list_with_enabled_and_disabled(self, mock_invoker):
        self.cc.main(["--list", "--list-disabled", "--list-disabled"])
        self.cc._validate_options()

        repos = [Repo("x", [("enabled", "1")]), Repo("y", [("enabled", "0")]), Repo("z", [("enabled", "0")])]
        mock_invoker.return_value.get_repos.return_value = repos

        with Capture() as cap:
            self.cc._do_command()

        result = self.check_output_for_repos(cap.out, repos)
        self.assertEqual((True, True, True), result)
Example #14
0
 def test_overrides_removed_and_edited(self):
     update_action = RepoUpdateActionCommand()
     update_action.written_overrides.overrides = {'x': {'gpgcheck': 'override_value'}}
     update_action.overrides = {}
     old_repo = Repo('x', [('gpgcheck', 'hand_edit'), ('gpgkey', 'some_key')])
     new_repo = Repo(old_repo.id, [('gpgcheck', 'original'), ('gpgkey', 'some_key')])
     update_action._set_override_info(new_repo)
     # The value from the current repo file (with the old hand edit) should exist pre-update
     self.assertEquals('hand_edit', old_repo['gpgcheck'])
     update_action.update_repo(old_repo, new_repo)
     # Because the current value doesn't match the override, we don't modify it
     self.assertEquals('hand_edit', old_repo['gpgcheck'])
     self.assertEquals('some_key', old_repo['gpgkey'])
Example #15
0
 def test_non_default_overrides_added_to_existing(self):
     '''
     Test that overrides for values that aren't found in Repo.PROPERTIES are written
     to existing repos
     '''
     update_action = RepoUpdateActionCommand()
     update_action.written_overrides.overrides = {}
     update_action.overrides = {'x': {'somekey': 'someval'}}
     old_repo = Repo('x', [])
     new_repo = Repo(old_repo.id, [])
     update_action._set_override_info(new_repo)
     update_action.update_repo(old_repo, new_repo)
     self.assertEquals('someval', old_repo['somekey'])
Example #16
0
 def test_non_default_override_removed_deleted(self):
     '''
     Test that overrides for values that aren't found in Repo.PROPERTIES are
     removed from redhat.repo once the override is removed
     '''
     update_action = RepoUpdateActionCommand()
     update_action.written_overrides.overrides = {'x': {'somekey': 'someval'}}
     update_action.overrides = {}
     old_repo = Repo('x', [('somekey', 'someval')])
     new_repo = Repo(old_repo.id, [])
     update_action._set_override_info(new_repo)
     update_action.update_repo(old_repo, new_repo)
     self.assertFalse('somekey' in old_repo)
Example #17
0
 def test_overrides_removed_revert_to_default(self):
     update_action = RepoUpdateActionCommand()
     update_action.written_overrides.overrides = {'x': {'gpgcheck': 'blah'}}
     update_action.overrides = {}
     old_repo = Repo('x', [('gpgcheck', 'blah'), ('gpgkey', 'some_key')])
     new_repo = Repo(old_repo.id, [('gpgcheck', 'original'), ('gpgkey', 'some_key')])
     update_action._set_override_info(new_repo)
     # The value from the current repo file (with the old override) should exist pre-update
     self.assertEquals('blah', old_repo['gpgcheck'])
     update_action.update_repo(old_repo, new_repo)
     # Because the override has been removed, the value is reset to the default
     self.assertEquals('original', old_repo['gpgcheck'])
     self.assertEquals('some_key', old_repo['gpgkey'])
Example #18
0
    def test_enable_repo_wildcard(self):
        repo_settings = {
            "enabled": "0",
        }

        self.invoker.return_value.get_repos.return_value = [
            Repo("hello", list(repo_settings.copy().items())),
            Repo("helium", list(repo_settings.copy().items())),
        ]
        self.repo_file.items.return_value = list(repo_settings.copy().items())

        result = api.enable_yum_repositories("he*")
        self.repo_file.return_value.write.assert_called_with()
        self.assertEqual(2, result)
    def test_set_repo_status_with_wildcards(self, mock_repolib):
        repolib_instance = mock_repolib.return_value
        self._inject_mock_valid_consumer('fake_id')

        repos = [Repo('zoo'), Repo('zebra'), Repo('zip')]
        items = [('0', 'z*')]
        self.cc.use_overrides = True
        self.cc._set_repo_status(repos, repolib_instance, items)

        expected_overrides = [{'contentLabel': i.id, 'name': 'enabled', 'value': '0'} for i in repos]
        metadata_overrides = [{'contentLabel': i.id, 'name': 'enabled_metadata', 'value': '0'} for i in repos]
        expected_overrides.extend(metadata_overrides)
        match_dict_list = Matcher(self.assert_items_equals, expected_overrides)
        self.cc.cp.setContentOverrides.assert_called_once_with('fake_id', match_dict_list)
        self.assertTrue(repolib_instance.update.called)
Example #20
0
    def test_enable_repo_wildcard(self):
        repo_settings = {
            'enabled': '0',
        }

        self.invoker.get_repos.return_value = [
            Repo('hello', repo_settings.copy().items()),
            Repo('helium', repo_settings.copy().items()),
        ]
        self.repo_file.items.return_value = repo_settings.copy().items()

        result = api.enable_yum_repositories('he*')

        self.assertTrue(call.write() in self.repo_file.mock_calls)
        self.assertEquals(2, result)
Example #21
0
    def test_update_overrides_cache(self, mock_set, mock_supports):
        mock_supports.return_value = True

        repo_settings = {
            'enabled': '0',
        }
        self.invoker.get_repos.return_value = [
            Repo('hello', repo_settings.items()),
        ]
        self.repo_file.items.return_value = repo_settings.items()

        @api.request_injection
        def munge_injection():
            self._inject_mock_valid_consumer("123")
            return api.enable_yum_repositories('hello')

        result = munge_injection()

        expected_overrides = [{
            'contentLabel': 'hello',
            'name': 'enabled',
            'value': '1',
        }]
        self.assertTrue(call("123", expected_overrides) in mock_set.mock_calls)
        self.assertTrue(call.update() in self.invoker.mock_calls)
        self.assertEquals(1, result)
Example #22
0
 def test_unset_immutable_property(self):
     self._inject_mock_invalid_consumer()
     update_action = RepoUpdateActionCommand()
     existing_repo = Repo('testrepo')
     incoming_repo = {'name': "woof"}
     update_action.update_repo(existing_repo, incoming_repo)
     self.assertEqual("woof", existing_repo['name'])
Example #23
0
 def test_unset_mutable_property(self):
     self._inject_mock_invalid_consumer()
     update_action = RepoUpdateActionCommand()
     existing_repo = Repo('testrepo')
     incoming_repo = {'metadata_expire': 2000}
     update_action.update_repo(existing_repo, incoming_repo)
     self.assertEqual(2000, existing_repo['metadata_expire'])
Example #24
0
    def test_update_overrides_cache(self):
        with patch("rhsm.connection.UEPConnection") as mock_uep:
            self.stub_cp_provider.consumer_auth_cp = mock_uep
            mock_uep.supports_resource = Mock(return_value=True)
            mock_uep.setContentOverrides = Mock()

            repo_settings = {
                "enabled": "0",
            }
            self.invoker.return_value.get_repos.return_value = [
                Repo("hello", list(repo_settings.items())),
            ]
            self.repo_file.items.return_value = list(repo_settings.items())

            self._inject_mock_valid_consumer("123")

            # The API methods try to bootstrap injection themselves so we want
            # to avoid that here.
            with patch("subscription_manager.api.injected") as injected:
                injected.return_value = True

                result = api.enable_yum_repositories("hello")

                expected_overrides = [{
                    "contentLabel": "hello",
                    "name": "enabled",
                    "value": "1",
                }]
                self.assertTrue(
                    call("123", expected_overrides) in
                    mock_uep.setContentOverrides.mock_calls)

                self.invoker.return_value.update.assert_called_with()
                self.assertEqual(1, result)
Example #25
0
 def test_overrides_trump_ent_cert(self):
     update_action = RepoUpdateActionCommand()
     update_action.overrides = {'x': {'gpgcheck': 'blah'}}
     r = Repo('x', [('gpgcheck', 'original'), ('gpgkey', 'some_key')])
     self.assertEquals('original', r['gpgcheck'])
     update_action._set_override_info(r)
     self.assertEquals('blah', r['gpgcheck'])
     self.assertEquals('some_key', r['gpgkey'])
Example #26
0
 def test_gpgcheck_is_mutable(self):
     update_action = RepoUpdateActionCommand()
     self._inject_mock_invalid_consumer()
     existing_repo = Repo('testrepo')
     existing_repo['gpgcheck'] = "0"
     incoming_repo = {'gpgcheck': "1"}
     update_action.update_repo(existing_repo, incoming_repo)
     self.assertEqual("0", existing_repo['gpgcheck'])
Example #27
0
 def test_mutable_property_in_repo_but_not_in_cert(self):
     self._inject_mock_invalid_consumer()
     update_action = RepoUpdateActionCommand()
     existing_repo = Repo('testrepo')
     existing_repo['metadata_expire'] = 1000
     incoming_repo = {}
     update_action.update_repo(existing_repo, incoming_repo)
     self.assertEqual(1000, existing_repo['metadata_expire'])
    def test_repo_update_forbidden_when_registered(self):
        existing_repo = Repo('testrepo')
        existing_repo['proxy_username'] = "******"
        incoming_repo = {'proxy_username': '******'}

        update_action = RepoUpdateActionCommand()
        update_action.override_supported = True
        self.assertRaises(UnsupportedOperationException,
                          update_action.update_repo, existing_repo,
                          incoming_repo)
    def test_set_repo_status_when_disconnected(self, mock_repofile):
        self._inject_mock_invalid_consumer()
        mock_repofile_inst = mock_repofile.return_value

        enabled = list({'enabled': '1'}.items())
        disabled = list({'enabled': '0'}.items())

        zoo = Repo('zoo', enabled)
        zebra = Repo('zebra', disabled)
        zippy = Repo('zippy', enabled)
        zero = Repo('zero', disabled)
        repos = [zoo, zebra, zippy, zero]
        items = [('0', 'z*')]

        self.cc._set_repo_status(repos, None, items)
        calls = [call(r) for r in repos if r['enabled'] == 1]
        mock_repofile_inst.update.assert_has_calls(calls)
        for r in repos:
            self.assertEqual('0', r['enabled'])
        mock_repofile_inst.write.assert_called_once_with()
Example #30
0
    def test_does_not_enable_nonmatching_repos(self):
        repo_settings = {
            'enabled': '0',
        }
        self.invoker.get_repos.return_value = [
            Repo('x', repo_settings.items()),
        ]
        self.repo_file.items.return_value = repo_settings.items()
        result = api.enable_yum_repositories('hello')

        self.assertFalse(call.write() in self.repo_file.mock_calls)
        self.assertEquals(0, result)
Example #31
0
    def test_disable_repo(self):
        repo_settings = {
            'enabled': '1',
        }
        self.invoker.get_repos.return_value = [
            Repo('hello', repo_settings.items()),
        ]
        self.repo_file.items.return_value = repo_settings.items()
        result = api.disable_yum_repositories('hello')

        self.assertTrue(call.write() in self.repo_file.mock_calls)
        self.assertEquals(1, result)
Example #32
0
    def test_does_not_enable_nonmatching_repos(self):
        repo_settings = {
            "enabled": "0",
        }
        self.invoker.return_value.get_repos.return_value = [
            Repo("x", list(repo_settings.items())),
        ]
        self.repo_file.items.return_value = list(repo_settings.items())
        result = api.enable_yum_repositories("hello")

        self.assertEqual(0, len(self.repo_file.return_value.write.mock_calls))
        self.assertEqual(0, result)
Example #33
0
    def test_disable_repo(self):
        repo_settings = {
            "enabled": "1",
        }
        self.invoker.return_value.get_repos.return_value = [
            Repo("hello", list(repo_settings.items())),
        ]
        self.repo_file.items.return_value = list(repo_settings.items())
        result = api.disable_yum_repositories("hello")

        self.repo_file.return_value.write.assert_called_with()
        self.assertEqual(1, result)
Example #34
0
 def test_set_immutable_property_now_empty(self):
     existing_repo = Repo('testrepo')
     existing_repo['proxy_username'] = "******"
     incoming_repo = {}
     existing_repo.update(incoming_repo)
     self.assertFalse("proxy_username" in existing_repo.keys())
Example #35
0
 def test_unset_immutable_property(self):
     existing_repo = Repo('testrepo')
     incoming_repo = {'name': "woof"}
     existing_repo.update(incoming_repo)
     self.assertEqual("woof", existing_repo['name'])
Example #36
0
 def test_gpgcheck_is_mutable(self):
     existing_repo = Repo('testrepo')
     existing_repo['gpgcheck'] = "0"
     incoming_repo = {'gpgcheck': "1"}
     existing_repo.update(incoming_repo)
     self.assertEqual("0", existing_repo['gpgcheck'])
 def test_empty_strings_not_set_in_file(self):
     r = Repo("testrepo", (("proxy", ""),))
     r["proxy"] = ""
     self.assertFalse(("proxy", "") in r.items())
 def test_unknown_property_is_preserved(self):
     existing_repo = Repo('testrepo')
     existing_repo['fake_prop'] = 'fake'
     self.assertTrue(('fake_prop', 'fake') in list(existing_repo.items()))
 def test_empty_strings_not_set_in_file(self):
     r = Repo('testrepo', (('proxy', ""),))
     r['proxy'] = ""
     self.assertFalse(("proxy", "") in list(r.items()))
 def test_existing_order_is_preserved(self):
     config = (('key 1', 'value 1'), ('key b', 'value b'), ('key 3', 'value 3'))
     repo = Repo('testrepo', config)
     self.assertEqual(config, tuple(repo.items())[:3])
Example #41
0
 def test_unset_mutable_property(self):
     existing_repo = Repo('testrepo')
     incoming_repo = {'metadata_expire': 2000}
     existing_repo.update(incoming_repo)
     self.assertEqual(2000, existing_repo['metadata_expire'])
 def test_unknown_property_is_preserved(self):
     existing_repo = Repo("testrepo")
     existing_repo["fake_prop"] = "fake"
     self.assertTrue(("fake_prop", "fake") in existing_repo.items())
 def test_existing_order_is_preserved(self):
     config = (("key 1", "value 1"), ("key b", "value b"), ("key 3", "value 3"))
     repo = Repo("testrepo", config)
     self.assertEquals(config, repo.items()[:3])
Example #44
0
 def test_mutable_property_in_repo_but_not_in_cert(self):
     existing_repo = Repo('testrepo')
     existing_repo['metadata_expire'] = 1000
     incoming_repo = {}
     existing_repo.update(incoming_repo)
     self.assertEqual(1000, existing_repo['metadata_expire'])