Release v1.0.0
Some checks failed
CI / Checks (push) Failing after 13m2s

This commit is contained in:
2025-08-20 21:00:50 +02:00
commit b4338e2769
401 changed files with 23576 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
# -*- 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
@pytest.mark.django_db
def test_ok(authenticated_client: Client):
# When
result = authenticated_client.get(
reverse('ui.accounts.browse'),
)
# Then
assert result.status_code == http.HTTPStatus.NOT_FOUND
@pytest.mark.django_db
def test_inactive_account(inactive_account_client: Client):
# When
result = inactive_account_client.get(
reverse('ui.accounts.browse'),
)
# Then
asserts.assertRedirects(
result,
reverse(
'ui.accounts.login',
query=[('next', reverse('ui.accounts.browse'))],
),
fetch_redirect_response=False,
)
@pytest.mark.django_db
def test_anonymous(client: Client):
# When
result = client.get(
reverse('ui.accounts.browse'),
)
# Then
asserts.assertRedirects(
result,
reverse(
'ui.accounts.login',
query=[('next', reverse('ui.accounts.browse'))],
),
fetch_redirect_response=False,
)

View File

@@ -0,0 +1,60 @@
# -*- coding: utf-8 -*-
# type: ignore
from __future__ import annotations
from django.test import Client
from django.urls import reverse
import pytest
from pytest_django import asserts
@pytest.mark.django_db
def test_ok(authenticated_client: Client):
# When
result = authenticated_client.get(
reverse('ui.accounts.index'),
follow=False,
)
# Then
asserts.assertRedirects(
result,
reverse('ui.accounts.settings'),
fetch_redirect_response=False,
)
@pytest.mark.django_db
def test_inactive_account(inactive_account_client: Client):
# When
result = inactive_account_client.get(
reverse('ui.accounts.index'),
)
# Then
asserts.assertRedirects(
result,
reverse(
'ui.accounts.login',
query=[('next', reverse('ui.accounts.index'))],
),
fetch_redirect_response=False,
)
@pytest.mark.django_db
def test_anonymous(client: Client):
# When
result = client.get(
reverse('ui.accounts.index'),
)
# Then
asserts.assertRedirects(
result,
reverse(
'ui.accounts.login',
query=[('next', reverse('ui.accounts.index'))],
),
fetch_redirect_response=False,
)

View File

