Co-authored-by: Tomek Wójcik <labs@tomekwojcik.pl> Co-committed-by: Tomek Wójcik <labs@tomekwojcik.pl>
69 lines
1.7 KiB
Python
69 lines
1.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
# type: ignore
|
|
from __future__ import annotations
|
|
|
|
import http
|
|
|
|
from django.test import Client
|
|
from django.urls import reverse
|
|
import pytest
|
|
from pytest_django import asserts
|
|
|
|
from hotpocket_common.url import URL
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_ok(authenticated_client: Client):
|
|
# When
|
|
result = authenticated_client.get(
|
|
reverse('ui.integrations.extension.authenticate'),
|
|
follow=False,
|
|
)
|
|
|
|
# Then
|
|
assert result.status_code == http.HTTPStatus.FOUND
|
|
assert 'Location' in result.headers
|
|
|
|
redirect_url = URL(result.headers['Location'])
|
|
assert redirect_url.raw_path == reverse('ui.integrations.extension.post_authenticate')
|
|
assert 'auth_key' in redirect_url.query
|
|
|
|
assert 'extension_auth_key' in authenticated_client.session
|
|
assert authenticated_client.session['extension_auth_key'] == redirect_url.query['auth_key'][0]
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_inactive_account(inactive_account_client: Client):
|
|
# When
|
|
result = inactive_account_client.get(
|
|
reverse('ui.integrations.extension.authenticate'),
|
|
)
|
|
|
|
# Then
|
|
asserts.assertRedirects(
|
|
result,
|
|
reverse(
|
|
'ui.accounts.login',
|
|
query=[('next', reverse('ui.integrations.extension.authenticate'))],
|
|
),
|
|
fetch_redirect_response=False,
|
|
)
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_anonymous(client: Client):
|
|
# When
|
|
result = client.get(
|
|
reverse('ui.integrations.extension.authenticate'),
|
|
)
|
|
|
|
# Then
|
|
asserts.assertRedirects(
|
|
result,
|
|
reverse(
|
|
'ui.accounts.login',
|
|
query=[('next', reverse('ui.integrations.extension.authenticate'))],
|
|
),
|
|
fetch_redirect_response=False,
|
|
)
|