Skip to content

Commit

Permalink
Add view tests
Browse files Browse the repository at this point in the history
Fix `render_to_string()` kwarg.
Add django-test-plus for testing
Update version
  • Loading branch information
grahamu committed Jan 26, 2018
1 parent 5c2efe7 commit e691f28
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 16 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ Fragment displays how many invites a particular user has.

## Change Log

### 6.1.2

* Replace deprecated `context_instance=RequestContext(r)` kwarg with `request=r`
* Add InviteView smoke tests

### 6.1.1

* Add django>=1.11 to requirements
Expand Down
25 changes: 24 additions & 1 deletion pinax/invitations/tests/tests.py
Original file line number Diff line number Diff line change
@@ -1,10 +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):
Expand Down Expand Up @@ -73,3 +73,26 @@ def test_already_invited(self):
}
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()
1 change: 1 addition & 0 deletions pinax/invitations/tests/urls.py
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")),
]
6 changes: 3 additions & 3 deletions pinax/invitations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ def get_data(self, form):
self.invite_form_fragment, {
"form": form,
"user": self.request.user
}, context_instance=RequestContext(self.request)
}, request=self.request
),
"fragments": {
self.invites_remaining_fragment_selector: render_to_string(
self.invites_remaining_fragment, {
"invites_remaining": self.request.user.invitationstat.invites_remaining()
}, context_instance=RequestContext(self.request)
}, request=self.request
),
self.invited_fragment_selector: render_to_string(
self.invited_fragment, {
"invited_list": self.request.user.invites_sent.all()
}, context_instance=RequestContext(self.request)
}, request=self.request
)
}
}
Expand Down
22 changes: 20 additions & 2 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@

from django.conf import settings


DEFAULT_SETTINGS = dict(
INSTALLED_APPS=[
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.sites",
"account",
"bootstrapform",
"pinax.invitations",
"pinax.invitations.tests"
"pinax.invitations.tests",
"pinax.templates",
],
MIDDLEWARE=[
"django.contrib.sessions.middleware.SessionMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
],
DATABASES={
"default": {
Expand All @@ -25,6 +31,18 @@
SITE_ID=1,
ROOT_URLCONF="pinax.invitations.tests.urls",
SECRET_KEY="notasecret",
TEMPLATES=[
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"APP_DIRS": True,
"OPTIONS": {
"debug": True,
"context_processors": [
"django.contrib.auth.context_processors.auth",
]
}
},
],
)


Expand Down
20 changes: 11 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import find_packages, setup

VERSION = "6.1.1"
VERSION = "6.1.2"
LONG_DESCRIPTION = """
.. image:: http://pinaxproject.com/pinax-design/patches/pinax-invitations.svg
:target: https://pypi.python.org/pypi/pinax-invitations/
Expand Down Expand Up @@ -61,14 +61,6 @@
package_data={
"invitations": []
},
install_requires=[
"django>=1.11",
"django-appconf>=1.0.1",
"django-user-accounts>=2.0.3",
],
test_suite="runtests.runtests",
tests_require=[
],
classifiers=[
"Development Status :: 5 - Production/Stable",
"Environment :: Web Environment",
Expand All @@ -87,5 +79,15 @@
'Programming Language :: Python :: 3.6',
"Topic :: Software Development :: Libraries :: Python Modules",
],
install_requires=[
"django>=1.11",
"django-appconf>=1.0.1",
"django-user-accounts>=2.0.3",
],
test_suite="runtests.runtests",
tests_require=[
"django-test-plus",
"pinax-templates>=1.0.2",
],
zip_safe=False,
)
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ inline-quotes = double
[isort]
multi_line_output=3
known_django=django
known_third_party=account,appconf,pinax
known_third_party=account,appconf,pinax,test_plus
sections=FUTURE,STDLIB,DJANGO,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
include_trailing_comma=True
skip_glob=**/*/migrations/*
Expand Down

0 comments on commit e691f28

Please sign in to comment.