Example #1
0
from django.test import TestCase
from django.contrib.auth.models import User
from recipes.models import Recipe
from ingredients.models import Ingredient
from user.models import UserProfile


# Create your tests here.

class RecipeTestCase(TestCase):
    def setUp(self):
        user = User.objects.create_user('testuser')
<<<<<<< HEAD
        profile = UserProfile.get_or_create_profile(user)
=======
        profile = UserProfile.create_or_get_profile(user)
>>>>>>> dev
        Ingredient.objects.bulk_create([Ingredient(name='Vodka', category='alcohol'),
                                        Ingredient(name='Rum', category='alcohol'),
                                        Ingredient(name='Gin', category='alcohol'),
                                        Ingredient(name='Orange Juice', category='juice'),
                                        Ingredient(name='Pineapple Juice', category='juice'),
                                        Ingredient(name='White Rum', category='alcohol'),
                                        Ingredient(name='Coconut Cream', category='milk')])

        self.vodka_id = Ingredient.objects.get(name='Vodka').id
        self.oj_id = Ingredient.objects.get(name='Orange Juice').id
        self.gin_id = Ingredient.objects.get(name='Gin').id
        self.rum_id = Ingredient.objects.get(name='Rum').id
        self.pineapple_juice_id = Ingredient.objects.get(name='Pineapple Juice').id
        self.white_rum_id = Ingredient.objects.get(name='White Rum').id
Example #2
0
            RecipeIngredients.objects.bulk_create(drink_ingredients)

        create_drink('screwdriver', 120, 40)
        create_drink('gin_and_vodka', 10, 40)

        add_ingredients_to_drink(self.screwdriver, [(Ingredient.objects.get(name='Vodka'), 1),
                                                    (Ingredient.objects.get(name='Orange Juice'), 2)])

        add_ingredients_to_drink(self.gin_and_vodka, [(Ingredient.objects.get(name='Vodka'), 2),
                                                      (Ingredient.objects.get(name='Gin'), 2)])

    def test_create_or_get_profile(self):
<<<<<<< HEAD
        profile = UserProfile.get_or_create_profile(self.user)
=======
        profile = UserProfile.create_or_get_profile(self.user)
>>>>>>> dev
        self.assertEqual(self.profile, profile)
        self.assertEqual('testuser', profile.user.username)
        self.assertEqual('*****@*****.**', profile.user.email)
        self.assertNotEqual('password', profile.user.password)

    def test_set_favorites(self):
        # Test set 1 favorite
<<<<<<< HEAD
        # noinspection PyUnresolvedReferences
=======
>>>>>>> dev
        def set_one_favorite():
            favorites = self.profile.set_favorites(self.screwdriver.id)
            self.assertIn(self.screwdriver, favorites)
Example #3
0
 def get(self,request):
     user = self.request.user
     if (user.is_authenticated()):
         profile = UserProfile.create_or_get_profile(user)