コード例 #1
0
    def test_set_duplicate_multi_environment(self):
        def env_list(*args, **kwargs):
            return [{
                "id": "1234",
                "name": "somename"
            }, {
                "id": "5678",
                "name": "othername"
            }]

        with patch("rhsm.connection.UEPConnection",
                   new_callable=StubUEP) as mock_uep:
            mock_uep.getEnvironmentList = env_list
            mock_uep.supports_resource = Mock(return_value=True)
            self.stub_cp_provider.basic_auth_cp = mock_uep

            rc = RegisterCommand()
            rc.cp = mock_uep
            rc.options = Mock()
            rc.options.activation_keys = None
            rc.options.environments = None
            rc._prompt_for_environment = Mock(
                return_value="somename,othername,somename")

            with Capture(silent=True):
                with self.assertRaises(SystemExit):
                    rc._process_environments(mock_uep, "owner")
コード例 #2
0
    def test_set_multi_environment_id_multi_available(self):
        def env_list(*args, **kwargs):
            return [{
                "id": "1234",
                "name": "somename"
            }, {
                "id": "5678",
                "name": "othername"
            }]

        with patch("rhsm.connection.UEPConnection",
                   new_callable=StubUEP) as mock_uep:
            mock_uep.getEnvironmentList = env_list
            mock_uep.supports_resource = Mock(return_value=True)
            mock_uep.has_capability = Mock(return_value=True)
            self.stub_cp_provider.basic_auth_cp = mock_uep

            rc = RegisterCommand()
            rc.cp = mock_uep
            rc.options = Mock()
            rc.options.activation_keys = None
            rc.options.environments = None
            rc._prompt_for_environment = Mock(
                return_value="somename,othername")
            env_id = rc._process_environments(mock_uep, "owner")
            expected = "1234,5678"
            self.assertEqual(expected, env_id)
コード例 #3
0
    def test_validate_multi_environment_with_activation_key(self):
        with patch("rhsm.connection.UEPConnection",
                   new_callable=StubUEP) as mock_uep:
            mock_uep.supports_resource = Mock(return_value=True)
            self.stub_cp_provider.basic_auth_cp = mock_uep

            rc = RegisterCommand()
            rc.cp = mock_uep
            rc.options = Mock()
            rc.options.activation_keys = "someAK"
            rc.options.environments = None
            ret = rc._process_environments(mock_uep, "owner")
            self.assertIsNone(ret)
コード例 #4
0
    def test_get_environment_id_one_available(self):
        def env_list(*args, **kwargs):
            return [{"id": "1234", "name": "somename"}]

        with patch('rhsm.connection.UEPConnection', new_callable=StubUEP) as mock_uep:
            mock_uep.getEnvironmentList = env_list
            mock_uep.supports_resource = Mock(return_value=True)
            self.stub_cp_provider.basic_auth_cp = mock_uep

            rc = RegisterCommand()
            rc.options = Mock()
            rc.options.activation_keys = None
            env_id = rc._get_environment_id(mock_uep, 'owner', None)

            expected = "1234"
            self.assertEqual(expected, env_id)
コード例 #5
0
    def test_get_environment_id_multi_available_bad_name(self):
        def env_list(*args, **kwargs):
            return [{"id": "1234", "name": "somename"},
                    {"id": "5678", "name": "othername"}]

        with patch('rhsm.connection.UEPConnection', new_callable=StubUEP) as mock_uep:
            mock_uep.getEnvironmentList = env_list
            mock_uep.supports_resource = Mock(return_value=True)
            self.stub_cp_provider.basic_auth_cp = mock_uep

            rc = RegisterCommand()
            rc.options = Mock()
            rc.options.activation_keys = None
            rc._prompt_for_environment = Mock(return_value="not_an_env")

            with Capture(silent=True):
                with self.assertRaises(SystemExit):
                    rc._get_environment_id(mock_uep, 'owner', None)
コード例 #6
0
    def test_get_environment_id_none_available(self):
        def env_list(*args, **kwargs):
            return []

        with patch("rhsm.connection.UEPConnection",
                   new_callable=StubUEP) as mock_uep:
            mock_uep.getEnvironmentList = env_list
            mock_uep.supports_resource = Mock(return_value=True)
            self.stub_cp_provider.basic_auth_cp = mock_uep

            rc = RegisterCommand()
            rc.options = Mock()
            rc.options.activation_keys = None
            rc.options.environments = None
            env_id = rc._process_environments(mock_uep, "owner")

            expected = None
            self.assertEqual(expected, env_id)
コード例 #7
0
    def test_validate_multi_capable_multi_entry(self):
        with patch("rhsm.connection.UEPConnection",
                   new_callable=StubUEP) as mock_uep:
            rc = RegisterCommand()
            rc.cp = mock_uep
            rc.is_registered = Mock(return_value=False)
            rc.options = Mock()
            rc.options.activation_keys = None
            rc.options.force = None
            rc.options.consumertype = None
            rc.options.environments = "One,Two"

            mock_uep.has_capability = Mock(return_value=False)
            try:
                rc._validate_options()
                self.fail("No Exception Raised")
            except SystemExit as e:
                self.assertEqual(e.code, os.EX_USAGE)

            mock_uep.has_capability = Mock(return_value=True)
            try:
                rc._validate_options()
            except SystemExit:
                self.fail("Exception Raised")