-
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.
* adding tests and adding timezones to fixtures * adding more tests * moving tests to a tests folder * refactoring the way tests are stored * adding some more asserts * adding tests for permissions * testing delete method * remove debug * rename tests * adding test for field limiter * adding some crud test cases for recipes * adding a test for filtering * fixing test cases for create and update * adding file creation * fixing tests * use django unit test class * adding some comments to teh login test cases * adding some comments to teh common test cases * removing un-needed fixtures
- Loading branch information
Showing
22 changed files
with
876 additions
and
261 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 |
---|---|---|
@@ -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
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='[email protected]', 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.