@@ -0,0 +1,203 @@
# -*- 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_backend_testing.services.accounts import AccountsTestingService
@pytest.fixture
def payload(account_password):
return {
'old_password': account_password,
'new_password1': 'thisisnewpassword',
'new_password2': 'thisisnewpassword',
}
@pytest.mark.django_db
def test_ok(account_with_password_client: Client,
payload,
account_with_password,
):
# When
result = account_with_password_client.post(
reverse('ui.accounts.settings.password'),
data=payload,
)
# Then
asserts.assertRedirects(
result,
reverse('ui.accounts.settings.password'),
fetch_redirect_response=False,
)
AccountsTestingService().assert_password_changed(
pk=account_with_password.pk,
reference=account_with_password,
)
@pytest.mark.xfail(
reason="Apparently I'm too dumb to properly fix a federated account, LOL",
)
@pytest.mark.django_db
def test_federated_account(federated_account_client: Client,
payload,
federated_account,
):
# When
result = federated_account_client.post(
reverse('ui.accounts.settings.password'),
data=payload,
)
# Then
assert result.status_code == 500
@pytest.mark.django_db
def test_invalid_all_empty(authenticated_client: Client,
payload,
):
# Given
effective_payload = {
key: ''
for key
in payload.keys()
}
# When
result = authenticated_client.post(
reverse('ui.accounts.settings.password'),
data=effective_payload,
)
# Then
assert result.status_code == http.HTTPStatus.OK
assert 'old_password' in result.context['form'].errors
assert 'new_password1' in result.context['form'].errors
assert 'new_password2' in result.context['form'].errors
@pytest.mark.django_db
def test_invalid_all_missing(authenticated_client: Client):
# Given
effective_payload = {}
# When
result = authenticated_client.post(
reverse('ui.accounts.settings.password'),
data=effective_payload,
)
# Then
assert result.status_code == http.HTTPStatus.OK
assert 'old_password' in result.context['form'].errors
assert 'new_password1' in result.context['form'].errors
assert 'new_password2' in result.context['form'].errors
@pytest.mark.django_db
def test_invaliid_bad_old_password(account_with_password_client: Client,
payload,
account_with_password,
):
# Given
payload['old_password'] = 'badpassword'
# When
result = account_with_password_client.post(
reverse('ui.accounts.settings.password'),
data=payload,
)
# Then
assert result.status_code == http.HTTPStatus.OK
assert 'old_password' in result.context['form'].errors
@pytest.mark.django_db
def test_invaliid_bad_new_password1(account_with_password_client: Client,
payload,
account_with_password,
):
# Given
payload['new_password1'] = 'badpassword'
# When
result = account_with_password_client.post(
reverse('ui.accounts.settings.password'),
data=payload,
)
# Then
assert result.status_code == http.HTTPStatus.OK
assert 'new_password2' in result.context['form'].errors
@pytest.mark.django_db
def test_invaliid_bad_new_password2(account_with_password_client: Client,
payload,
account_with_password,
):
# Given
payload['new_password2'] = 'badpassword'
# When
result = account_with_password_client.post(
reverse('ui.accounts.settings.password'),
data=payload,
)
# Then
assert result.status_code == http.HTTPStatus.OK
assert 'new_password2' in result.context['form'].errors
@pytest.mark.django_db
def test_inactive_account(inactive_account_client: Client):
# When
result = inactive_account_client.post(
reverse('ui.accounts.settings.password'),
)
# Then
asserts.assertRedirects(
result,
reverse(
'ui.accounts.login',
query=[('next', reverse('ui.accounts.settings.password'))],
),
fetch_redirect_response=False,
)
@pytest.mark.django_db
def test_anonymous(client: Client):
# When
result = client.post(
reverse('ui.accounts.settings.password'),
)
# Then
asserts.assertRedirects(
result,
reverse(
'ui.accounts.login',
query=[('next', reverse('ui.accounts.settings.password'))],
),
fetch_redirect_response=False,
)

View File

@@ -0,0 +1,137 @@
# -*- coding: utf-8 -*-
# type: ignore
from __future__ import annotations
from django.test import Client
from django.urls import reverse
import pytest
from pytest_django import asserts
@pytest.mark.django_db
def test_ok(authenticated_client: Client):
# Given
session = authenticated_client.session
session['post_login_next_url'] = (
reverse('ui.accounts.settings.settings')
)
session.save()
# When
result = authenticated_client.post(
reverse('ui.accounts.post_login'),
)
asserts.assertRedirects(
result,
reverse('ui.accounts.settings.settings'),
fetch_redirect_response=False,
)
@pytest.mark.django_db
def test_ok_without_next_url(authenticated_client: Client):
# When
result = authenticated_client.post(
reverse('ui.accounts.post_login'),
)
asserts.assertRedirects(
result,
reverse('ui.index.index'),
fetch_redirect_response=False,
)
@pytest.mark.django_db
def test_ok_absolute_url(authenticated_client: Client, settings):
# Given
settings.ALLOWED_HOSTS = ['testserver']
session = authenticated_client.session
session['post_login_next_url'] = (
'http://testserver/'
)
session.save()
# When
result = authenticated_client.post(
reverse('ui.accounts.post_login'),
)
asserts.assertRedirects(
result,
'http://testserver/',
fetch_redirect_response=False,
)
@pytest.mark.django_db
def test_allowed_hosts_asterisk(authenticated_client: Client, settings):
# Given
settings.ALLOWED_HOSTS = ['*']
session = authenticated_client.session
session['post_login_next_url'] = (
'http://thisisinsecure/'
)
session.save()
# When
result = authenticated_client.post(
reverse('ui.accounts.post_login'),
)
# `*` doesn't have effect here. Django requires hard matches on the
# `next_url` netloc. IDC, really. Redirects to absolute URLs here shouldn't
# happen unless somebody tries something funny. In wich case, NOPE.
asserts.assertRedirects(
result,
'/',
fetch_redirect_response=False,
)
@pytest.mark.django_db
def test_allowed_hosts_mismatch(authenticated_client: Client, settings):
# Given
settings.ALLOWED_HOSTS = ['testserver']
session = authenticated_client.session
session['post_login_next_url'] = (
'http://thisisinsecure/'
)
session.save()
# When
result = authenticated_client.post(
reverse('ui.accounts.post_login'),
)
asserts.assertRedirects(
result,
'/',
fetch_redirect_response=False,
)
@pytest.mark.django_db
def test_inactive_account(inactive_account_client: Client):
# When
result = inactive_account_client.post(
reverse('ui.accounts.post_login'),
)
# Then
assert result.status_code == 403
@pytest.mark.django_db
def test_anonymous(client: Client):
# When
result = client.post(
reverse('ui.accounts.post_login'),
)
# Then
assert result.status_code == 403

