Example #1
0
    def test_delete_team_member_method(self, mock_fetch_url, mock_get_version):
        set_module_args({
            'state': 'present',
            'name': 'MyTestTeam',
            'email': '*****@*****.**',
            'url': 'http://grafana.example.com'
        })
        module = grafana_team.setup_module_object()
        mock_fetch_url.return_value = delete_team_member_resp()
        mock_get_version.return_value = get_version_resp()

        grafana_iface = grafana_team.GrafanaTeamInterface(module)
        with patch.object(
                grafana_team.GrafanaTeamInterface,
                'get_user_id_from_mail') as mock_get_user_id_from_mail:
            mock_get_user_id_from_mail.return_value = 42
            res = grafana_iface.delete_team_member(2, "*****@*****.**")
            mock_fetch_url.assert_called_once_with(
                module,
                'http://grafana.example.com/api/teams/2/members/42',
                data=None,
                headers={
                    'Content-Type': 'application/json',
                    'Authorization': self.authorization
                },
                method='DELETE')
            self.assertEquals(res, None)
Example #2
0
    def test_update_team_method(self, mock_fetch_url, mock_get_version):
        set_module_args({
            'state': 'present',
            'name': 'MyTestTeam',
            'email': '*****@*****.**',
            'url': 'http://grafana.example.com'
        })
        module = grafana_team.setup_module_object()
        mock_fetch_url.return_value = team_updated_resp()
        mock_get_version.return_value = get_version_resp()

        grafana_iface = grafana_team.GrafanaTeamInterface(module)
        res = grafana_iface.update_team(2, "MyTestTeam", "*****@*****.**")
        mock_fetch_url.assert_called_once_with(
            module,
            'http://grafana.example.com/api/teams/2',
            data=json.dumps({
                "email": "*****@*****.**",
                "name": "MyTestTeam"
            },
                            sort_keys=True),
            headers={
                'Content-Type': 'application/json',
                'Authorization': self.authorization
            },
            method='PUT')
        self.assertEquals(res, {"message": "Team updated"})
Example #3
0
    def test_get_team_method_with_existing_team(self, mock_fetch_url,
                                                mock_get_version):
        set_module_args({
            'state': 'present',
            'name': 'MyTestTeam',
            'email': '*****@*****.**',
            'url': 'http://grafana.example.com'
        })
        module = grafana_team.setup_module_object()
        mock_fetch_url.return_value = team_exists_resp()
        mock_get_version.return_value = get_version_resp()

        grafana_iface = grafana_team.GrafanaTeamInterface(module)
        res = grafana_iface.get_team("MyTestTeam")
        mock_fetch_url.assert_called_once_with(
            module,
            'http://grafana.example.com/api/teams/search?name=MyTestTeam',
            data=None,
            headers={
                'Content-Type': 'application/json',
                'Authorization': self.authorization
            },
            method='GET')
        self.assertEquals(res, {
            "email": "*****@*****.**",
            "name": "MyTestTeam"
        })
Example #4
0
    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'))
Example #5
0
    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')
Example #6
0
    def test_delete_team_method(self, mock_fetch_url, mock_get_version):
        set_module_args({
            'state': 'absent',
            'name': 'MyTestTeam',
            'email': '*****@*****.**',
            'url': 'http://grafana.example.com'
        })
        module = grafana_team.setup_module_object()
        mock_fetch_url.return_value = team_deleted_resp()
        mock_get_version.return_value = get_version_resp()

        grafana_iface = grafana_team.GrafanaTeamInterface(module)
        res = grafana_iface.delete_team(2)
        mock_fetch_url.assert_called_once_with(
            module,
            'http://grafana.example.com/api/teams/2',
            data=None,
            headers={
                'Content-Type': 'application/json',
                'Authorization': self.authorization
            },
            method='DELETE')
        self.assertEquals(res, {"message": "Team deleted"})