def test_module_setup_fails_without_params(self): set_module_args({}) with self.assertRaises(AnsibleFailJson) as result: grafana_team.main() err, arg_list = result.exception.args[0]['msg'].split(':') missing_args = [item.strip() for item in arg_list.split(',')] self.assertEqual(err, 'missing required arguments') self.assertEqual(arg_list, ["name", "email", "url"])
def test_module_setup_fails_without_url(self): set_module_args({ 'name': 'MyTestTeam', 'email': '*****@*****.**', }) with self.assertRaises(AnsibleFailJson) as result: grafana_team.main() self.assertEqual(result.exception.args[0]['msg'], 'missing required arguments: url')
def test_module_setup_fails_without_name(self): set_module_args({ 'email': '*****@*****.**', 'url': 'http://grafana.example.com' }) with self.assertRaises(AnsibleFailJson) as result: grafana_team.main() self.assertEqual(result.exception.args[0]['msg'], 'missing required arguments: name')
def test_module_setup_fails_with_mutually_exclusive_auth_methods(self): set_module_args({ 'name': 'MyTestTeam', 'email': '*****@*****.**', 'url': 'http://grafana.example.com', 'grafana_user': '******', 'grafana_api_key': 'random_api_key', }) with self.assertRaises(AnsibleFailJson) as result: grafana_team.main() self.assertEqual( result.exception.args[0]['msg'], 'parameters are mutually exclusive: url_username|grafana_api_key')
def test_module_failure_with_permission_denied_resp( self, mock_fetch_url, mock_get_version): set_module_args({ 'name': 'MyTestTeam', 'email': '*****@*****.**', 'url': 'http://grafana.example.com', }) module = grafana_team.setup_module_object() mock_fetch_url.return_value = permission_denied_resp() mock_get_version.return_value = get_version_resp() with self.assertRaises(AnsibleFailJson) as result: grafana_team.main() self.assertTrue( result.exception.args[0]['msg'].startswith('Permission Denied'))
def test_module_fails_with_low_grafana_version(self, mock_get_version): set_module_args({ 'name': 'MyTestTeam', 'email': '*****@*****.**', 'url': 'http://grafana.example.com', 'grafana_user': '******', 'grafana_password': '******', }) module = grafana_team.setup_module_object() mock_get_version.return_value = get_low_version_resp() with self.assertRaises(AnsibleFailJson) as result: grafana_team.main() self.assertEqual(result.exception.args[0]['msg'], 'Teams API is available starting Grafana v5')