Skip to content

Commit

Permalink
tests: fix and reenable the user tests
Browse files Browse the repository at this point in the history
  • Loading branch information
goapunk committed May 3, 2022
1 parent f151bb2 commit f47a68a
Showing 1 changed file with 39 additions and 32 deletions.
71 changes: 39 additions & 32 deletions tests/users/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
from allauth.account.models import EmailAddress
from django.contrib import auth
from django.core import mail
from django.test import modify_settings
from django.urls import reverse

# from adhocracy4.test.helpers import redirect_target
from adhocracy4.test.helpers import redirect_target
from apps.users import models

User = auth.get_user_model()
Expand Down Expand Up @@ -56,6 +57,9 @@ def test_logout_with_next(user, client, logout_url):
assert '_auth_user_id' not in client.session


@modify_settings(MIDDLEWARE={
'remove': 'apps.djangosaml2_overwrites.middlewares.SamlSignupMiddleware',
})
@pytest.mark.django_db
def test_register(client, signup_url):
assert EmailAddress.objects.count() == 0
Expand All @@ -78,24 +82,27 @@ def test_register(client, signup_url):
email=email, verified=False
).count() == 1
assert len(mail.outbox) == 1
# confirmation_url = re.search(
# r'(http://testserver/.*/)',
# str(mail.outbox[0].body)
# ).group(0)

# confirm_email_response = client.get(confirmation_url)
# assert confirm_email_response.status_code == 200
# assert EmailAddress.objects.filter(
# email=email, verified=False
# ).count() == 1
# confirm_email_response = client.post(confirmation_url)
# assert confirm_email_response.status_code == 302
# assert EmailAddress.objects.filter(
# email=email, verified=True
# ).count() == 1
# assert User.objects.get(email=email).get_newsletters is True
confirmation_url = re.search(
r'(http://testserver/.*/)',
str(mail.outbox[0].body)
).group(0)

confirm_email_response = client.get(confirmation_url)
assert confirm_email_response.status_code == 200
assert EmailAddress.objects.filter(
email=email, verified=False
).count() == 1
confirm_email_response = client.post(confirmation_url)
assert confirm_email_response.status_code == 302
assert EmailAddress.objects.filter(
email=email, verified=True
).count() == 1
assert User.objects.get(email=email).get_newsletters is True


@modify_settings(MIDDLEWARE={
'remove': 'apps.djangosaml2_overwrites.middlewares.SamlSignupMiddleware',
})
@pytest.mark.django_db
def test_register_with_next(client, signup_url):
assert EmailAddress.objects.count() == 0
Expand All @@ -118,21 +125,21 @@ def test_register_with_next(client, signup_url):
email=email, verified=False
).count() == 1
assert len(mail.outbox) == 1
# confirmation_url = re.search(
# r'(http://testserver/.*/?next=/en/projects/pppp/)',
# str(mail.outbox[0].body)
# ).group(0)
# confirm_email_response = client.get(confirmation_url)
# assert confirm_email_response.status_code == 200
# assert EmailAddress.objects.filter(
# email=email, verified=False
# ).count() == 1
# confirm_email_response = client.post(confirmation_url)
# assert confirm_email_response.status_code == 302
# assert redirect_target(confirm_email_response) == "project-detail"
# assert EmailAddress.objects.filter(
# email=email, verified=True
# ).count() == 1
confirmation_url = re.search(
r'(http://testserver/.*/?next=/en/projects/pppp/)',
str(mail.outbox[0].body)
).group(0)
confirm_email_response = client.get(confirmation_url)
assert confirm_email_response.status_code == 200
assert EmailAddress.objects.filter(
email=email, verified=False
).count() == 1
confirm_email_response = client.post(confirmation_url)
assert confirm_email_response.status_code == 302
assert redirect_target(confirm_email_response) == "project-detail"
assert EmailAddress.objects.filter(
email=email, verified=True
).count() == 1


@pytest.mark.django_db
Expand Down

0 comments on commit f47a68a

Please sign in to comment.