forked from RyanNoelk/OpenEats
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Shows filter totals in browse sidebar (RyanNoelk#137)
* Rather than matching cuisine and course filters by title we're matching them by slug, which will be url-safer. * No point in having a `?format=json` when we can just use the application type header
- Loading branch information
Showing
12 changed files
with
344 additions
and
63 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,35 @@ | ||
[ | ||
{ | ||
"pk": 1, | ||
"model": "recipe_groups.course", | ||
"fields": { | ||
"title": "Course 1", | ||
"slug": "course-1", | ||
"author": "1" | ||
} | ||
},{ | ||
"pk": 2, | ||
"model": "recipe_groups.course", | ||
"fields": { | ||
"title": "Course 2", | ||
"slug": "course-2", | ||
"author": "1" | ||
} | ||
},{ | ||
"pk": 3, | ||
"model": "recipe_groups.course", | ||
"fields": { | ||
"title": "Course 3", | ||
"slug": "course-3", | ||
"author": "1" | ||
} | ||
},{ | ||
"pk": 4, | ||
"model": "recipe_groups.course", | ||
"fields": { | ||
"title": "Course 4", | ||
"slug": "course-4", | ||
"author": "1" | ||
} | ||
} | ||
] |
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,35 @@ | ||
[ | ||
{ | ||
"pk": 1, | ||
"model": "recipe_groups.cuisine", | ||
"fields": { | ||
"title": "Cuisine 1", | ||
"slug": "cuisine-1", | ||
"author": "1" | ||
} | ||
},{ | ||
"pk": 2, | ||
"model": "recipe_groups.cuisine", | ||
"fields": { | ||
"title": "Cuisine 2", | ||
"slug": "cuisine-2", | ||
"author": "1" | ||
} | ||
},{ | ||
"pk": 3, | ||
"model": "recipe_groups.cuisine", | ||
"fields": { | ||
"title": "Cuisine 3", | ||
"slug": "cuisine-3", | ||
"author": "1" | ||
} | ||
},{ | ||
"pk": 4, | ||
"model": "recipe_groups.cuisine", | ||
"fields": { | ||
"title": "Cuisine 4", | ||
"slug": "cuisine-4", | ||
"author": "1" | ||
} | ||
} | ||
] |
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,104 @@ | ||
[ | ||
{ | ||
"pk": 1, | ||
"model": "recipe.recipe", | ||
"fields": { | ||
"title": "Recipe 1", | ||
"slug": "recipe-1", | ||
"author": "1", | ||
"cuisine": "1", | ||
"course": "1", | ||
"info": "Recipe info", | ||
"prep_time": "1", | ||
"cook_time": "1", | ||
"servings": "1", | ||
"pub_date": "2017-01-01 00:00:00", | ||
"update_date": "2017-01-01 00:00:00" | ||
} | ||
}, | ||
{ | ||
"pk": 2, | ||
"model": "recipe.recipe", | ||
"fields": { | ||
"title": "Recipe 2", | ||
"slug": "recipe-2", | ||
"author": "1", | ||
"cuisine": "1", | ||
"course": "2", | ||
"info": "Recipe info", | ||
"prep_time": "1", | ||
"cook_time": "1", | ||
"servings": "1", | ||
"pub_date": "2017-01-01 00:00:00", | ||
"update_date": "2017-01-01 00:00:00" | ||
} | ||
}, | ||
{ | ||
"pk": 3, | ||
"model": "recipe.recipe", | ||
"fields": { | ||
"title": "Recipe 3", | ||
"slug": "recipe-3", | ||
"author": "1", | ||
"cuisine": "2", | ||
"course": "1", | ||
"info": "Recipe info", | ||
"prep_time": "1", | ||
"cook_time": "1", | ||
"servings": "1", | ||
"pub_date": "2017-01-01 00:00:00", | ||
"update_date": "2017-01-01 00:00:00" | ||
} | ||
}, | ||
{ | ||
"pk": 4, | ||
"model": "recipe.recipe", | ||
"fields": { | ||
"title": "Recipe 4", | ||
"slug": "recipe-4", | ||
"author": "1", | ||
"cuisine": "1", | ||
"course": "3", | ||
"info": "Recipe info", | ||
"prep_time": "1", | ||
"cook_time": "1", | ||
"servings": "1", | ||
"pub_date": "2017-01-01 00:00:00", | ||
"update_date": "2017-01-01 00:00:00" | ||
} | ||
}, | ||
{ | ||
"pk": 5, | ||
"model": "recipe.recipe", | ||
"fields": { | ||
"title": "Recipe 5", | ||
"slug": "recipe-5", | ||
"author": "1", | ||
"cuisine": "2", | ||
"course": "2", | ||
"info": "Recipe info", | ||
"prep_time": "1", | ||
"cook_time": "1", | ||
"servings": "1", | ||
"pub_date": "2017-01-01 00:00:00", | ||
"update_date": "2017-01-01 00:00:00" | ||
} | ||
}, | ||
{ | ||
"pk": 6, | ||
"model": "recipe.recipe", | ||
"fields": { | ||
"title": "Recipe 6", | ||
"slug": "recipe-6", | ||
"author": "1", | ||
"cuisine": "3", | ||
"course": "1", | ||
"info": "Recipe info", | ||
"prep_time": "1", | ||
"cook_time": "1", | ||
"servings": "1", | ||
"pub_date": "2017-01-01 00:00:00", | ||
"update_date": "2017-01-01 00:00:00" | ||
} | ||
} | ||
] |
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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 | ||
from __future__ import unicode_literals | ||
from django.test import TestCase | ||
from rest_framework.test import APIRequestFactory | ||
from v1.recipe_groups import views | ||
|
||
class RecipeGroupsTests(TestCase): | ||
fixtures = ['test/users.json', 'test/cuisine.json', 'test/course.json', 'test/recipes.json'] | ||
|
||
def setUp(self): | ||
self.factory = APIRequestFactory() | ||
|
||
def test_cuisine_all(self): | ||
view = views.CuisineViewSet.as_view({'get': 'list'}) | ||
request = self.factory.get('/api/v1/recipe_groups/cuisine/') | ||
response = view(request) | ||
|
||
self.assertEqual(response.data.get('count'), 4) | ||
|
||
results = response.data.get('results') | ||
totals = {"cuisine-1": 3, "cuisine-2": 2, "cuisine-3": 1, "cuisine-4": 0} | ||
|
||
for item in results: | ||
self.assertEquals(totals[item.get('slug')], item.get('total')) | ||
|
||
def test_course_all(self): | ||
view = views.CourseViewSet.as_view({'get': 'list'}) | ||
request = self.factory.get('/api/v1/recipe_groups/course/') | ||
response = view(request) | ||
|
||
self.assertEqual(response.data.get('count'), 4) | ||
|
||
results = response.data.get('results') | ||
totals = {"course-1": 3, "course-2": 2, "course-3": 1, "course-4": 0} | ||
|
||
for item in results: | ||
self.assertEquals(totals[item.get('slug')], item.get('total')) | ||
|
||
def test_cuisine_with_course_filter(self): | ||
view = views.CuisineViewSet.as_view({'get': 'list'}) | ||
request = self.factory.get('/api/v1/recipe_groups/cuisine/?course=course-1') | ||
response = view(request) | ||
|
||
self.assertEqual(response.data.get('count'), 3) | ||
|
||
results = response.data.get('results') | ||
totals = {"cuisine-1": 1, "cuisine-2": 1, "cuisine-3": 1} | ||
|
||
for item in results: | ||
self.assertEquals(totals[item.get('slug')], item.get('total')) | ||
|
||
def test_cuisine_with_course_filter_no_results(self): | ||
view = views.CuisineViewSet.as_view({'get': 'list'}) | ||
request = self.factory.get('/api/v1/recipe_groups/cuisine/?course=course-4') | ||
response = view(request) | ||
|
||
self.assertEqual(response.data.get('count'), 0) | ||
|
||
def test_course_with_cuisine_filter(self): | ||
view = views.CourseViewSet.as_view({'get': 'list'}) | ||
request = self.factory.get('/api/v1/recipe_groups/course/?cuisine=cuisine-1') | ||
response = view(request) | ||
|
||
self.assertEqual(response.data.get('count'), 3) | ||
|
||
results = response.data.get('results') | ||
totals = {"course-1": 1, "course-2": 1, "course-3": 1} | ||
|
||
for item in results: | ||
self.assertEquals(totals[item.get('slug')], item.get('total')) | ||
|
||
def test_cuisine_with_course_filter_no_results(self): | ||
view = views.CourseViewSet.as_view({'get': 'list'}) | ||
request = self.factory.get('/api/v1/recipe_groups/course/?cuisine=cuisine-4') | ||
response = view(request) | ||
|
||
self.assertEqual(response.data.get('count'), 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
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.