oncall-engine/engine/apps/grafana_plugin/tests/test_install.py
Joey Orlando 7c4b40a046
upgrade to Python 3.12 (#3456)
# What this PR does

Upgrade to Python 3.12 + fix several invalid test assertions that lead
to test failures in the latest version of `pytest`:
```
AttributeError: 'called_once_with' is not a valid assertion. Use a spec for the mock if 'called_once_with' is meant to be an attribute.. Did you mean: 'assert_called_once_with'?
```

## Checklist

- [ ] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)
2023-11-30 13:47:41 +00:00

27 lines
1,008 B
Python

from unittest.mock import patch
import pytest
from django.urls import reverse
from rest_framework import status
from rest_framework.test import APIClient
GRAFANA_TOKEN = "TESTTOKEN"
@patch("apps.grafana_plugin.views.install.sync_organization", return_value=None)
@pytest.mark.django_db
def test_it_triggers_an_organization_sync_and_saves_the_grafana_token(
mocked_sync_organization, make_organization_and_user_with_plugin_token, make_user_auth_headers
):
organization, user, token = make_organization_and_user_with_plugin_token()
client = APIClient()
auth_headers = make_user_auth_headers(user, token, grafana_token=GRAFANA_TOKEN)
response = client.post(reverse("grafana-plugin:install"), format="json", **auth_headers)
assert response.status_code == status.HTTP_204_NO_CONTENT
mocked_sync_organization.assert_called_once_with(organization)
# make sure api token is saved on the org
organization.refresh_from_db()
assert organization.api_token == GRAFANA_TOKEN