#9 feat(Tryton): create products from tryton.
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import json
|
||||
from decimal import Decimal
|
||||
from unittest.mock import patch
|
||||
|
||||
from django.test import Client, TestCase
|
||||
from ..models import ProductCategory, Product
|
||||
|
||||
|
||||
class TestProductsFromTryton(TestCase):
|
||||
def setUp(self):
|
||||
self.client = Client()
|
||||
|
||||
@patch('sabatron_tryton_rpc_client.client.Client.call')
|
||||
@patch('sabatron_tryton_rpc_client.client.Client.connect')
|
||||
def test_import_products(self, mock_connect, mock_call):
|
||||
mock_connect.return_value = None
|
||||
|
||||
def fake_call(*args, **kwargs):
|
||||
product_search = 'model.product.product.search'
|
||||
search_args = [[], 0, 1000, [['rec_name', 'ASC'], ['id', None]], {'company': 1}]
|
||||
if (args == (product_search, search_args)):
|
||||
return [190]
|
||||
|
||||
product_read = 'model.product.product.read'
|
||||
product_args = ([190],
|
||||
['id', 'name', 'default_uom.id',
|
||||
'default_uom.rec_name', 'list_price'],
|
||||
{'company': 1}
|
||||
)
|
||||
if (args == (product_read, product_args)):
|
||||
return [{'id': 190, 'list_price': Decimal('25000'),
|
||||
'name': 'Producto 1',
|
||||
'default_uom.': {'id': 1, 'rec_name': 'Unit'}}]
|
||||
|
||||
raise Exception(f"Sorry, args non expected on this test: {args}")
|
||||
|
||||
mock_call.side_effect = fake_call
|
||||
|
||||
url = '/don_confiao/api/importar_productos_de_tryton'
|
||||
response = self.client.post(url)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
content = json.loads(response.content.decode('utf-8'))
|
||||
expected_response = {
|
||||
'checked_tryton_products': [190],
|
||||
'created_products': [1],
|
||||
'untouched_products': [],
|
||||
'failed_products': [],
|
||||
'updated_products': []
|
||||
}
|
||||
self.assertEqual(content, expected_response)
|
||||
|
||||
created_product = Product.objects.get(id=1)
|
||||
self.assertEqual(created_product.external_id, str(190))
|
||||
self.assertEqual(created_product.name, 'Producto 1')
|
||||
self.assertEqual(created_product.price, Decimal('25000'))
|
||||
self.assertEqual(created_product.measuring_unit, 'Unit')
|
||||
Reference in New Issue
Block a user