feat (Tryton): get customers from tryton.
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import json
|
||||
from unittest.mock import patch
|
||||
|
||||
from django.test import Client, TestCase
|
||||
from ..models import Customer
|
||||
|
||||
|
||||
class TestCustomersFromTryton(TestCase):
|
||||
def setUp(self):
|
||||
self.customer = Customer.objects.create(
|
||||
name='Calos',
|
||||
external_id=5
|
||||
)
|
||||
self.customer.save()
|
||||
|
||||
self.customer2 = Customer.objects.create(
|
||||
name='Cristian',
|
||||
external_id=6
|
||||
)
|
||||
self.customer2.save()
|
||||
|
||||
@patch('sabatron_tryton_rpc_client.client.Client.call')
|
||||
@patch('sabatron_tryton_rpc_client.client.Client.connect')
|
||||
def test_create_import_customer(self, mock_connect, mock_call):
|
||||
def fake_call(*args, **kwargs):
|
||||
party_search = 'model.party.party.search'
|
||||
search_args = [[], 0, 1000, [['rec_name', 'ASC'], ['id', None]], {'company': 1}]
|
||||
|
||||
if (args == (party_search, search_args)):
|
||||
return [5, 6, 7, 8]
|
||||
|
||||
party_read = 'model.party.party.read'
|
||||
read_args = ([5, 6, 7, 8], ['id', 'name'], {'company': 1})
|
||||
if (args == (party_read, read_args)):
|
||||
return [
|
||||
{'id': 5, 'name': 'Carlos'},
|
||||
{'id': 6, 'name': 'Cristian'},
|
||||
{'id': 7, 'name': 'Ana'},
|
||||
{'id': 8, 'name': 'José'},
|
||||
]
|
||||
|
||||
raise Exception(f"Sorry, args non expected on this test: {args}")
|
||||
mock_call.side_effect = fake_call
|
||||
|
||||
url = '/don_confiao/api/importar_clientes_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_parties': [5, 6, 7, 8],
|
||||
'created_customers': [3, 4],
|
||||
'untouched_customers': [2],
|
||||
'failed_parties': [],
|
||||
'updated_customers': [1]
|
||||
}
|
||||
self.assertEqual(content, expected_response)
|
||||
|
||||
created_customer = Customer.objects.get(id=3)
|
||||
self.assertEqual(created_customer.external_id, str(7))
|
||||
self.assertEqual(created_customer.name, 'Ana')
|
||||
|
||||
updated_customer = Customer.objects.get(id=1)
|
||||
self.assertEqual(updated_customer.external_id, str(5))
|
||||
self.assertEqual(updated_customer.name, 'Carlos')
|
||||
Reference in New Issue
Block a user