def test_for_order_by_name(self): response = self.client.get( build_url('v1:products', params={'order_by': 'name'})) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual( ProductsSerializer(Product.objects.order_by('name'), many=True).data, response.data)
def test_create_invalid_category_product(self): response = self.client.post(build_url('v1:products'), data={ 'name': 'Valid Product', 'sub_category': 0 }) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, 'Provide sub category not exists')
def test_create_valid_category_product(self): response = self.client.post(build_url('v1:products'), data={ 'name': 'Valid Product', 'sub_category': self.sub_category_1_category_1.id }) self.assertEqual(response.status_code, status.HTTP_201_CREATED)
def test_for_order_by_sub_category_desc(self): response = self.client.get( build_url('v1:products', params={ 'order_by': 'sub_category', 'order': 'DESC' })) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual( ProductsSerializer(Product.objects.order_by('-sub_category'), many=True).data, response.data)