#9 feat(Tryton): enviar_ventas_a_tryton
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import csv
|
||||
import json
|
||||
from unittest.mock import patch
|
||||
|
||||
from django.test import TestCase, Client
|
||||
from django.urls import reverse
|
||||
@@ -10,10 +12,13 @@ class TestExportarVentasParaTryton(TestCase):
|
||||
self.product = Product.objects.create(
|
||||
name='Panela',
|
||||
price=5000,
|
||||
measuring_unit='UNIT'
|
||||
measuring_unit='UNIT',
|
||||
unit_external_id=1,
|
||||
external_id=1
|
||||
)
|
||||
self.customer = Customer.objects.create(
|
||||
name='Camilo'
|
||||
name='Camilo',
|
||||
external_id=1
|
||||
)
|
||||
self.sale = Sale.objects.create(
|
||||
customer=self.customer,
|
||||
@@ -71,3 +76,27 @@ class TestExportarVentasParaTryton(TestCase):
|
||||
csv_rows = list(csv_reader)
|
||||
self.assertEqual(csv_rows[0], expected_rows[0])
|
||||
self.assertEqual(csv_rows[1], expected_rows[1])
|
||||
|
||||
@patch('sabatron_tryton_rpc_client.client.Client.call')
|
||||
@patch('sabatron_tryton_rpc_client.client.Client.connect')
|
||||
def test_send_sales_to_tryton(self, mock_connect, mock_call):
|
||||
client = Client()
|
||||
external_id = '23423'
|
||||
url = '/don_confiao/api/enviar_ventas_a_tryton'
|
||||
mock_connect.return_value = None
|
||||
mock_call.return_value = [external_id]
|
||||
response = client.post(url)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
content = json.loads(response.content.decode('utf-8'))
|
||||
expected_response = {
|
||||
'successful': [self.sale.id],
|
||||
'failed': [],
|
||||
}
|
||||
self.assertEqual(content, expected_response)
|
||||
|
||||
updated_sale = Sale.objects.get(id=self.sale.id)
|
||||
self.assertEqual(updated_sale.external_id, external_id)
|
||||
mock_connect.assert_called_once()
|
||||
mock_call.assert_called_once()
|
||||
mock_call.assert_called_with('model.sale.sale.create', [[{'company': 1, 'currency': 1, 'description': '', 'party': '1', 'reference': 'don_confiao 1', 'sale_date': {'__class__': 'date', 'year': 2024, 'month': 9, 'day': 2}, 'lines': [['create', [{'product': '1', 'quantity': {'__class__': 'Decimal', 'decimal': '2.00'}, 'type': 'line', 'unit': '1', 'unit_price': {'__class__': 'Decimal', 'decimal': '3000.00'}}, {'product': '1', 'quantity': {'__class__': 'Decimal', 'decimal': '3.00'}, 'type': 'line', 'unit': '1', 'unit_price': {'__class__': 'Decimal', 'decimal': '5000.00'}}]]]}], {}])
|
||||
|
||||
Reference in New Issue
Block a user