Exemplo n.º 1
0
    def test_delete(self):
        restaurant: Restaurant = RestaurantFactory()
        url = reverse('api:restaurant:edit-delete',
                      kwargs={'pk': restaurant.id})
        response = self.client.delete(url)
        self.assertEqual(response.status_code, 204, response.content)

        with self.assertRaises(Restaurant.DoesNotExist):
            restaurant.refresh_from_db()
Exemplo n.º 2
0
 def test_rate(self):
     restaurant: Restaurant = RestaurantFactory(rating=0)
     url = reverse('api:restaurant:rate', kwargs={'pk': restaurant.id})
     new_rating = 5
     self.assertEqual(restaurant.rating, 0)
     response = self.client.post(url, {'rating': new_rating})
     self.assertEqual(response.status_code, 201, response.content)
     data = response.json()
     self.assertEqual(data['rating'], new_rating)
     restaurant.refresh_from_db()
     self.assertEqual(restaurant.rating, new_rating)
Exemplo n.º 3
0
    def test_edit_partial(self):
        restaurant: Restaurant = RestaurantFactory()
        url = reverse('api:restaurant:edit-delete',
                      kwargs={'pk': restaurant.id})
        new_name = restaurant.name + ' (new)'
        response = self.client.patch(url, {'name': new_name},
                                     'application/json')
        self.assertEqual(response.status_code, 200, response.content)
        data = response.json()

        self.assertEqual(data['name'], new_name)
        restaurant.refresh_from_db()
        self.assertEqual(restaurant.name, new_name)
Exemplo n.º 4
0
    def test_details(self):
        restaurant: Restaurant = RestaurantFactory()
        url = reverse('api:restaurant:edit-delete',
                      kwargs={'pk': restaurant.id})
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200, response.content)
        data = response.json()

        self.assertEqual(data['name'], restaurant.name)
        self.assertEqual(data['food_types'],
                         list(restaurant.food_types.values('id', 'name')))
        self.assertEqual(data['address'], restaurant.address)
        self.assertEqual(data['rating'], restaurant.rating)
Exemplo n.º 5
0
    def test_edit(self):
        restaurant: Restaurant = RestaurantFactory()
        url = reverse('api:restaurant:edit-delete',
                      kwargs={'pk': restaurant.id})
        new_name = restaurant.name + ' (new)'
        response = self.client.put(
            url, {
                'name': new_name,
                'food_types': [ft.id for ft in restaurant.food_types.all()],
                'address': restaurant.address,
                'rating': restaurant.rating,
            }, 'application/json')
        self.assertEqual(response.status_code, 200, response.content)
        data = response.json()

        self.assertEqual(data['name'], new_name)
        restaurant.refresh_from_db()
        self.assertEqual(restaurant.name, new_name)