View File

@@ -0,0 +1,144 @@
# -*- 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_backend_testing.services.accounts import AccountsTestingService
@pytest.fixture
def payload():
return {
'first_name': 'Ziomek',
'last_name': 'Dog',
'email': 'woof@ziomek.dog',
}
@pytest.mark.django_db
def test_ok(authenticated_client: Client,
payload,
account,
):
# When
result = authenticated_client.post(
reverse('ui.accounts.settings.profile'),
data=payload,
)
# Then
asserts.assertRedirects(
result,
reverse('ui.accounts.settings.profile'),
fetch_redirect_response=False,
)
AccountsTestingService().assert_edited(
pk=account.pk,
update=payload,
reference=account,
)
@pytest.mark.xfail(
reason="Apparently I'm too dumb to properly fix a federated account, LOL",
)
@pytest.mark.django_db
def test_federated_account(federated_account_client: Client,
payload,
federated_account,
):
# When
result = federated_account_client.post(
reverse('ui.accounts.settings.profile'),
data=payload,
)
# Then
assert result.status_code == 500
@pytest.mark.django_db
def test_invalid_all_empty(authenticated_client: Client,
payload,
):
# Given
effective_payload = {
key: ''
for key
in payload.keys()
}
# When
result = authenticated_client.post(
reverse('ui.accounts.settings.profile'),
data=effective_payload,
)
# Then
assert result.status_code == http.HTTPStatus.OK
assert 'first_name' in result.context['form'].errors
assert 'last_name' in result.context['form'].errors
assert 'email' in result.context['form'].errors
@pytest.mark.django_db
def test_invalid_all_missing(authenticated_client: Client):
# Given
effective_payload = {}
# When
result = authenticated_client.post(
reverse('ui.accounts.settings.profile'),
data=effective_payload,
)
# Then
assert result.status_code == http.HTTPStatus.OK
assert 'first_name' in result.context['form'].errors
assert 'last_name' in result.context['form'].errors
assert 'email' in result.context['form'].errors
@pytest.mark.django_db
def test_inactive_account(inactive_account_client: Client):
# When
result = inactive_account_client.post(
reverse('ui.accounts.settings.profile'),
)
# Then
asserts.assertRedirects(
result,
reverse(
'ui.accounts.login',
query=[('next', reverse('ui.accounts.settings.profile'))],
),
fetch_redirect_response=False,
)
@pytest.mark.django_db
def test_anonymous(client: Client):
# When
result = client.post(
reverse('ui.accounts.settings.profile'),
)
# Then
asserts.assertRedirects(
result,
reverse(
'ui.accounts.login',
query=[('next', reverse('ui.accounts.settings.profile'))],
),
fetch_redirect_response=False,
)

View File

