コード例 #1
0
    def test_show_dialog_with_overrides(self):
        repo = self._create_repo("my_repo", [('enabled', '0')])
        self.repo_lib.get_repos.return_value = [repo]
        self.overrides_mock.get_overrides.return_value = [
            Override('my_repo', 'enabled', '1'),
            Override('my_repo', 'gpgcheck', '0')
        ]
        self.dialog.show()

        # Check that the model is populated correctly
        store = self.dialog.overrides_store
        tree_iter = store.get_iter_first()
        self.assertTrue(tree_iter is not None)
        self.assertTrue(store.iter_next(tree_iter) is None)

        self.assertEquals("my_repo",
                          store.get_value(tree_iter, store['repo_id']))
        self.assertTrue(store.get_value(tree_iter, store['enabled']))
        # has overrides so make sure that we are modified
        self.assertTrue(store.get_value(tree_iter, store['modified']))
        # make sure that there is an icon since we are modified
        self.assertTrue(
            store.get_value(tree_iter, store['modified-icon']) is not None)
        self.assertEquals("MY_REPO", store.get_value(tree_iter, store['name']))
        self.assertEquals('http://foo.bar',
                          store.get_value(tree_iter, store['baseurl']))
        self.assertFalse(store.get_value(tree_iter, store['gpgcheck']))
        # This will be True if there is an override that modifies the gpgcheck value
        self.assertTrue(store.get_value(tree_iter, store['gpgcheck_modified']))

        # verify that the model stores the correct override info for this repo
        override_data = store.get_value(tree_iter, store['override_data'])
        self.assertEquals(2, len(override_data))
        self.assertTrue('enabled' in override_data)
        self.assertEquals('1', override_data['enabled'])
        self.assertTrue('gpgcheck' in override_data)
        self.assertEquals('0', override_data['gpgcheck'])

        # Check that the correct repo was stored in the model
        self.assertEquals(repo, store.get_value(tree_iter, store['repo_data']))

        # Check that the details view is populated correctly
        name = self._get_text(self.dialog.name_text)
        self.assertEquals("MY_REPO", name)

        baseurl = self._get_text(self.dialog.baseurl_text)
        self.assertEquals("http://foo.bar", baseurl)

        # Check the state of the gpgcheck editing widgets
        self.assertFalse(self.dialog.gpgcheck_text.props.visible)
        self.assertFalse(self.dialog.gpgcheck_edit_button.props.visible)

        self.assertTrue(self.dialog.gpgcheck_combo_box.props.visible)
        self.assertTrue(self.dialog.gpgcheck_combo_box.props.sensitive)
        self.assertFalse(
            self._get_combo_box_value(self.dialog.gpgcheck_combo_box))
        self.assertTrue(self.dialog.gpgcheck_remove_button.props.visible)
        self.assertTrue(self.dialog.gpgcheck_remove_button.props.sensitive)
コード例 #2
0
 def test_list_specific_repos(self):
     data = [
         Override('x', 'hello', 'world'),
         Override('z', 'greetings', 'mars')
     ]
     with Capture() as cap:
         self.cc._list(data, ['x'])
         output = cap.out
         self.assertTrue(re.search('Repository: x', output))
         self.assertTrue(re.search('\s+hello:\s+world', output))
         self.assertFalse(re.search('Repository: z', output))
コード例 #3
0
 def test_list_specific_repos(self):
     data = [
         Override("x", "hello", "world"),
         Override("z", "greetings", "mars")
     ]
     with Capture() as cap:
         self.cc._list(data, ["x"])
         output = cap.out
         self.assertTrue(re.search(r"Repository: x", output))
         self.assertTrue(re.search(r"\s+hello:\s+world", output))
         self.assertFalse(re.search(r"Repository: z", output))
コード例 #4
0
    def _update_override_mapping(self, attribute, model, path, iter, override_mapping):
        '''
        Process a single model row and determine if an override should be added/removed.
        '''
        repo = model.get_value(iter, model['repo_data'])
        remote_overrides = model.get_value(iter, model['override_data'])

        repo_attribute_value = self._get_boolean(repo[attribute])
        model_attribute_value = self._get_boolean(model.get_value(iter, model[attribute]))
        has_remote_override = remote_overrides and attribute in remote_overrides

        if not has_remote_override and model_attribute_value != repo_attribute_value:
            override_mapping["to_add"].append(Override(repo.id, attribute, str(int(model_attribute_value))))
        elif has_remote_override and model_attribute_value == repo_attribute_value:
            override_mapping["to_remove"].append(Override(repo.id, attribute))
