From a70dc79839b5fff81676eeff17fe2bc347756bde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20=C3=89vrard?= Date: Fri, 3 Jun 2016 17:26:55 +0200 Subject: [PATCH] Disable zeep cache handling when using the test server issue5600 review20231002 --- carrier.py | 9 ++------- configuration.py | 17 +++++++++++++++++ stock.py | 9 ++------- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/carrier.py b/carrier.py index 6b5aed0dbb..6cc912a9c6 100644 --- a/carrier.py +++ b/carrier.py @@ -1,14 +1,11 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from urlparse import urljoin -from zeep import Client from zeep.exceptions import Fault -from trytond.config import config from trytond.model import ModelSQL, ModelView, MatchMixin, fields from trytond.pool import PoolMeta -from .configuration import SERVER_URLS, LOGIN_SERVICE +from .configuration import get_client, LOGIN_SERVICE __all__ = ['CredentialDPD', 'Carrier'] @@ -40,9 +37,7 @@ class CredentialDPD(ModelSQL, ModelView, MatchMixin): return 'testing' def update_token(self): - api_base_url = config.get('stock_package_shipping_dpd', - self.server, default=SERVER_URLS[self.server]) - auth_client = Client(urljoin(api_base_url, LOGIN_SERVICE)) + auth_client = get_client(self.server, LOGIN_SERVICE) lang = (self.company.party.lang.code if self.company.party.lang else 'en_US') try: diff --git a/configuration.py b/configuration.py index 5b50739303..4b4b60dd89 100644 --- a/configuration.py +++ b/configuration.py @@ -1,5 +1,10 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. +from urlparse import urljoin +from zeep import Client +from zeep.transports import Transport + +from trytond.config import config SERVER_URLS = { 'testing': 'https://public-ws-stage.dpd.com/services/', @@ -8,3 +13,15 @@ SERVER_URLS = { LOGIN_SERVICE = 'LoginService/V2_0?wsdl' SHIPMENT_SERVICE = 'ShipmentService/V3_2?wsdl' + + +def get_client(server, service): + api_base_url = config.get('stock_package_shipping_dpd', + server, default=SERVER_URLS[server]) + url = urljoin(api_base_url, service) + # Disable the cache for testing because zeep's bug + # https://github.com/mvantellingen/python-zeep/issues/48 + # which makes testing environments fail + transport = (Transport(cache=None) + if url.startswith(SERVER_URLS['testing']) else None) + return Client(url, transport=transport) diff --git a/stock.py b/stock.py index 4381bb7ebe..9087d06d7e 100644 --- a/stock.py +++ b/stock.py @@ -2,19 +2,16 @@ # this repository contains the full copyright notices and license terms. from io import BytesIO -from urlparse import urljoin from lxml import etree -from zeep import Client from zeep.exceptions import Fault from PyPDF2 import PdfFileReader, PdfFileWriter -from trytond.config import config from trytond.pool import Pool, PoolMeta from trytond.model import fields from trytond.wizard import Wizard, StateAction, StateTransition from trytond.transaction import Transaction -from .configuration import SERVER_URLS, SHIPMENT_SERVICE +from .configuration import get_client, SHIPMENT_SERVICE __all__ = ['ShipmentOut', 'CreateShipping', 'CreateDPDShipping'] @@ -96,9 +93,7 @@ class CreateDPDShipping(Wizard): if not credential.depot or not credential.token: credential.update_token() - api_base_url = config.get('stock_package_shipping_dpd', - credential.server, default=SERVER_URLS[credential.server]) - shipping_client = Client(urljoin(api_base_url, SHIPMENT_SERVICE)) + shipping_client = get_client(credential.server, SHIPMENT_SERVICE) print_options = self.get_print_options(shipment) packages = shipment.root_packages shipment_data = self.get_shipment_data(credential, shipment, packages)