oncall-engine/engine/apps/grafana_plugin/tests/test_install.py
Joey Orlando 49d20f1a7e
bump uwsgi to 2.0.26 + Python to 3.12.3 (#4495)
# What this PR does

- bumps `uwsgi` to latest version (`2.0.26`), which unblocks us from
bumping Python to 3.12
- bumps Python to 3.12.3
- refactor the Snyk GitHub Actions workflow to use the composable
actions for installed frontend and backend dependencies
- fixes several `AttributeError`s in our tests that went from a warning
to an error in Python 3.12 (see
https://github.com/python/cpython/issues/100690)

# Which issue(s) this PR closes

Closes #4358
Closes https://github.com/grafana/oncall/issues/4387
2024-06-10 15:33:37 -04: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