コード例 #5
0
 def test_add_function(self):
     repos = ["x", "y"]
     override_props = {"a": "b", "c": "d"}
     overrides = [
         Override(repo, name, value) for repo in repos
         for name, value in list(override_props.items())
     ]
     expected = [
         {
             "contentLabel": "x",
             "name": "a",
             "value": "b"
         },
         {
             "contentLabel": "x",
             "name": "c",
             "value": "d"
         },
         {
             "contentLabel": "y",
             "name": "a",
             "value": "b"
         },
         {
             "contentLabel": "y",
             "name": "c",
             "value": "d"
         },
     ]
     result = self.overrides._add(overrides)
     self.assertTrue(self.assert_items_equals(expected, result))
コード例 #6
0
 def test_remove_function(self):
     repos = ["x", "y"]
     props_to_remove = ["a", "b"]
     removes = [
         Override(repo, name) for repo in repos for name in props_to_remove
     ]
     expected = [
         {
             "contentLabel": "x",
             "name": "a"
         },
         {
             "contentLabel": "x",
             "name": "b"
         },
         {
             "contentLabel": "y",
             "name": "a"
         },
         {
             "contentLabel": "y",
             "name": "b"
         },
     ]
     result = self.overrides._remove(removes)
     self.assertTrue(self.assert_items_equals(expected, result))
コード例 #7
0
ファイル: test_repogui.py プロジェクト: Lorquas/rhsm
 def test_remove_all_button_enabled_when_repo_has_modifications(self):
     self.repo_lib.get_repos.return_value = [self._create_repo("my_repo", [('enabled', '0')])]
     self.overrides_mock.get_overrides.return_value = [
         Override('my_repo', 'enabled', '1')
     ]
     self.dialog.show()
     self.assertTrue(self.dialog.reset_button.props.sensitive)
コード例 #8
0
ファイル: test_overrideslib.py プロジェクト: Lorquas/rhsm
 def test_remove_function(self):
     repos = ['x', 'y']
     props_to_remove = ['a', 'b']
     removes = [
         Override(repo, name) for repo in repos for name in props_to_remove
     ]
     expected = [
         {
             'contentLabel': 'x',
             'name': 'a'
         },
         {
             'contentLabel': 'x',
             'name': 'b'
         },
         {
             'contentLabel': 'y',
             'name': 'a'
         },
         {
             'contentLabel': 'y',
             'name': 'b'
         },
     ]
     result = self.overrides._remove(removes)
     self.assertTrue(self.assert_items_equals(expected, result))
コード例 #9
0
ファイル: test_overrideslib.py プロジェクト: Lorquas/rhsm
 def test_add_function(self):
     repos = ['x', 'y']
     override_props = {'a': 'b', 'c': 'd'}
     overrides = [
         Override(repo, name, value) for repo in repos
         for name, value in list(override_props.items())
     ]
     expected = [
         {
             'contentLabel': 'x',
             'name': 'a',
             'value': 'b'
         },
         {
             'contentLabel': 'x',
             'name': 'c',
             'value': 'd'
         },
         {
             'contentLabel': 'y',
             'name': 'a',
             'value': 'b'
         },
         {
             'contentLabel': 'y',
             'name': 'c',
             'value': 'd'
         },
     ]
     result = self.overrides._add(overrides)
     self.assertTrue(self.assert_items_equals(expected, result))
コード例 #10
0
 def test_list_nonexistant_repos(self):
     data = [Override('x', 'hello', 'world')]
     with Capture() as cap:
         self.cc._list(data, ['x', 'z'])
         output = cap.out
         self.assertTrue(re.search("Nothing is known about 'z'", output))
         self.assertTrue(re.search('Repository: x', output))
         self.assertTrue(re.search('\s+hello:\s+world', output))
コード例 #11
0
 def test_list_function(self):
     data = [
         Override('x', 'hello', 'world'),
         Override('x', 'blast-off', 'space'),
         Override('y', 'goodbye', 'earth'),
         Override('z', 'greetings', 'mars')
     ]
     with Capture() as cap:
         self.cc._list(data, None)
         output = cap.out
         self.assertTrue(re.search('Repository: x', output))
         self.assertTrue(re.search('\s+hello:\s+world', output))
         self.assertTrue(re.search('\s+blast-off:\s+space', output))
         self.assertTrue(re.search('Repository: y', output))
         self.assertTrue(re.search('\s+goodbye:\s+earth', output))
         self.assertTrue(re.search('Repository: z', output))
         self.assertTrue(re.search('\s+greetings:\s+mars', output))
