Exemple #1
0
    def test_should_raise_if_dish_name_already_exist(self):
        self.authenticate_and_add_modify_permissions()
        dish = DishFactory()
        dish1 = DishFactory()
        payload = {
            'name': dish1.name
        }
        path = reverse('dish-manage-detail', args=[dish.id])

        response = self.client.patch(path, payload)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(response.json(), {'name': ['dish with this name already exists.']})
Exemple #2
0
    def test_should_edit_dish(self):
        self.authenticate_and_add_modify_permissions()
        dish = DishFactory()
        payload = {
            'price': '22.34',
        }
        path = reverse('dish-manage-detail', args=[dish.id])

        response = self.client.patch(path, payload)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        dish.refresh_from_db()
        self.assertEqual(str(dish.price), payload['price'])
Exemple #3
0
    def test_should_upload_a_picture(self):
        self.authenticate_and_add_modify_permissions()
        dish = DishFactory()
        payload = {
            'picture': File(open(self.picture_path, 'rb'))
        }
        path = reverse('dish-manage-picture', args=[dish.id])

        response = self.client.put(path, payload)

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
        dish.refresh_from_db()
        self.assertEqual(dish.picture.read(), open(self.picture_path, 'rb').read())
Exemple #4
0
    def test_should_delete_menu_with_all_dishes(self):
        self.authenticate_and_add_modify_permissions()
        menu = MenuFactory()
        DishFactory(menu=menu)
        path = reverse('menu-manage-detail', args=[menu.id])

        response = self.client.delete(path)

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
        self.assertEqual(Menu.objects.count(), 0)
        self.assertEqual(Dish.objects.count(), 0)
Exemple #5
0
    def test_should_remove_picture(self):
        self.authenticate_and_add_modify_permissions()
        dish = DishFactory()
        dish.picture = File(open(self.picture_path, 'rb'))
        dish.save()
        path = reverse('dish-manage-picture', args=[dish.id])

        response = self.client.delete(path)

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
        dish.refresh_from_db()
        self.assertFalse(dish.picture)
Exemple #6
0
    def test_should_raise_if_price_out_of_range(self):
        self.authenticate_and_add_modify_permissions()
        dish = DishFactory()
        payload = {
            'price': '334.444'
        }
        path = reverse('dish-manage-detail', args=[dish.id])

        response = self.client.patch(path, payload)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(
            response.json(),
            {'price': ['Ensure that there are no more than 4 digits in total.']}
        )
Exemple #7
0
    def test_should_raise_if_wrong_picture_format(self):
        self.authenticate_and_add_modify_permissions()
        wrong_picture = BytesIO(b'somebytes')
        payload = {
            'picture': File(wrong_picture)
        }
        dish = DishFactory()
        path = reverse('dish-manage-picture', args=[dish.id])

        response = self.client.put(path, data=payload)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(
            response.json(),
            {'picture': ['Upload a valid image. The file you uploaded was either not an image or a corrupted image.']}
        )
Exemple #8
0
    def test_should_raise_if_wrong_format_of_prepare_time(self):
        self.authenticate_and_add_modify_permissions()
        dish = DishFactory()
        payload = {
            'prepare_time': '30m'
        }
        path = reverse('dish-manage-detail', args=[dish.id])

        response = self.client.patch(path, payload)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(
            response.json(),
            {'prepare_time': [
                'Duration has wrong format. Use one of these formats instead: [DD] [HH:[MM:]]ss[.uuuuuu].'
            ]}
        )
Exemple #9
0
 def create_menus():
     MenuFactory()
     menus = MenuFactory.create_batch(3)
     for menu in menus:
         DishFactory.create_batch(3, menu=menu)