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
 def test_missing_doc_reviewer(self, monkeypatch, module_args):
     """
     When ensure_product() raises DocsReviewerNotFoundError, the
     Ansible module exits with the proper error message.
     """
     mock_ensure = Mock()
     mock_ensure.side_effect = \
         DocsReviewerNotFoundError('*****@*****.**')
     monkeypatch.setattr(errata_tool_product, 'ensure_product', mock_ensure)
     module_args['default_docs_reviewer'] = '*****@*****.**',
     set_module_args(module_args)
     with pytest.raises(AnsibleFailJson) as ex:
         main()
     result = ex.value.args[0]
     assert result['changed'] is False
     expected = 'default_docs_reviewer [email protected] account not found'
     assert result['msg'] == expected
 def test_missing_program_manager(self, monkeypatch):
     mock_ensure = Mock()
     mock_ensure.side_effect = \
         ProgramManagerNotFoundError('*****@*****.**')
     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(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