Skip to content

Commit

Permalink
Merge pull request #133 from akretion/update-setup-changelog
Browse files Browse the repository at this point in the history
Update setup changelog
  • Loading branch information
florian-dacosta authored Dec 10, 2020
2 parents 30aa4b4 + 28ec1d2 commit 853546e
Show file tree
Hide file tree
Showing 28 changed files with 158 additions and 103 deletions.
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# black roulier
c8f96f37968d26aacbc36f8f09616ff683a89392
b2064d9d658b385bfd46ef136da186522107f575
47 changes: 35 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,40 @@
language: python
cache:
directories:
- $HOME/.cache/pip
- $HOME/.cache/pre-commit
python:
- "3.6"
install:
- pip install -r requirements.txt
- pip install pytest
script:
- pytest -s roulier/carriers/laposte_fr
deploy:
provider: pypi
user: hparfr
password:
secure: go1MWqMNj5t21FWbZWlSvZsMYiAAJkgO8aeQRMCIv5ZQN8LGCE3nUQxjx1REY768lD9uMD6QgrXchxWWoWk+4B95cEjVOfi+CcINwOT9i3tvQoixwWhK/d4kgUmYggjCR1yOgGR75wc5CrAE5wghg36vnLAxJxxXR1mP5/L2Cz/0qSLUp7MEEal7j+Yo8Hx2o6/lBBHSjKXQugK5FlmOvyfJHHTARU4puSQdyBc/GfgKE6Uxt5vihD3lvj8n/HmXLG1nInEd0DKbIZvFc759ZAk3njKxuL1FWycdaSoGc3XVa5b3qFZa5+7LNrFOjldBm0O21MaHGDHgVE8DLs45i/PgC3L3ATSQ7eDx/1ArPazrZCSdn+umJtkxS2Id/KHLF1yDHguXmUtYwDjW4NmUSLAiVInz5Il/bnADFwXnOQ4WLdmU0GMHkWPLd+TJe4iPTj+SagVpUMVxtQXm2RgFhGSo5h8daK5/ZQnu8DEMX4dtdSKGrMF7FJkbBWFzXIMw8mGbIKKoSjw+nYIl72lNgaPorR3l9s6aR/bwHFaxF0sviSwebvNEecLKIP2TZEIU45u6CQEU5iKptCLzznWemA9mvzw/JDiUlehqm5M0cLgYiJf74QJJbrj6eTC1IK9oAo8iCfn3511u19SqPpnV2ovEenPHly1Gni0i/Gv8JQ0=
distributions: sdist bdist_wheel
on:
tags: true
branch: master
- pip install -r requirements-test.txt
stages:
- name: linting
- name: test
- name: deploy
if: tag IS present

jobs:
include:
- stage: linting
name: "pre-commit"
python: 3.6
install: pip install pre-commit
script: pre-commit run --all --show-diff-on-failure
- stage: test
python: 3.6
script: pytest -s roulier/carriers
- stage: deploy
install:
script: echo "Deploy to PyPi"
deploy:
provider: pypi
user: hparfr
password:
secure: go1MWqMNj5t21FWbZWlSvZsMYiAAJkgO8aeQRMCIv5ZQN8LGCE3nUQxjx1REY768lD9uMD6QgrXchxWWoWk+4B95cEjVOfi+CcINwOT9i3tvQoixwWhK/d4kgUmYggjCR1yOgGR75wc5CrAE5wghg36vnLAxJxxXR1mP5/L2Cz/0qSLUp7MEEal7j+Yo8Hx2o6/lBBHSjKXQugK5FlmOvyfJHHTARU4puSQdyBc/GfgKE6Uxt5vihD3lvj8n/HmXLG1nInEd0DKbIZvFc759ZAk3njKxuL1FWycdaSoGc3XVa5b3qFZa5+7LNrFOjldBm0O21MaHGDHgVE8DLs45i/PgC3L3ATSQ7eDx/1ArPazrZCSdn+umJtkxS2Id/KHLF1yDHguXmUtYwDjW4NmUSLAiVInz5Il/bnADFwXnOQ4WLdmU0GMHkWPLd+TJe4iPTj+SagVpUMVxtQXm2RgFhGSo5h8daK5/ZQnu8DEMX4dtdSKGrMF7FJkbBWFzXIMw8mGbIKKoSjw+nYIl72lNgaPorR3l9s6aR/bwHFaxF0sviSwebvNEecLKIP2TZEIU45u6CQEU5iKptCLzznWemA9mvzw/JDiUlehqm5M0cLgYiJf74QJJbrj6eTC1IK9oAo8iCfn3511u19SqPpnV2ovEenPHly1Gni0i/Gv8JQ0=
distributions: "sdist bdist_wheel"
skip_upload_docs: true
on:
repo: akretion/roulier
branch: master
tags: true
15 changes: 10 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@

# Next
- Misc python3 fix
- Remove TRS carrier because aborted project

Roadmap / TODO:

