def test_update_when_repo_modified_on_mutable(self, mock_get_repo_file_classes): self._inject_mock_invalid_consumer() modified_repo = Repo('x', [('gpgcheck', 'unoriginal'), ('gpgkey', 'some_key')]) server_repo = Repo('x', [('gpgcheck', 'original')]) mock_file = MagicMock() mock_file.CONTENT_TYPES = [None] mock_file.fix_content = lambda x: x mock_file.section.side_effect = [modified_repo, server_repo] mock_class = MagicMock(return_value=mock_file) mock_get_repo_file_classes.return_value = [(mock_class, mock_class)] 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'])
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()))
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'])
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_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()))
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.assertEqual('original', old_repo['gpgcheck']) update_action.update_repo(old_repo, new_repo) self.assertEqual('blah', old_repo['gpgcheck']) self.assertEqual('some_key', old_repo['gpgkey'])
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.assertEqual('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.assertEqual('original', old_repo['gpgcheck']) self.assertEqual('some_key', old_repo['gpgkey'])
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.assertEqual('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.assertEqual('hand_edit', old_repo['gpgcheck']) self.assertEqual('some_key', old_repo['gpgkey'])
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.assertEqual('someval', old_repo['somekey'])
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)
def get_all_content(self, baseurl, ca_cert): matching_content = self.matching_content() content_list = [] # avoid checking for release/etc if there is no matching_content if not matching_content: return content_list # wait until we know we have content before fetching # release. We could make YumReleaseverSource understand # cache_only as well. release_source = YumReleaseverSource() for content in matching_content: repo = Repo.from_ent_cert_content(content, baseurl, ca_cert, release_source) # overrides are yum repo only at the moment, but # content sources will likely need to learn how to # apply overrides as well, perhaps generically if self.override_supported and self.apply_overrides: repo = self._set_override_info(repo) content_list.append(repo) return content_list
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'])
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'])
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_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'])
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.assertEqual('original', r['gpgcheck']) update_action._set_override_info(r) self.assertEqual('blah', r['gpgcheck']) self.assertEqual('some_key', r['gpgkey'])
def stub_content(): return [Repo('x', [('gpgcheck', 'new'), ('gpgkey', 'new_key'), ('name', 'test')])]
def test_valid_unicode_just_ascii_label_for_id(self): repo_id = u'valid-label' repo = Repo(repo_id) self.assertEqual(repo_id, repo.id)
def test_invalid_unicode_label_for_id(self): repo_id = u'valid-不明-label' repo = Repo(repo_id) expected = 'valid----label' self.assertEqual(expected, repo.id)
def test_invalid_label_with_spaces(self): repo_id = 'label with spaces' repo = Repo(repo_id) self.assertEqual('label-with-spaces', repo.id)
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])
def test_empty_strings_not_set_in_file(self): r = Repo('testrepo', (('proxy', ""),)) r['proxy'] = "" self.assertFalse(("proxy", "") in list(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_https(self): repo = Repo('testrepo') r = Repo._set_proxy_info(repo) self.assertEqual(r['proxy'], "https://fake.server.com:3129")
def test_extra_chars_in_scheme(self): repo = Repo('testrepo') r = Repo._set_proxy_info(repo) self.assertEqual(r['proxy'], "https://fake.server.com:3129")
def test_valid_label_for_id(self): repo_id = 'valid-label' repo = Repo(repo_id) self.assertEqual(repo_id, repo.id)
def stub_content(): return [Repo('x', [('gpgcheck', 'original'), ('gpgkey', 'some_key')])]