feat(api): implemented create sale as api endpoint.
This commit is contained in:
32
tienda_ilusion/don_confiao/tests/test_api.py
Normal file
32
tienda_ilusion/don_confiao/tests/test_api.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import json
|
||||
from django.urls import reverse
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APITestCase
|
||||
from ..models import Sale, Product, Customer
|
||||
|
||||
|
||||
class TestAPI(APITestCase):
|
||||
def setUp(self):
|
||||
self.product = Product.objects.create(
|
||||
name='Panela',
|
||||
price=5000,
|
||||
measuring_unit='UNIT'
|
||||
)
|
||||
self.customer = Customer.objects.create(
|
||||
name='Camilo'
|
||||
)
|
||||
|
||||
def test_create_sale(self):
|
||||
url = '/don_confiao/api/sales/'
|
||||
data = {
|
||||
'customer': self.customer.id,
|
||||
'date': '2024-09-02',
|
||||
'lines': [
|
||||
{'product': self.product.id, 'quantity': 2, 'unit_price': 3000},
|
||||
{'product': self.product.id, 'quantity': 3, 'unit_price': 5000}
|
||||
],
|
||||
}
|
||||
response = self.client.post(url, data, format='json')
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
self.assertEqual(Sale.objects.count(), 1)
|
||||
self.assertEqual(Sale.objects.all()[0].customer.name, self.customer.name)
|
||||
Reference in New Issue
Block a user