File: configuration.py

package info (click to toggle)
tryton-modules-stock-package-shipping-dpd 5.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 336 kB
  • sloc: python: 409; xml: 80; makefile: 6; sh: 3
file content (27 lines) | stat: -rw-r--r-- 988 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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 urllib.parse 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/',
    'production': 'https://public-ws.dpd.com/services/',
    }

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)