Skip to content

Commit

Permalink
seperated out settings
Browse files Browse the repository at this point in the history
  • Loading branch information
bee-keeper committed Dec 6, 2015
1 parent b025501 commit 00a9d9e
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ env:
- TOX_ENV=py34-django17
- TOX_ENV=py34-django18
- TOX_ENV=py34-django19
- TOX_ENV=flake8
- TOX_ENV=allauth
- TOX_ENV=flake8
matrix:
include:
- python: "3.5"
Expand Down
2 changes: 1 addition & 1 deletion invitations/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from django.utils.encoding import force_unicode as force_text

from .app_settings import app_settings
from .utils import import_attribute


class BaseInvitationsAdapter(object):
Expand Down Expand Up @@ -112,6 +113,5 @@ def get_invitations_adapter():
from allauth.account.adapter import get_adapter
return get_adapter()
else:
from .utils import import_attribute
# load an adapter from elsewhere
return import_attribute(app_settings.ADAPTER)()
1 change: 0 additions & 1 deletion invitations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def __str__(self):

# here for backwards compatibility, historic allauth adapter
if hasattr(settings, 'ACCOUNT_ADAPTER'):

if settings.ACCOUNT_ADAPTER == 'invitations.models.InvitationsAdapter':
from allauth.account.adapter import DefaultAccountAdapter

Expand Down
Empty file added invitations/tests/__init__.py
Empty file.
Empty file.
78 changes: 78 additions & 0 deletions invitations/tests/allauth/test_allauth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
from django.test import TestCase
from django.contrib.auth import get_user_model
from django.core.urlresolvers import reverse
from django.test.client import RequestFactory
from django.test.utils import override_settings

from nose_parameterized import parameterized
from allauth.account.models import EmailAddress

from invitations.models import Invitation, InvitationsAdapter
from invitations.adapters import get_invitations_adapter


class AllAuthIntegrationTests(TestCase):

@classmethod
def setUpClass(cls):
cls.user = get_user_model().objects.create_user(
username='flibble',
password='password')
cls.invitation = Invitation.create(
'email@example.com', inviter=cls.user)
cls.adapter = get_invitations_adapter()

@classmethod
def tearDownClass(cls):
get_user_model().objects.all().delete()
Invitation.objects.all().delete()

@parameterized.expand([
('get'),
('post'),
])
def test_accept_invite_allauth(self, method):
client_with_method = getattr(self.client, method)
resp = client_with_method(
reverse('invitations:accept-invite',
kwargs={'key': self.invitation.key}), follow=True)
invite = Invitation.objects.get(email='email@example.com')
self.assertTrue(invite.accepted)
self.assertEqual(invite.inviter, self.user)
self.assertEqual(
resp.request['PATH_INFO'], reverse('account_signup'))

form = resp.context_data['form']
self.assertEqual('email@example.com', form.fields['email'].initial)
messages = resp.context['messages']
message_text = [message.message for message in messages]
self.assertEqual(
message_text, [
'Invitation to - email@example.com - has been accepted'])

resp = self.client.post(
reverse('account_signup'),
{'email': 'email@example.com',
'username': 'username',
'password1': 'password',
'password2': 'password'
})

allauth_email_obj = EmailAddress.objects.get(
email='email@example.com')
self.assertTrue(allauth_email_obj.verified)

def test_fetch_adapter(self):
self.assertIsInstance(self.adapter, InvitationsAdapter)

@override_settings(
INVITATIONS_INVITATION_ONLY=True,
)
def test_allauth_adapter_invitations_only(self):
signup_request = RequestFactory().get(reverse(
'account_signup', urlconf='allauth.account.urls'))
self.assertFalse(
self.adapter.is_open_for_signup(signup_request))
response = self.client.get(
reverse('account_signup'))
self.assertIn('Sign Up Closed', response.content.decode('utf8'))
Empty file.
78 changes: 8 additions & 70 deletions invitations/tests.py → invitations/tests/basic/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
from django.contrib.auth import get_user_model
from django.core import mail
from django.contrib.auth.models import AnonymousUser
from django.conf import settings

