Skip to content

Commit

Permalink
fixing test cases for create and update
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanNoelk committed Apr 6, 2018
1 parent d11987b commit ff58bb0
Show file tree
Hide file tree
Showing 2 changed files with 366 additions and 15 deletions.
126 changes: 119 additions & 7 deletions v1/recipe/tests/test_create_recipe.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,147 @@
#!/usr/bin/env python
# encoding: utf-8

import json
from django.test import TestCase
from django.contrib.auth.models import User
from rest_framework.test import APIRequestFactory
from v1.recipe import views


class RecipeSerializerTests(TestCase):
fixtures = [
'test/users.json',
'course_data.json',
'cuisine_data.json',
]

def setUp(self):
self.factory = APIRequestFactory()
self.staff = User.objects.create_user(
username='staff', email='staff@gmail.com', password='top_secret', is_superuser=True
)

def test_simple_create_recipe(self):
"""Test to make sure we have the right fields"""
view = views.RecipeViewSet.as_view({'post': 'create'})
request = self.factory.get('/api/v1/recipe/recipes/')
request.data = {
"id": 1,
"ingredients": [],
data = {
"ingredient_groups": [
{
"id": 3,
"title": "",
"ingredients": []
},
{
"id": 4,
"title": "Veges",
"ingredients": [
{
"id": 13,
"numerator": 1.0,
"denominator": 2.0,
"measurement": "dash",
"title": "black pepper"
},
{
"id": 14,
"numerator": 4.0,
"denominator": 1.0,
"measurement": "tablespoons",
"title": "chili powder"
},
{
"id": 15,
"numerator": 1.0,
"denominator": 1.0,
"measurement": "tablespoon",
"title": "cumin"
},
{
"id": 16,
"numerator": 1.0,
"denominator": 1.0,
"measurement": "can",
"title": "dark kidney beans"
},
{
"id": 17,
"numerator": 2.0,
"denominator": 1.0,
"measurement": "cans",
"title": "diced tomatos"
},
{
"id": 18,
"numerator": 1.0,
"denominator": 1.0,
"measurement": "whole",
"title": "green bell pepper"
},
{
"id": 19,
"numerator": 1.0,
"denominator": 1.0,
"measurement": "can",
"title": "light kidney beans"
},
{
"id": 20,
"numerator": 1.0,
"denominator": 1.0,
"measurement": "whole",
"title": "serrano pepper"
},
{
"id": 21,
"numerator": 1.0,
"denominator": 1.0,
"measurement": "whole",
"title": "white onion"
}
]
},
{
"id": 5,
"title": "Beef",
"ingredients": [
{
"id": 22,
"numerator": 1.0,
"denominator": 1.0,
"measurement": "pound",
"title": "ground pork"
},
{
"id": 23,
"numerator": 1.0,
"denominator": 1.0,
"measurement": "pound",
"title": "ground sirloin"
},
{
"id": 24,
"numerator": 1.0,
"denominator": 1.0,
"measurement": "dash",
"title": "kosher salt"
}
]
}
],
"directions": '',
"tags": [],
"tags": ['hi', 'hello'],
"title": "Recipe name",
"info": "Recipe info",
"source": "",
"source": "google.com",
"prep_time": 60,
"cook_time": 60,
"servings": 8,
"rating": 0,
"author": 1,
"cuisine": 1,
"course": 2
}
request = self.factory.post('/api/v1/recipe/recipes/', data=data)
request.user = self.staff
response = view(request)

self.assertTrue(response.data.get('id', True))
Loading

0 comments on commit ff58bb0

Please sign in to comment.