コード例 #1
0
    def test_strict_user_check_missing_role(self, monkeypatch, module_args):
        """
        Test that the module fails when in strict user check mode
        and the user doesn't have the 'docs' role.
        """
        monkeypatch.setenv('ANSIBLE_STRICT_USER_CHECK_MODE', 'True')

        module_args['default_docs_reviewer'] = '*****@*****.**'
        module_args['_ansible_check_mode'] = True
        set_module_args(module_args)

        mock_ensure = Mock()
        mock_ensure.return_value = {'changed': True}
        monkeypatch.setattr(errata_tool_product, 'ensure_product', mock_ensure)

        mock_get_user = Mock()
        mock_get_user.return_value = {'roles': ['qa']}
        monkeypatch.setattr(common_errata_tool, 'get_user', mock_get_user)

        with pytest.raises(AnsibleFailJson) as ex:
            main()

        result = ex.value.args[0]
        assert result['changed'] is False

        expected = "User [email protected] does not have 'docs' role in ET"
        assert result['msg'] == expected
コード例 #2
0
    def test_strict_user_check_missing_user(self, monkeypatch, module_args):
        """
        Test that the module fails when in strict user check mode
        and the user doesn't exist.
        """
        monkeypatch.setenv('ANSIBLE_STRICT_USER_CHECK_MODE', 'True')

        module_args['program_manager'] = '*****@*****.**'
        module_args['_ansible_check_mode'] = True
        set_module_args(module_args)

        mock_ensure = Mock()
        mock_ensure.return_value = {'changed': True}
        monkeypatch.setattr(errata_tool_release, 'ensure_release', mock_ensure)

        mock_get_user = Mock()
        mock_get_user.side_effect = UserNotFoundError('*****@*****.**')
        monkeypatch.setattr(common_errata_tool, 'get_user', mock_get_user)

        with pytest.raises(AnsibleFailJson) as ex:
            main()

        result = ex.value.args[0]
        assert result['changed'] is False

        expected = 'program_manager [email protected] account not found'
        assert result['msg'] == expected
コード例 #3
0
 def mock_ensure_variant(self, monkeypatch):
     """
     Fake this large method, since we unit-test it individually elsewhere.
     """
     mock_ensure = Mock()
     mock_ensure.return_value = {'changed': True}
     monkeypatch.setattr(errata_tool_variant, 'ensure_variant', mock_ensure)
     return mock_ensure
コード例 #4
0
 def test_simple(self, monkeypatch, module_args):
     """ Create a simple minimal product. """
     mock_ensure = Mock()
     mock_ensure.return_value = {'changed': True}
     monkeypatch.setattr(errata_tool_product, 'ensure_product', mock_ensure)
     set_module_args(module_args)
     with pytest.raises(AnsibleExitJson) as ex:
         main()
     result = ex.value.args[0]
     assert result['changed'] is True
コード例 #5
0
 def test_simple_async(self, monkeypatch):
     mock_ensure = Mock()
     mock_ensure.return_value = {'changed': True}
     monkeypatch.setattr(errata_tool_release, 'ensure_release', mock_ensure)
     module_args = {
         'name': 'rhceph-5.0',
         'type': 'Async',
         'description': 'Red Hat Ceph Storage 5.0',
         'program_manager': '*****@*****.**',
         'product_versions': [],
     }
     set_module_args(module_args)
     with pytest.raises(AnsibleExitJson) as ex:
         main()
     result = ex.value.args[0]
     assert result['changed'] is True