- Add Kuehne & Nagel carrier
- Add UPS carrier
- Add geodis carrier
- Add dpd carrier
- Support test_mode for some carriers
- Improve documentation
- Support additionnal methods of api
- Write tests
- define an output API (tracking)
- generate api documentation

# 1.0.0 2020-12-08
- Refactore library design to be able to re-use some logic between carriers
- Add compatibility with python 3
- Remove compatibility with python 2 (check versions < 1.0.0 for that)
- Adapt laposte and chronopost to python 3
- Add gls France support
- standardize output for all supported carriers

# 0.3.9 2019-09-12
- Improve setup.py

Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ Roulier will get a label + tracking number to your carrier for you.
### Installation

This is not compatible with python 2.7.
Please use the python 2 branch in that case.
This is work in progress.
Please use version < 1.0.0 (python2 branch) in that case.

### Usage

```python
from roulier import roulier

response = laposte.get_label(
payload= {
"auth": {
"login": "12345",
Expand Down
7 changes: 6 additions & 1 deletion roulier/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ def _parcel(self):
"required": True,
"empty": False,
},
# reference of parcel in external app
# This ref should be attached to the label in roulier response so the
# external app is able to link a label file/tracking ref to the corresponding
# parcel.
"reference": {"type": "string"},
}
# 'description': 'Weight in kg',

Expand Down Expand Up @@ -153,7 +158,7 @@ def _auth(self):
return {
"login": {"type": "string", "default": ""},
"password": {"type": "string", "default": ""},
"isTest": {"type": "boolean", "default": False}
"isTest": {"type": "boolean", "default": False},
}

def _schemas(self):
Expand Down
4 changes: 3 additions & 1 deletion roulier/carrier_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ def decoder(self):
def api(self):
pass

ws_test_url = ''
ws_test_url = ""


class CarrierGetLabel(Carrier, ABC):

is_test = False
roulier_input = None

@property
@abstractmethod
Expand All @@ -52,6 +53,7 @@ def get_label(self, carrier_type, action, data):
encoder = self.encoder(self)
decoder = self.decoder(self)
transport = self.transport(self)
self.roulier_input = data

parcels = data.get("parcels", []).copy()
# one call to carrier webservice is enough
Expand Down
14 changes: 5 additions & 9 deletions roulier/carriers/chronopost_fr/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def _service(self):

def _parcel(self):
schema = super(ChronopostFrApiParcel, self)._parcel()
schema["reference"] = {"type": "string", "maxlength": 15}
schema["reference"].update({"maxlength": 15})
schema["objectType"] = {
"type": "string",
"allowed": ["DOC", "MAR"],
Expand All @@ -71,10 +71,7 @@ def _parcel(self):
def _address(self):
schema = super(ChronopostFrApiParcel, self)._address()
additional_fields = {
"civility": {
"type": "string",
"allowed": ["E", "L", "M"],
},
"civility": {"type": "string", "allowed": ["E", "L", "M"],},
"contact_name": {"type": "string", "maxlength": 100},
"preAlert": {"type": "integer"},
}
Expand All @@ -98,10 +95,9 @@ def _from_address(self):
schema = super(ChronopostFrApiParcel, self)._from_address()
schema["preAlert"].update({"allowed": [0, 11]})
# strangely, civility seem really mandatory for shipper
schema['civility'].update({
"required": True,
"empty": False,
})
schema["civility"].update(
{"required": True, "empty": False,}
)
return schema

def _auth(self):
Expand Down
2 changes: 1 addition & 1 deletion roulier/carriers/chronopost_fr/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def decode(self, response, input_payload):
output_format = input_payload["output_format"]
parcel = {
"id": 1, # no multi parcel management for now.
"reference": "",
"reference": self._get_parcel_number(input_payload),
"tracking": {"number": tracking_ref, "url": ""},
"label": {
"data": data,
Expand Down
2 changes: 1 addition & 1 deletion roulier/carriers/geodis/geodis_transport_rest_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def send_request(self, body, infos):
"""Send body to geodis WS."""
ws_url = infos["url"]
token = infos["token"]
return requests.post(ws_url, headers={"X-GEODIS-Service": token,}, data=body)
return requests.post(ws_url, headers={"X-GEODIS-Service": token,}, data=body,)

def handle_500(self, response):
"""Handle reponse in case of ERROR 500 type."""
Expand Down
2 changes: 1 addition & 1 deletion roulier/carriers/geodis/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from . import test_rest
# from . import test_rest
File renamed without changes.
8 changes: 4 additions & 4 deletions roulier/carriers/gls_fr/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
class GlsDecoder(DecoderGetLabel):
"""Gls weird string -> Python."""

def decode(self, response, inpyt_payload):
def decode(self, response, input_payload):
"""Gls -> Python."""
data = self.exotic_serialization_to_dict(response.get("body"))
self.search_exception(data, inpyt_payload)
self.search_exception(data, input_payload)
data_file = BytesIO(self.populate_label(data).encode())
self.result["parcels"].append(
{
"id": 1, # no multi parcel management for now.
"reference": "",
"reference": self._get_parcel_number(input_payload),
"tracking": {"number": data.get("T8913"), "url": ""},
"label": {
"data": base64.b64encode(data_file.read()),
Expand Down Expand Up @@ -90,7 +90,7 @@ def search_exception(self, data, data_request):
log.warning("Exception according these data:")
detail = """Tag "%s" (%s), value %s""" % (tag, info.get(tag), value)
log.warning(detail)
exception = ("wrong or absent information : %s" % detail)
exception = "wrong or absent information : %s" % detail
if exception:
self.create_exception(result, exception, ctx_except, data_request)
return False
Expand Down
4 changes: 2 additions & 2 deletions roulier/carriers/gls_fr/tests/credential_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

credentials = {
"login": "2509999999",
"customerId": "2588888888",
"agencyId": "2588888888",
"customerId": "2500030002",
"agencyId": "FR0094",
"isTest": True,
}
12 changes: 7 additions & 5 deletions roulier/carriers/gls_fr/tests/test_roulier_gls_fr.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from datetime import date
from roulier.carriers.gls_fr.gls import Gls
from roulier import roulier

logger = logging.getLogger(__name__)

Expand All @@ -17,8 +17,9 @@


def test_connexion():
gls = Gls()
gls.get_label(
roulier.get(
"gls_fr",
"get_label",
{
"auth": {"login": credentials["login"], "isTest": credentials["isTest"]},
"service": {
Expand All @@ -27,6 +28,7 @@ def test_connexion():
"shippingDate": date.today(),
"shippingId": "125874",
"intructions": "Sent from automatic test",
"parcel_total_number": 1,
},
"from_address": {
"company": "my company",
Expand All @@ -45,7 +47,7 @@ def test_connexion():
"city": "Paris",
"phone": "01 99 99 99 99",
"email": "[email protected]",
"country_code": "FR",
"country": "FR",
},
"parcels": [
{
Expand All @@ -55,5 +57,5 @@ def test_connexion():
"custom_sequence": "1234567899",
}
],
}
},
)
4 changes: 2 additions & 2 deletions roulier/carriers/laposte_fr/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def _parcel(self):
"default": "",
# 'description': 'Needed for cn23'
}
schema["customs"] = {"type": "dict", "schema": self._customs()}
return schema

def _auth(self):
Expand All @@ -184,11 +185,10 @@ def _customs(self):
},
"default": [],
},
}
},
}
return schema

def _schemas(self):
schemas = super()._schemas()
schemas["customs"] = self._customs()
return schemas
10 changes: 7 additions & 3 deletions roulier/carriers/laposte_fr/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,27 @@ def get_cid(tag, tree):
annexes = []

if cn23_cid:
annexes.append({"name": "cn23", "data": parts.get(cn23_cid), "type": "pdf"})
data = parts.get(cn23_cid)
annexes.append(
{"name": "cn23", "data": base64.b64encode(data), "type": "pdf"}
)

if rep.find("pdfUrl"):
annexes.append({"name": "label", "data": rep.find("pdfUrl"), "type": "url"})

parcel = {
"id": 1, # no multi parcel management for now.
"reference": rep.parcelNumber,
"reference": self._get_parcel_number(input_payload),
"tracking": {
"number": rep.parcelNumber,
"url": "",
"partner": rep.find("parcelNumberPartner"),
},
"label": {
"data": base64.b64encode(parts.get(label_cid).encode()),
"data": base64.b64encode(parts.get(label_cid)),
"name": "label_1",
"type": output_format,
},
}
self.result["parcels"].append(parcel)
self.result["annexes"] += annexes
7 changes: 6 additions & 1 deletion roulier/carriers/laposte_fr/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ def _extra_input_data_processing(self, input_payload, data):
data["service"]["labelFormat"] = self.lookup_label_format(
data["service"]["labelFormat"]
)
# Since multi parcels is not managed for la poste, some informations are expected
# in service by laposte but are in parcel in roulier.
parcel = data["parcels"][0]
if parcel.get("totalAmount"):
data["service"]["totalAmount"] = parcel["totalAmount"]
return data

def transform_input_to_carrier_webservice(self, data):
Expand All @@ -34,7 +39,7 @@ def transform_input_to_carrier_webservice(self, data):
auth=data["auth"],
sender_address=data["from_address"],
receiver_address=data["to_address"],
customs=data["customs"],
customs=data["parcels"][0].get("customs", False),
),
"headers": data["auth"],
"output_format": data["service"]["labelFormat"],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<customsDeclarations>
<includeCustomsDeclarations>{{ (customs.category != '') | lower }}</includeCustomsDeclarations>
{% if customs.category != '' %}
<includeCustomsDeclarations>{{ (customs and customs.category != '') | lower }}</includeCustomsDeclarations>
{% if customs and customs.category != '' %}
<contents>
{% for article in customs.articles %}
<article>
Expand Down
Loading

0 comments on commit 853546e

Please sign in to comment.