@@ -0,0 +1,59 @@
# -*- coding: utf-8 -*-
# type: ignore
from __future__ import annotations
from django.test import Client
from django.urls import reverse
import pytest
from pytest_django import asserts
@pytest.mark.django_db
def test_ok(authenticated_client: Client):
# When
result = authenticated_client.get(
reverse('ui.accounts.settings'),
)
# Then
asserts.assertRedirects(
result,
reverse('ui.accounts.settings.profile'),
fetch_redirect_response=False,
)
@pytest.mark.django_db
def test_inactive_account(inactive_account_client: Client):
# When
result = inactive_account_client.get(
reverse('ui.accounts.settings'),
)
# Then
asserts.assertRedirects(
result,
reverse(
'ui.accounts.login',
query=[('next', reverse('ui.accounts.settings'))],
),
fetch_redirect_response=False,
)
@pytest.mark.django_db
def test_anonymous(client: Client):
# When
result = client.get(
reverse('ui.accounts.settings'),
)
# Then
asserts.assertRedirects(
result,
reverse(
'ui.accounts.login',
query=[('next', reverse('ui.accounts.settings'))],
),
fetch_redirect_response=False,
)

View File

@@ -0,0 +1,151 @@
# -*- 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_backend_testing.services.accounts import AccountsTestingService
@pytest.fixture
def payload():
return {
'theme': 'cosmo',
'auto_load_embeds': 'True',
}
@pytest.mark.django_db
def test_ok(authenticated_client: Client,
payload,
account,
):
# When
result = authenticated_client.post(
reverse('ui.accounts.settings.settings'),
data=payload,
)
# Then
asserts.assertRedirects(
result,
reverse('ui.accounts.settings.settings'),
fetch_redirect_response=False,
)
AccountsTestingService().assert_settings_edited(
pk=account.pk,
update={
'theme': None, # TODO: Themes!
'auto_load_embeds': True,
},
reference=account,
)
@pytest.mark.django_db
def test_invalid_invalid_selects(authenticated_client: Client):
# Given
effective_payload = {
'auto_load_embeds': 'thisisntright',
}
# When
result = authenticated_client.post(
reverse('ui.accounts.settings.settings'),
data=effective_payload,
)
# Then
assert result.status_code == http.HTTPStatus.OK
assert 'auto_load_embeds' in result.context['form'].errors
@pytest.mark.xfail(
reason='WIP',
)
@pytest.mark.django_db
def test_invalid_all_empty(authenticated_client: Client,
payload,
):
# Given
effective_payload = {
key: ''
for key
in payload.keys()
}
# When
result = authenticated_client.post(
reverse('ui.accounts.settings.settings'),
data=effective_payload,
)
# Then
assert result.status_code == http.HTTPStatus.OK
assert 'theme' in result.context['form'].errors
assert 'auto_load_embeds' not in result.context['form'].errors
@pytest.mark.xfail(
reason='WIP',
)
@pytest.mark.django_db
def test_invalid_all_missing(authenticated_client: Client):
# Given
effective_payload = {}
# When
result = authenticated_client.post(
reverse('ui.accounts.settings.settings'),
data=effective_payload,
)
# Then
assert result.status_code == http.HTTPStatus.OK
assert 'theme' in result.context['form'].errors
assert 'auto_load_embeds' not in result.context['form'].errors
@pytest.mark.django_db
def test_inactive_account(inactive_account_client: Client):
# When
result = inactive_account_client.post(
reverse('ui.accounts.settings.settings'),
)
# Then
asserts.assertRedirects(
result,
reverse(
'ui.accounts.login',
query=[('next', reverse('ui.accounts.settings.settings'))],
),
fetch_redirect_response=False,
)
@pytest.mark.django_db
def test_anonymous(client: Client):
# When
result = client.post(
reverse('ui.accounts.settings.settings'),
)
# Then
asserts.assertRedirects(
result,
reverse(
'ui.accounts.login',
query=[('next', reverse('ui.accounts.settings.settings'))],
),
fetch_redirect_response=False,
)