-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- adds basic flow integration test for Registrion Flow
- replaces print by self.stdout.write within command - replaces date.today calls by timezone ones in registration_view - adds test to check for username validation Ref: #71
- Loading branch information
1 parent
98c0d64
commit d891ee9
Showing
7 changed files
with
132 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from unittest import mock | ||
from django.test import TestCase | ||
from django.core.exceptions import ValidationError | ||
from django.contrib.auth import get_user_model | ||
|
||
User = get_user_model() | ||
|
||
class TapirUserTests(TestCase): | ||
|
||
def setUp(self): | ||
super().setUp() | ||
has_ldap_patch = mock.patch("tapir.accounts.models.LdapUser.has_ldap") | ||
self.has_ldap = has_ldap_patch.start() | ||
|
||
ldap_save_patch = mock.patch("tapir.accounts.models.LdapPerson.save") | ||
self.ldap_save = ldap_save_patch.start() | ||
|
||
self.addCleanup(has_ldap_patch.stop) | ||
self.addCleanup(ldap_save_patch.stop) | ||
|
||
def test_model_validates_usernames(self): | ||
self.has_ldap.return_value = 0 | ||
self.ldap_save.return_value = None | ||
|
||
usernames = [ | ||
"asd$", | ||
] | ||
for username in usernames: | ||
try: | ||
User.objects.create_user(username=username) | ||
except ValidationError: | ||
continue | ||
self.fail(f"validation error not raised for username: {username}") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,93 @@ | ||
from io import StringIO | ||
from unittest import mock | ||
from django_webtest import WebTest | ||
from django.contrib.auth import get_user_model | ||
from django.urls import reverse | ||
from django.utils import timezone | ||
from django.core.management import call_command | ||
from tapir.wirgarten.models import GrowingPeriod | ||
|
||
User = get_user_model() | ||
|
||
class WizardTests(WebTest): | ||
|
||
def test_bla(self): | ||
a | ||
@classmethod | ||
def setUpTestData(cls): | ||
cls.now = now = timezone.now() | ||
|
||
call_command("parameter_definitions", stdout=StringIO()) | ||
fixtures = [ | ||
"0010_pickup_locations", | ||
"0020_product_types", | ||
"0021_tax_rates", | ||
"0030_products", | ||
"0031_product_prices", | ||
"0040_growing_periods", | ||
"0050_product_capacity", | ||
"0060_pickup_location_capabilities", | ||
] | ||
for fix in fixtures: | ||
call_command("loaddata", f"tapir/wirgarten/fixtures/{fix}", app="wirgarten", stdout=StringIO()) | ||
|
||
GrowingPeriod.objects.create( | ||
start_date=now.replace(year=now.year - 1, month=3, day=1), | ||
end_date=now.replace(year=now.year + 1, month=2, day=28) | ||
) | ||
|
||
@mock.patch('tapir.accounts.models.LdapPerson.save') | ||
@mock.patch('tapir.accounts.models.LdapUser.has_ldap') | ||
def test_simple_signup_flow(self, has_ldap, ldap_save): | ||
has_ldap.return_value = False | ||
ldap_save.return_value = None | ||
|
||
form = self.app.get(reverse('wirgarten:draftuser_register')).form | ||
form["Harvest Shares-harvest_shares_s"] = 1 | ||
r = form.submit() | ||
|
||
form = r.form | ||
form["Cooperative Shares-statute_consent"] = True | ||
r = form.submit() | ||
|
||
form = r.form | ||
r = form.submit() | ||
|
||
form = r.form | ||
r = form.submit() | ||
|
||
form = r.form | ||
r = form.submit() | ||
|
||
form = r.form | ||
r = form.submit() | ||
|
||
form = r.form | ||
form['Personal Details-first_name'] = 'Firstname' | ||
form['Personal Details-last_name'] = 'Lastname' | ||
form['Personal Details-email'] = 'any@mail.com' | ||
form['Personal Details-phone_number'] = '+12125552368' | ||
form['Personal Details-street'] = 'fake street' | ||
form['Personal Details-street_2'] = '' | ||
form['Personal Details-postcode'] = '12345' | ||
form['Personal Details-city'] = 'Berlin' | ||
form['Personal Details-country'] = 'DE' | ||
form['Personal Details-birthdate'] = '' | ||
r = form.submit() | ||
|
||
form = r.form | ||
form['Payment Details-account_owner'] = 'Firstname Lastname' | ||
form['Payment Details-iban'] = 'DE89370400440532013000' | ||
form['Payment Details-bic'] = 'DEUTDE5M' | ||
r = form.submit() | ||
|
||
form = r.form | ||
form['Payment Details-sepa_consent'] = True | ||
r = form.submit() | ||
|
||
form = r.form | ||
form['Consent-withdrawal_consent'] = True | ||
form['Consent-privacy_consent'] = True | ||
r = form.submit().follow() | ||
|
||
user = User.objects.filter(email='any@mail.com').first() | ||
self.assertIsNotNone(user) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -479,7 +479,6 @@ def get_free_product_capacity( | |
), | ||
) | ||
) | ||
|
||
return total_capacity - used_capacity | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters