-
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.
Merge pull request #27 from TeoTN/release/2.2.0
v2.2.0
- Loading branch information
Showing
20 changed files
with
420 additions
and
20 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 |
---|---|---|
|
@@ -95,3 +95,4 @@ ENV/ | |
# tfoosball/db.sqlite3 | ||
dump.rdb | ||
|
||
tfoosball/emails.log |
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,6 +1,5 @@ | ||
language: python | ||
python: | ||
- "3.5" | ||
- "3.6" | ||
|
||
env: | ||
|
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 +1,2 @@ | ||
release: python manage.py migrate | ||
web: gunicorn tfoosball.wsgi --log-file - |
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,16 @@ | ||
from django.core.mail import send_mail | ||
|
||
|
||
def send_invitation(email, activation_code): | ||
send_mail( | ||
subject='[Invitation] Rethink the way you play table football!', | ||
message=''' | ||
Hi! | ||
You have been invited to TFoosball. Join us here: https://tfoosball.herokuapp.com/accept/{0}/ | ||
The service is not active yet, thank you for your patience. | ||
'''.format(activation_code), | ||
# html_message='Here is the message.', | ||
from_email='[email protected]', | ||
recipient_list=[email], | ||
fail_silently=False, | ||
) |
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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
from django.test import TestCase | ||
from rest_framework import status | ||
from rest_framework.test import force_authenticate, APIRequestFactory | ||
from api.views import TeamViewSet | ||
from tfoosball.models import Team, Player, Member, PlayerPlaceholder | ||
|
||
factory = APIRequestFactory() | ||
|
||
|
||
class TeamInviteTestCase(TestCase): | ||
fixtures = ['teams.json', 'players.json', 'members.json'] | ||
|
||
def setUp(self): | ||
self.dev_team = Team.objects.get(name='Developer Team') | ||
self.member_player = Player.objects.get(username='pflores6') | ||
self.non_member_player = Player.objects.get(username='phawkins1') | ||
self.url = '/api/teams/{0}/invite/'.format(self.dev_team.pk) | ||
|
||
def test_request_by_non_member(self): | ||
request = factory.post(self.url) | ||
force_authenticate(request, user=self.non_member_player) | ||
view = TeamViewSet.as_view({'post': 'invite'}) | ||
response = view(request, team=self.dev_team.pk) | ||
response.render() | ||
self.assertEqual( | ||
response.status_code, status.HTTP_403_FORBIDDEN, | ||
'expected HTTP 403 when non member sends invitation' | ||
) | ||
|
||
def test_request_with_missing_email(self): | ||
request = factory.post(self.url) | ||
force_authenticate(request, user=self.member_player) | ||
view = TeamViewSet.as_view({'post': 'invite'}) | ||
response = view(request, pk=self.dev_team.pk) | ||
response.render() | ||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, 'expected HTTP 400 on no email') | ||
|
||
def test_invite_already_existing_member(self): | ||
email = '[email protected]' | ||
request = factory.post(self.url, data={'email': email, 'username': 'LFJ'}) | ||
force_authenticate(request, user=self.member_player) | ||
view = TeamViewSet.as_view({'post': 'invite'}) | ||
response = view(request, pk=self.dev_team.pk) | ||
response.render() | ||
self.assertEqual( | ||
response.status_code, status.HTTP_409_CONFLICT, | ||
'expected HTTP 409 when inviting existing member' | ||
) | ||
|
||
def test_invite_existing_player(self): | ||
email = self.non_member_player.email | ||
username = 'PHS' | ||
request = factory.post(self.url, data={'email': email, 'username': username}) | ||
force_authenticate(request, user=self.member_player) | ||
view = TeamViewSet.as_view({'post': 'invite'}) | ||
response = view(request, pk=self.dev_team.pk) | ||
response.render() | ||
member = Member.objects.filter(team=self.dev_team, username=username) | ||
self.assertEqual(member.count(), 1, 'Member should have been created') | ||
self.assertEqual(member[0].player.id, self.non_member_player.id, 'Member should have player assigned') | ||
self.assertNotEqual(member[0].activation_code, '', 'Activation code should be set') | ||
self.assertEqual( | ||
response.status_code, status.HTTP_201_CREATED, | ||
'expected HTTP 201 - Created' | ||
) | ||
|
||
def test_invite_not_existing_player(self): | ||
email = '[email protected]' | ||
username = 'NEX' | ||
request = factory.post(self.url, data={'email': email, 'username': username}) | ||
force_authenticate(request, user=self.member_player) | ||
view = TeamViewSet.as_view({'post': 'invite'}) | ||
response = view(request, pk=self.dev_team.pk) | ||
response.render() | ||
member = Member.objects.filter(team=self.dev_team, username=username) | ||
placeholder = PlayerPlaceholder.objects.filter(member=member, email=email) | ||
self.assertEqual(member.count(), 1, 'Member should have been created') | ||
self.assertTrue(placeholder.exists(), 'Player placeholder should have been created') | ||
self.assertNotEqual(member[0].activation_code, '', 'Activation code should be set') | ||
self.assertEqual( | ||
response.status_code, status.HTTP_201_CREATED, | ||
'expected HTTP 201 - Created' | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
python-3.5.2 | ||
python-3.6.2 |
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,20 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.10.5 on 2017-06-28 14:43 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('tfoosball', '0028_auto_20170423_1833'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='member', | ||
name='activation_code', | ||
field=models.CharField(default='', max_length=28), | ||
), | ||
] |
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,20 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.10.5 on 2017-06-28 14:53 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('tfoosball', '0029_member_activation_code'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='member', | ||
name='activation_code', | ||
field=models.CharField(default='', max_length=40), | ||
), | ||
] |
Oops, something went wrong.