-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
605d0ee
commit 33a35a4
Showing
12 changed files
with
2,998 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
908 changes: 908 additions & 0 deletions
908
...r/carriers/mondialrelay_fr/tests/cassettes/test_mondialrelay/test_mondialrelay_label.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
908 changes: 908 additions & 0 deletions
908
...ers/mondialrelay_fr/tests/cassettes/test_mondialrelay/test_mondialrelay_label_return.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
1,047 changes: 1,047 additions & 0 deletions
1,047
...iers/mondialrelay_fr/tests/cassettes/test_mondialrelay/test_mondialrelay_pickup_site.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Copyright 2024 Akretion (http://www.akretion.com). | ||
# @author Florian Mounier <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
|
||
from ....tests.conftest import * # noqa |
72 changes: 72 additions & 0 deletions
72
roulier/carriers/mondialrelay_fr/tests/test_mondialrelay.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Copyright 2024 Akretion (http://www.akretion.com). | ||
# @author Florian Mounier <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
import pytest | ||
from roulier import roulier | ||
from ....helpers import merge | ||
|
||
|
||
@pytest.fixture | ||
def get_label_data(credentials, base_get_label_data): | ||
return merge( | ||
credentials["mondialrelay_fr"], | ||
base_get_label_data, | ||
{ | ||
"service": { | ||
"product": "HOM", | ||
"pickupMode": "REL", | ||
"pickupSite": "AUTO", | ||
"pickupCountry": "FR", | ||
} | ||
}, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def find_pickup_site_data(credentials, base_find_pickup_site_data): | ||
return merge( | ||
credentials["mondialrelay_fr"], | ||
base_find_pickup_site_data, | ||
) | ||
|
||
|
||
@pytest.mark.vcr() | ||
def test_mondialrelay_label(get_label_data): | ||
rv = roulier.get("mondialrelay_fr", "get_label", get_label_data) | ||
assert "parcels" in rv | ||
assert "label" in rv["parcels"][0] | ||
label = rv["parcels"][0]["label"] | ||
assert label["name"] == "label_url" | ||
assert label["type"] == "url" | ||
assert label["data"].startswith("https://www.mondialrelay.com") | ||
|
||
|
||
@pytest.mark.vcr() | ||
def test_mondialrelay_label_return(get_label_data): | ||
rv = roulier.get( | ||
"mondialrelay_fr", | ||
"get_label", | ||
merge( | ||
get_label_data, | ||
{ | ||
"service": { | ||
"product": "LCC", | ||
}, | ||
}, | ||
), | ||
) | ||
assert "parcels" in rv | ||
assert "label" in rv["parcels"][0] | ||
label = rv["parcels"][0]["label"] | ||
assert label["name"] == "label_url" | ||
assert label["type"] == "url" | ||
assert label["data"].startswith("https://www.mondialrelay.com") | ||
|
||
|
||
@pytest.mark.vcr() | ||
def test_mondialrelay_pickup_site(find_pickup_site_data): | ||
rv = roulier.get("mondialrelay_fr", "find_pickup_site", find_pickup_site_data) | ||
assert "sites" in rv | ||
assert len(rv["sites"]) > 0 | ||
assert "name" in rv["sites"][0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright 2024 Akretion (http://www.akretion.com). | ||
# @author Florian Mounier <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
from base64 import b64decode | ||
|
||
|
||
def assert_data_type(b64_data, expected_type): | ||
data = b64decode(b64_data) | ||
if expected_type == "EPL": # No magic bytes for EPL | ||
assert len(data) > 0, "EPL data should not be empty" | ||
assert b"\r\n" in data | ||
return | ||
|
||
magic_bytes = { | ||
"PDF": b"%PDF-", | ||
"PNG": b"\x89PNG\r\n", | ||
# https://gist.github.com/metafloor/773bc61480d1d05a976184d45099ef56 | ||
"ZPL": b"^XA", | ||
} | ||
if expected_type not in magic_bytes: | ||
raise ValueError(f"Unsupported type: {expected_type}") | ||
|
||
if expected_type == "ZPL": | ||
if data[:3] == b"\xef\xbb\xbf": | ||
# Handle ZPL data that starts with the byte order mark (BOM) | ||
data = data[3:] | ||
if not data.startswith(magic_bytes[expected_type]) and b"\n" in data: | ||
# Try next line | ||
data = data.split(b"\n", 1)[1] | ||
|
||
assert data.startswith(magic_bytes[expected_type]), f"Invalid {expected_type} data" | ||
|
||
|
||
def assert_pdf(b64_data): | ||
assert_data_type(b64_data, "PDF") | ||
|
||
|
||
def assert_zpl(b64_data): | ||
assert_data_type(b64_data, "ZPL") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters