Skip to content

Commit

Permalink
(consolidate) Colissimo integration with unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danh91 committed Nov 5, 2023
1 parent 29df3d4 commit 5461b26
Show file tree
Hide file tree
Showing 25 changed files with 3,722 additions and 337 deletions.
8 changes: 0 additions & 8 deletions modules/connections/colissimo/_tests/colissimo/fixture.py

This file was deleted.

213 changes: 0 additions & 213 deletions modules/connections/colissimo/_tests/colissimo/test_shipment.py

This file was deleted.

2 changes: 1 addition & 1 deletion modules/connections/colissimo/generate
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ quicktype () {
echo "Generating $1..."
docker run -it -v $PWD:/app -e SCHEMAS=/app/schemas -e LIB_MODULES=/app/karrio/schemas/colissimo \
karrio/tools /quicktype/script/quicktype --no-uuids --no-date-times --no-enums --src-lang json --lang jstruct \
--no-nice-property-names --all-properties-optional --type-as-suffix $@
--no-nice-property-names --all-properties-optional $@
}

quicktype --src="${SCHEMAS}/error_response.json" --out="${LIB_MODULES}/error_response.py"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import karrio.lib as lib
import karrio.api.proxy as proxy
import karrio.providers.colissimo.utils as provider_utils
import karrio.mappers.colissimo.settings as provider_settings
import karrio.universal.mappers.rating_proxy as rating_proxy

Expand All @@ -18,10 +19,10 @@ def create_shipment(self, request: lib.Serializable) -> lib.Deserializable[str]:
data=request.serialize(),
trace=self.trace_as("json"),
method="POST",
headers={"Content-Type": "application/json"},
headers={"Content-Type": "application/json;charset=UTF-8"},
)

return lib.Deserializable(response, lib.to_dict)
return lib.Deserializable(response, provider_utils.parse_response, request.ctx)

def get_tracking(self, request: lib.Serializable) -> lib.Deserializable[str]:
idships = ",".join(request.serialize())
Expand Down
36 changes: 32 additions & 4 deletions modules/connections/colissimo/karrio/providers/colissimo/error.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

import karrio.schemas.colissimo.error_response as laposte
import typing
import karrio.lib as lib
import karrio.core.models as models
Expand All @@ -10,14 +10,42 @@ def parse_error_response(
settings: provider_utils.Settings,
**kwargs,
) -> typing.List[models.Message]:
errors = [] # compute the carrier error object list
messages = response.get("json_info", {}).get("messages", [])

return [
models.Message(
carrier_id=settings.carrier_id,
carrier_name=settings.carrier_name,
code=msg.get("type"),
message=msg.get("messageContent"),
details={**kwargs},
)
for msg in messages
if msg.get("type") == "ERROR"
]


def parse_laposte_error_response(
response: typing.Union[dict, typing.List[dict]],
settings: provider_utils.Settings,
**kwargs,
) -> typing.List[models.Message]:
responses = response if isinstance(response, list) else [response]
errors = [
lib.to_object(laposte.ErrorResponse, res)
for res in responses
if (
not str(res.get("returnCode")).startswith("20")
or res.get("code") is not None
)
]

return [
models.Message(
carrier_id=settings.carrier_id,
carrier_name=settings.carrier_name,
code="", # set the carrier error code
message="", # set the carrier error message
code=(error.returnCode or error.code),
message=(error.returnMessage or error.message),
details={**kwargs},
)
for error in errors
Expand Down
Loading

0 comments on commit 5461b26

Please sign in to comment.