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"})
    def test_get_team_members_method_no_members_returned(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_members_no_members_resp()
        mock_get_version.return_value = get_version_resp()

        grafana_iface = grafana_team.GrafanaTeamInterface(module)
        res = grafana_iface.get_team_members(2)
        mock_fetch_url.assert_called_once_with(
            module, 'http://grafana.example.com/api/teams/2/members',
            data=None,
            headers={'Content-Type': 'application/json', 'Authorization': self.authorization},
            method='GET')
        self.assertEquals(res, [])
    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"})
    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)