Exemple #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)
Exemple #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"})
Exemple #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"
        })
Exemple #4
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"})