You've already forked hotpocket
BTHLABS-50: Safari Web extension
Co-authored-by: Tomek Wójcik <labs@tomekwojcik.pl> Co-committed-by: Tomek Wójcik <labs@tomekwojcik.pl>
This commit is contained in:
@@ -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,
|
||||
)
|
||||
@@ -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,
|
||||
)
|
||||
@@ -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,
|
||||
)
|
||||
@@ -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,
|
||||
)
|
||||
Reference in New Issue
Block a user