Skip to content

Commit

Permalink
Merge pull request akretion#169 from akretion/ci-github-workflow
Browse files Browse the repository at this point in the history
Move ci from travis to github action
  • Loading branch information
florian-dacosta authored Jul 19, 2023
2 parents 9ec96b2 + 4d11d2d commit 57a5ec9
Show file tree
Hide file tree
Showing 25 changed files with 351 additions and 216 deletions.
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# black roulier
c8f96f37968d26aacbc36f8f09616ff683a89392
b2064d9d658b385bfd46ef136da186522107f575
1d31fdb69211052ee112e65db535df8f364a2e53
52 changes: 52 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: CI

on:
pull_request:
push:
branches:
- "master"
tags:
- "[0-9]+.[0-9]+.[0-9]+"

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: pre-commit/[email protected]
tests:
name: "Python ${{ matrix.python-version }}"
runs-on: "ubuntu-latest"
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11"]
steps:
- uses: "actions/checkout@v3"
- uses: "actions/setup-python@v4"
with:
python-version: "${{ matrix.python-version }}"
- name: "Install dependencies"
run: |
python -m pip install --upgrade vcrpy-unittest
python -m pip install --upgrade virtualenv tox tox-gh-actions
- name: "Run tox targets for ${{ matrix.python-version }}"
run: |
python -m tox
- uses: codecov/codecov-action@v3
deploy:
runs-on: ubuntu-latest
needs:
- pre-commit
- tests
if: startsWith(github.ref, 'refs/tags')
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- name: Build a binary wheel and a source tarball
run: pipx run build
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ default_language_version:
python: python3
repos:
- repo: https://github.com/psf/black
rev: 19.10b0
rev: 22.3.0
hooks:
- id: black
40 changes: 0 additions & 40 deletions .travis.yml

This file was deleted.

44 changes: 36 additions & 8 deletions roulier/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@ def _service(self):
"agencyId": {"default": ""},
"customerId": {"default": ""},
"shippingId": {"default": ""},
"shippingDate": {"type": "date", "required": True, "empty": False,},
"shippingDate": {
"type": "date",
"required": True,
"empty": False,
},
# 'description': 'Additionnal info visible by the client. Example : order number'
"reference1": {"type": "string", "default": ""},
"reference2": {"type": "string", "default": ""},
Expand All @@ -228,15 +232,21 @@ def _schemas(self):
class ApiPackingSlip(BaseApi):
def _packing_slip_number(self):
return {
"schema": {"type": "string", "empty": False,},
"schema": {
"type": "string",
"empty": False,
},
"required": True,
"excludes": "parcels_numbers",
}

def _parcels_numbers(self):
return {
"type": "list",
"schema": {"type": "string", "empty": False,},
"schema": {
"type": "string",
"empty": False,
},
"empty": False,
"required": True,
"excludes": "packing_slip_number",
Expand All @@ -258,33 +268,51 @@ def __init__(self, config_object):

def _parcel_number(self):
return {
"schema": {"type": "string", "empty": False, "default": "",},
"schema": {
"type": "string",
"empty": False,
"default": "",
},
"required": True,
}

def _document_id(self):
return {
"schema": {"type": "string", "empty": False, "default": "",},
"schema": {
"type": "string",
"empty": False,
"default": "",
},
"required": True,
}

def _document_type(self):
return {
"schema": {"type": "string", "empty": False, "default": "",},
"schema": {
"type": "string",
"empty": False,
"default": "",
},
"required": True,
}

def _document_path(self):
return {
"schema": {"type": "string", "empty": False, "default": "",},
"schema": {
"type": "string",
"empty": False,
"default": "",
},
"required": True,
}

def _schemas(self):
schema = {"auth": self._auth(), "service": {}}
if self.current_action == "get_documents":
schema["service"].update(
{"parcel_number": self._parcel_number(),}
{
"parcel_number": self._parcel_number(),
}
)
elif self.current_action == "get_document":
schema["service"].update(
Expand Down
6 changes: 3 additions & 3 deletions roulier/carrier_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ def get_packing_slip(self, carrier_type, action, data):

class CarrierAddressValidation(CarrierWebservice, ABC):
"""
Check if address is valid/known from the carrier and eventually get proposal
if addresses that could match the input
Check if address is valid/known from the carrier and eventually get proposal
if addresses that could match the input
"""

def validate_address(self, carrier_type, action, data):
Expand All @@ -110,7 +110,7 @@ def validate_address(self, carrier_type, action, data):

class CarrierGetEdi(CarrierBase, ABC):
"""
Generate an EDI file.
Generate an EDI file.
"""

@property
Expand Down
10 changes: 8 additions & 2 deletions roulier/carriers/chronopost_fr/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ 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 @@ -96,7 +99,10 @@ def _from_address(self):
schema["preAlert"].update({"allowed": [0, 11]})
# strangely, civility seem really mandatory for shipper
schema["civility"].update(
{"required": True, "empty": False,}
{
"required": True,
"empty": False,
}
)
return schema

Expand Down
10 changes: 9 additions & 1 deletion roulier/carriers/dpd_fr_soap/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@ def handle_500(self, response):
obj = objectify.fromstring(response.content)
error_id = (obj.xpath("//ErrorId") or obj.xpath("//faultcode"))[0]
error_message = (obj.xpath("//ErrorMessage") or obj.xpath("//faultstring"))[0]
raise CarrierError(response, [{"id": error_id, "message": error_message,}])
raise CarrierError(
response,
[
{
"id": error_id,
"message": error_message,
}
],
)

def handle_200(self, response):
"""Handle response type 200 (success)."""
Expand Down
3 changes: 2 additions & 1 deletion roulier/carriers/geodis/geodis_encoder_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def request_impression_etiquette():
def request_find_localite():
return {
"body": template.render(
receiver_address=data["to_address"], xmlns=infos["xmlns"],
receiver_address=data["to_address"],
xmlns=infos["xmlns"],
),
"headers": data["auth"],
"infos": infos,
Expand Down
14 changes: 12 additions & 2 deletions roulier/carriers/geodis_fr/geodis_soap_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ def handle_500(self, response):
and obj.xpath("//*[local-name() = 'code']")[0]
or ""
)
errors = [{"id": id_message, "message": message,}]
errors = [
{
"id": id_message,
"message": message,
}
]
raise CarrierError(response, errors)

def handle_200(self, response):
Expand Down Expand Up @@ -89,5 +94,10 @@ def handle_response(self, response):
else:
raise CarrierError(
response,
[{"id": None, "message": "Unexpected status code from server",}],
[
{
"id": None,
"message": "Unexpected status code from server",
}
],
)
20 changes: 17 additions & 3 deletions roulier/carriers/geodis_fr/geodis_transport_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,22 @@ def send(self, payload):
def send_request(self, body, token):
"""Send body to geodis WS."""
ws_url = self.config.ws_url
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."""
# TODO : put a try catch (like wrong server)
log.warning("Geodis error 500")
errors = [{"id": "", "message": "",}]
errors = [
{
"id": "",
"message": "",
}
]
raise CarrierError(response, errors)

def handle_true_negative_error(self, response, payload):
Expand Down Expand Up @@ -98,5 +107,10 @@ def handle_response(self, response):
else:
raise CarrierError(
response,
[{"id": None, "message": "Unexpected status code from server",}],
[
{
"id": None,
"message": "Unexpected status code from server",
}
],
)
Loading

0 comments on commit 57a5ec9

Please sign in to comment.