def setUp(self): self.client = Client() self.admin_user = create_superuser() self.client.force_login(self.admin_user) self.user = create_user()
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)
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 }
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)
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)
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)
def test_tag_str(self): tag = Tag.objects.create(user=create_user(), name='Vegan') self.assertEqual(str(tag), tag.name)
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)
def test_ingredient_str(self): ing = Ingredient.objects.create(user=create_user(), name='Potato') self.assertEqual(str(ing), ing.name)
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)
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)
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)
def setUp(self): self.user = create_user() self.client = APIClient() self.client.force_authenticate(self.user) self.payload = {'name': 'Test tag'}
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)