-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from pinax/add-form-test
Fix `render_to_string()` kwarg
- Loading branch information
Showing
7 changed files
with
87 additions
and
18 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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
from django.contrib.auth.models import User | ||
from django.core.management import call_command | ||
from django.test import TestCase | ||
|
||
from account.models import SignupCode | ||
from pinax.invitations.forms import InviteForm | ||
from pinax.invitations.models import InvitationStat, JoinInvitation | ||
from test_plus.test import TestCase | ||
|
||
|
||
class TestsJoinInvitation(TestCase): | ||
|
@@ -51,3 +52,47 @@ def test_add_invites(self): | |
call_command("add_invites", "10") | ||
istat = InvitationStat.objects.get(user=user) | ||
self.assertEqual(istat.invites_remaining(), 20) | ||
|
||
|
||
class FormTests(TestCase): | ||
|
||
def test_already_invited(self): | ||
"""Ensure form is not valid if invite has already been sent""" | ||
from_user = User.objects.create(username="eldarion") | ||
to_user = User.objects.create(username="invitee", email="[email protected]") | ||
InvitationStat.add_invites(2) | ||
istat = from_user.invitationstat | ||
istat.refresh_from_db() | ||
|
||
# Create an existing invitation | ||
JoinInvitation.invite(from_user, to_user.email, send=False) | ||
|
||
# Attempt to invite same user again | ||
form_data = { | ||
"email_address": to_user.email | ||
} | ||
form = InviteForm(user=from_user, data=form_data) | ||
self.assertFalse(form.is_valid()) | ||
|
||
|
||
class ViewTests(TestCase): | ||
|
||
def test_invite_view(self): | ||
"""verify no errors when posting good form data""" | ||
user = self.make_user("amy") | ||
InvitationStat.add_invites(2) | ||
post_data = { | ||
"email_address": "[email protected]" | ||
} | ||
with self.login(user): | ||
self.post("pinax_invitations:invite", data=post_data) | ||
self.response_200() | ||
|
||
def test_invite_view_bad_data(self): | ||
"""verify no errors when posting bad data""" | ||
user = self.make_user("sandee") | ||
post_data = { | ||
} | ||
with self.login(user): | ||
self.post("pinax_invitations:invite", data=post_data) | ||
self.response_200() |
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,5 +1,6 @@ | ||
from django.conf.urls import include, url | ||
|
||
urlpatterns = [ | ||
url(r"^account", include("account.urls")), | ||
url(r"^", include("pinax.invitations.urls", namespace="pinax_invitations")), | ||
] |
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
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