from freezegun import freeze_time
from nose_parameterized import parameterized

from .adapters import get_invitations_adapter, BaseInvitationsAdapter
from .models import Invitation
from .app_settings import app_settings
from .views import AcceptInvite, SendJSONInvite
from .forms import InviteForm
from invitations.adapters import (
get_invitations_adapter, BaseInvitationsAdapter)
from invitations.models import Invitation
from invitations.app_settings import app_settings
from invitations.views import AcceptInvite, SendJSONInvite
from invitations.forms import InviteForm


class InvitationModelTests(TestCase):
Expand Down Expand Up @@ -63,24 +63,7 @@ def tearDownClass(cls):
del cls.adapter

def test_fetch_adapter(self):
if hasattr(settings, 'ACCOUNT_ADAPTER'):
from .models import InvitationsAdapter
self.assertIsInstance(self.adapter, InvitationsAdapter)
else:
self.assertIsInstance(self.adapter, BaseInvitationsAdapter)

@override_settings(
INVITATIONS_INVITATION_ONLY=True,
)
def test_allauth_adapter_invitations_only(self):
if hasattr(settings, 'ACCOUNT_ADAPTER'):
signup_request = RequestFactory().get(reverse(
'account_signup', urlconf='allauth.account.urls'))
self.assertFalse(
self.adapter.is_open_for_signup(signup_request))
response = self.client.get(
reverse('account_signup'))
self.assertIn('Sign Up Closed', response.content.decode('utf8'))
self.assertIsInstance(self.adapter, BaseInvitationsAdapter)


class InvitationsSendViewTests(TestCase):
Expand All @@ -106,13 +89,7 @@ def test_auth(self):
reverse('invitations:send-invite'), {'email': 'valid@example.com'},
follow=True)

if hasattr(settings, 'ACCOUNT_ADAPTER'):
self.assertEqual(response.status_code, 200)
self.assertEqual(response.template_name, ['account/login.html'])

else:
self.assertEqual(response.status_code, 404)
self.assertEqual(response.request['PATH_INFO'], '/accounts/login/')
self.assertEqual(response.status_code, 404)

@parameterized.expand([
('invalid@example', 'Enter a valid email address'),
Expand Down Expand Up @@ -202,45 +179,6 @@ def test_accept_invite_vanilla(self, method):
self.assertEqual(
resp.request['PATH_INFO'], '/non-existent-url/')

@parameterized.expand([
('get'),
('post'),
])
def test_accept_invite_allauth(self, method):
if hasattr(settings, 'ACCOUNT_ADAPTER'):
# allauth specific
from allauth.account.models import EmailAddress

client_with_method = getattr(self.client, method)
resp = client_with_method(
reverse('invitations:accept-invite',
kwargs={'key': self.invitation.key}), follow=True)
invite = Invitation.objects.get(email='email@example.com')
self.assertTrue(invite.accepted)
self.assertEqual(invite.inviter, self.user)
self.assertEqual(
resp.request['PATH_INFO'], reverse('account_signup'))

form = resp.context_data['form']
self.assertEqual('email@example.com', form.fields['email'].initial)
messages = resp.context['messages']
message_text = [message.message for message in messages]
self.assertEqual(
message_text, [
'Invitation to - email@example.com - has been accepted'])

resp = self.client.post(
reverse('account_signup'),
{'email': 'email@example.com',
'username': 'username',
'password1': 'password',
'password2': 'password'
})

allauth_email_obj = EmailAddress.objects.get(
email='email@example.com')
self.assertTrue(allauth_email_obj.verified)

@override_settings(
INVITATIONS_SIGNUP_REDIRECT='/non-existent-url/'
)
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ deps =

commands =
python -V
coverage run manage.py test
coverage run manage.py test invitations/tests/basic
coverage report

[testenv:allauth]
Expand All @@ -25,7 +25,7 @@ deps =

commands =
python -V
coverage run manage.py test --settings=test_allauth_settings
coverage run manage.py test invitations/tests/allauth --settings=test_allauth_settings
coverage report

[testenv:flake8]
Expand Down

0 comments on commit 00a9d9e

Please sign in to comment.