コード例 #12
0
 def test_list_nonexistant_repos(self):
     data = [Override("x", "hello", "world")]
     with Capture() as cap:
         self.cc._list(data, ["x", "z"])
         output = cap.out
         self.assertTrue(re.search(r"Nothing is known about 'z'", output))
         self.assertTrue(re.search(r"Repository: x", output))
         self.assertTrue(re.search(r"\s+hello:\s+world", output))
コード例 #13
0
 def test_list_function(self):
     data = [
         Override("x", "hello", "world"),
         Override("x", "blast-off", "space"),
         Override("y", "goodbye", "earth"),
         Override("z", "greetings", "mars"),
     ]
     with Capture() as cap:
         self.cc._list(data, None)
         output = cap.out
         self.assertTrue(re.search(r"Repository: x", output))
         self.assertTrue(re.search(r"\s+hello:\s+world", output))
         self.assertTrue(re.search(r"\s+blast-off:\s+space", output))
         self.assertTrue(re.search(r"Repository: y", output))
         self.assertTrue(re.search(r"\s+goodbye:\s+earth", output))
         self.assertTrue(re.search(r"Repository: z", output))
         self.assertTrue(re.search(r"\s+greetings:\s+mars", output))
コード例 #14
0
 def _delete_override(self, repo, name):
     to_delete = Override(repo, name)
     current_overrides = self.backend.overrides.remove_overrides(self.identity.uuid, [to_delete])
     self.backend.overrides.update(current_overrides)
     self._refresh(current_overrides, self._get_selected_repo_id())
コード例 #15
0
 def _add_override(self, repo, name, value):
     to_add = Override(repo, name, value)
     current_overrides = self.backend.overrides.add_overrides(self.identity.uuid, [to_add])
     self.backend.overrides.update(current_overrides)
     self._refresh(current_overrides, self._get_selected_repo_id())
コード例 #16
0
    def _do_command(self):
        self._validate_options()
        # Abort if not registered
        self.assert_should_be_registered()

        supported_resources = get_supported_resources()
        if "content_overrides" not in supported_resources:
            system_exit(
                os.EX_UNAVAILABLE,
                _("Error: The 'repo-override' command is not supported by the server."
                  ))

        # update entitlement certificates if necessary. If we do have new entitlements
        # CertLib.update() will call RepoActionInvoker.update().
        self.entcertlib.update()
        # make sure the EntitlementDirectory singleton is refreshed
        self._request_validity_check()

        overrides = Overrides()

        if not manage_repos_enabled():
            print(_("Repositories disabled by configuration."))

        if self.options.list:
            results = overrides.get_overrides(self.identity.uuid)
            if results:
                self._list(results, self.options.repos)
            else:
                print(
                    _("This system does not have any content overrides applied to it."
                      ))
            return

        if self.options.additions:
            repo_ids = [
                repo.id
                for repo in overrides.repo_lib.get_repos(apply_overrides=False)
            ]
            to_add = [
                Override(repo, name, value) for repo in self.options.repos
                for name, value in list(self.options.additions.items())
            ]
            try:
                results = overrides.add_overrides(self.identity.uuid, to_add)
            except connection.RestlibException as ex:
                if ex.code == 400:
                    # blocklisted overrides specified.
                    # Print message and return a less severe code.
                    mapped_message: str = ExceptionMapper().get_message(ex)
                    system_exit(1, mapped_message)
                else:
                    raise ex

            # Print out warning messages if the specified repo does not exist in the repo file.
            for repo in self.options.repos:
                if repo not in repo_ids:
                    print(
                        _("Repository '{repo}' does not currently exist, but the override has been added."
                          ).format(repo=repo))

        if self.options.removals:
            to_remove = [
                Override(repo, item) for repo in self.options.repos
                for item in self.options.removals
            ]
            results = overrides.remove_overrides(self.identity.uuid, to_remove)
        if self.options.remove_all:
            results = overrides.remove_all_overrides(self.identity.uuid,
                                                     self.options.repos)

        # Update the cache and refresh the repo file.
        overrides.update(results)