-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
80ab4f8
commit 883b695
Showing
4 changed files
with
76 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,25 @@ | ||
from django import forms | ||
|
||
from core.models import FinetoothUser | ||
|
||
class CommentForm(forms.Form): | ||
content = forms.CharField( | ||
label="", widget=forms.Textarea(attrs={'rows': 6}) | ||
) | ||
|
||
class SignupForm(forms.Form): | ||
username = forms.CharField(label="username") | ||
password = forms.CharField(widget=forms.PasswordInput()) | ||
confirm_password = forms.CharField(widget=forms.PasswordInput()) | ||
email = forms.CharField() | ||
class SignupForm(forms.ModelForm): | ||
class Meta: | ||
model = FinetoothUser | ||
fields = ('username', 'email') | ||
|
||
password = forms.CharField(widget=forms.PasswordInput) | ||
confirm_password = forms.CharField(widget=forms.PasswordInput) | ||
|
||
def clean_confirm_password(self): | ||
password = self.cleaned_data.get('password') | ||
confirm_password = self.cleaned_data.get('confirm_password') | ||
if password != confirm_password: | ||
raise forms.ValidationError( | ||
"Password confirmation didn't match." | ||
) | ||
return password |
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 |
---|---|---|
|
@@ -15,34 +15,56 @@ class SignupTest(TestCase): | |
def test_can_sign_up(self): | ||
response = self.client.post( | ||
reverse('sign_up'), | ||
{'username': "signup_testr", 'password': "moeDukr(,rpdCesLlrqr", | ||
'confirm_password': "moeDukr(,rpdCesLlrqr", 'email': "[email protected]"} | ||
) | ||
# XX: The call to assertRedirects was printing an empty | ||
# dictionary to standard out (if someone accidentally left a | ||
# debugging print statement in Django core (?!), I couldn't | ||
# find it) | ||
with open(os.devnull, 'w') as dev_null: | ||
original_stdout = sys.stdout | ||
sys.stdout = dev_null | ||
self.assertRedirects(response, '/') | ||
sys.stdout = original_stdout | ||
self.assertTrue( | ||
FinetoothUser.objects.filter(username="signup_testr").exists() | ||
) | ||
|
||
@skip("an apparently spurious TransactionManagementError due to the issue " | ||
"described at http://stackoverflow.com/a/23326971") # TODO FIXME | ||
{'username': "signup_testr", | ||
'password': "moeDukr(,rpdCesLlrq", | ||
'confirm_password': "moeDukr(,rpdCesLlrq", | ||
'email': "[email protected]"} | ||
) | ||
self.assertRedirects(response, '/') | ||
user_queryset = FinetoothUser.objects.filter(username="signup_testr") | ||
self.assertTrue(user_queryset.exists()) | ||
self.assertTrue(user_queryset[0].check_password("moeDukr(,rpdCesLlrq")) | ||
|
||
def test_cannnot_claim_extant_username(self): | ||
f.FinetoothUserFactory.create(username="username_squatter") | ||
response = self.client.post( | ||
reverse('sign_up'), | ||
{'username': "username_squatter", 'password': "oclxJums^whyysmtam", | ||
{'username': "username_squatter", | ||
'password': "oclxJums^whyysmtam", | ||
'confirm_password': "oclxJums^whyysmtam", | ||
'email': "[email protected]"}, | ||
follow=True | ||
) | ||
self.assertIn(b"Username already exists.", response.content) | ||
|
||
def test_confirm_password_must_match(self): | ||
prior_user_count = FinetoothUser.objects.count() | ||
response = self.client.post( | ||
reverse('sign_up'), | ||
{'username': "pentest", | ||
'password': "*sd6f3mjdrt3y42", | ||
'confirm_password': "not_the_same_password_is_it", | ||
'email': "[email protected]"}, | ||
follow=True | ||
) | ||
post_user_count = FinetoothUser.objects.count() | ||
self.assertEqual(prior_user_count, post_user_count) | ||
self.assertEqual(422, response.status_code) | ||
|
||
def test_required_fields(self): | ||
prior_user_count = FinetoothUser.objects.count() | ||
response = self.client.post( | ||
reverse('sign_up'), | ||
{'username': '', | ||
'password': "oclxJums^whyysmtam", | ||
'confirm_password': "oclxJums^whyysmtam", | ||
'email': ''}, | ||
follow=True | ||
) | ||
post_user_count = FinetoothUser.objects.count() | ||
self.assertEqual(prior_user_count, post_user_count) | ||
self.assertEqual(422, response.status_code) | ||
|
||
|
||
class TaggingTest(TestCase): | ||
|
||
|
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