-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/menus
- Loading branch information
Showing
39 changed files
with
1,012 additions
and
321 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 |
---|---|---|
|
@@ -12,3 +12,4 @@ database/ | |
*.css.map | ||
*.js.map | ||
*.log | ||
.coverage |
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
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,19 @@ | ||
#!/usr/bin/env sh | ||
|
||
# Install test related dependencies | ||
pip install coveralls==1.3.0 | ||
apk add git | ||
|
||
# Prep the DB for testing | ||
python manage.py reset_db --noinput | ||
python manage.py migrate | ||
python manage.py test -k | ||
|
||
# Run the tests and create a coverage report | ||
coverage run --omit="*/migrations*,*/fixtures*" manage.py test -k | ||
ret=$? | ||
if [ $ret -ne 0 ]; then | ||
exit 1 | ||
fi | ||
|
||
# Submit coverage to Coveralls | ||
coveralls |
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,11 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 | ||
|
||
from .serializers import UserSerializer | ||
|
||
|
||
def handler(token, user=None, request=None): | ||
return { | ||
'token': token, | ||
'id': UserSerializer(user, context={'request': request}).data.get('id') | ||
} |
This file was deleted.
Oops, something went wrong.
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,2 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 |
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 was deleted.
Oops, something went wrong.
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,2 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 |
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,76 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 | ||
|
||
from django.contrib.auth.models import AnonymousUser, User | ||
from django.test import TestCase, RequestFactory | ||
from v1.common.permissions import IsAdminOrReadOnly, IsOwnerOrReadOnly | ||
|
||
|
||
class PermissionTest(TestCase): | ||
def setUp(self): | ||
# Every test needs access to the request factory. | ||
self.factory = RequestFactory() | ||
# Create a staff user. | ||
self.user = User.objects.create_user( | ||
username='jacob', email='jacob@gmail.com', password='top_secret', is_staff=True | ||
) | ||
|
||
def test_is_owner_or_read_only(self): | ||
# Try and access something as an admin user. | ||
# Both get and post should have access. | ||
request = self.factory.get('/admin') | ||
request.user = self.user | ||
self.assertTrue( | ||
IsOwnerOrReadOnly().has_permission(request, None) | ||
) | ||
self.assertTrue( | ||
IsOwnerOrReadOnly().has_object_permission(request, None, None) | ||
) | ||
request = self.factory.post('/admin') | ||
request.user = self.user | ||
self.assertTrue( | ||
IsOwnerOrReadOnly().has_permission(request, None) | ||
) | ||
|
||
# Try and access something as an anonymous user. | ||
# Both get should have access but post shouldn't. | ||
request = self.factory.get('/admin') | ||
request.user = AnonymousUser() | ||
self.assertTrue( | ||
IsOwnerOrReadOnly().has_permission(request, None) | ||
) | ||
self.assertTrue( | ||
IsOwnerOrReadOnly().has_object_permission(request, None, None) | ||
) | ||
request = self.factory.post('/admin') | ||
request.user = AnonymousUser() | ||
self.assertFalse( | ||
IsOwnerOrReadOnly().has_permission(request, None) | ||
) | ||
|
||
def test_is_admin_or_read_only(self): | ||
# Try and access something as an admin user. | ||
# Both get and post should have access. | ||
request = self.factory.get('/admin') | ||
request.user = self.user | ||
self.assertTrue( | ||
IsAdminOrReadOnly().has_permission(request, None) | ||
) | ||
request = self.factory.post('/admin') | ||
request.user = self.user | ||
self.assertTrue( | ||
IsAdminOrReadOnly().has_permission(request, None) | ||
) | ||
|
||
# Try and access something as an anonymous user. | ||
# Both get should have access but post shouldn't. | ||
request = self.factory.get('/admin') | ||
request.user = AnonymousUser() | ||
self.assertTrue( | ||
IsAdminOrReadOnly().has_permission(request, None) | ||
) | ||
request = self.factory.post('/admin') | ||
request.user = AnonymousUser() | ||
self.assertFalse( | ||
IsAdminOrReadOnly().has_permission(request, None) | ||
) |
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,36 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 | ||
|
||
from django.test import TestCase | ||
from v1.recipe.models import Recipe | ||
from v1.common.recipe_search import get_search_results | ||
|
||
|
||
class GetSearchResultsTests(TestCase): | ||
fixtures = [ | ||
'test/users.json', | ||
'course_data.json', | ||
'cuisine_data.json', | ||
'recipe_data.json', | ||
'ing_data.json' | ||
] | ||
|
||
def test_get_search_results(self): | ||
""" Run a search that will return data """ | ||
query = get_search_results( | ||
['title', 'ingredient_groups__ingredients__title', 'tags__title'], | ||
Recipe.objects, | ||
'chili' | ||
).distinct() | ||
|
||
self.assertTrue(len(query.all()) > 0) | ||
|
||
def test_get_search_no_results(self): | ||
""" Run a search that will return no data """ | ||
query = get_search_results( | ||
['title', 'ingredient_groups__ingredients__title', 'tags__title'], | ||
Recipe.objects, | ||
'blue berry' | ||
).distinct() | ||
|
||
self.assertTrue(len(query.all()) == 0) |
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
Oops, something went wrong.