Exemplo n.º 1
0
    def setUp(self):
        self.client = Client()

        self.admin_user = create_superuser()
        self.client.force_login(self.admin_user)

        self.user = create_user()
Exemplo n.º 2
0
 def setUp(self):
     self.payload = {
         'email': '*****@*****.**',
         'password': '******',
         'name': 'Name'
     }
     self.user = create_user(**self.payload)
     self.client = APIClient()
     self.client.force_authenticate(user=self.user)
Exemplo n.º 3
0
 def setUp(self):
     self.user = create_user()
     self.client = APIClient()
     self.client.force_authenticate(self.user)
     self.payload = {
         'title': 'Cheese cake',
         'time_minutes': 30,
         'price': 5.00
     }
Exemplo n.º 4
0
    def test_recipes_limited_to_user(self):
        user = create_user(email='*****@*****.**', password='******')
        create_recipe(user=user)
        create_recipe(user=self.user)

        self.assertEqual(Recipe.objects.count(), 2)

        r = self.client.get(RECIPE_LIST_URL)
        self.assertEqual(r.status_code, 200)
        self.assertEqual(len(r.data), 1)
Exemplo n.º 5
0
    def test_tags_limited_to_user(self):
        tag = Tag.objects.create(user=self.user, name='Vegan')

        anonymous_user = create_user(email='*****@*****.**', password='******')
        Tag.objects.create(user=anonymous_user, name='Horse meat')

        self.assertEqual(Tag.objects.count(), 2)

        r = self.client.get(TAG_LIST_URL)
        self.assertEqual(r.status_code, status.HTTP_200_OK)
        self.assertEqual(len(r.data), 1)
        self.assertEqual(r.data[0]['name'], tag.name)
Exemplo n.º 6
0
    def test_list_ingredients_limited_to_user(self):
        ing = Ingredient.objects.create(user=self.user, name='salt')

        anonymous_user = create_user(email='*****@*****.**', password='******')
        Ingredient.objects.create(user=anonymous_user, name='Horse meat')

        self.assertEqual(Ingredient.objects.count(), 2)

        r = self.client.get(INGREDIENT_LIST_URL)
        self.assertEqual(r.status_code, status.HTTP_200_OK)
        self.assertEqual(len(r.data), 1)
        self.assertEqual(r.data[0]['name'], ing.name)
Exemplo n.º 7
0
 def test_tag_str(self):
     tag = Tag.objects.create(user=create_user(), name='Vegan')
     self.assertEqual(str(tag), tag.name)
Exemplo n.º 8
0
 def test_recipe_str(self):
     recipe = Recipe.objects.create(user=create_user(),
                                    title='Baked steak',
                                    time_minutes=5,
                                    price=5.00)
     self.assertEqual(str(recipe), recipe.title)
Exemplo n.º 9
0
 def test_ingredient_str(self):
     ing = Ingredient.objects.create(user=create_user(), name='Potato')
     self.assertEqual(str(ing), ing.name)
Exemplo n.º 10
0
 def test_create_token_invalid_credantials(self):
     create_user(**self.payload)
     self.payload['password'] = '******'
     r = self.client.post(TOKEN_URL, self.payload)
     self.assertNotIn('token', r.data)
     self.assertEqual(r.status_code, status.HTTP_400_BAD_REQUEST)
Exemplo n.º 11
0
 def test_create_token_for_user(self):
     create_user(**self.payload)
     r = self.client.post(TOKEN_URL, self.payload)
     self.assertIn('token', r.data)
     self.assertEqual(r.status_code, status.HTTP_200_OK)
Exemplo n.º 12
0
    def test_user_exists(self):
        """ test creating user that already exists fails """

        create_user(**self.payload)
        r = self.client.post(CREATE_USER_URL, self.payload)
        self.assertEqual(r.status_code, status.HTTP_400_BAD_REQUEST)
Exemplo n.º 13
0
    def setUp(self):
        self.user = create_user()
        self.client = APIClient()
        self.client.force_authenticate(self.user)

        self.payload = {'name': 'Test tag'}
Exemplo n.º 14
0
 def setUp(self):
     self.user = create_user()
     self.client = APIClient()
     self.client.force_authenticate(self.user)
     self.recipe = create_recipe(user=self.user)
     self.url = get_image_upload_url(self.recipe.id)