Skip to content

Commit 5a40c51

Browse files
committed
chore: improve enum typing for lang and language configs for connectors and handle default values for carrier registration modal
1 parent f7c1be3 commit 5a40c51

17 files changed

Lines changed: 69 additions & 38 deletions

File tree

‎modules/connectors/canadapost/karrio/mappers/canadapost/settings.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
"""Karrio Canada post client settings."""
22

33
import attr
4-
from karrio.providers.canadapost import Settings as BaseSettings
4+
import karrio.lib as lib
5+
import karrio.providers.canadapost.utils as utils
56

67

78
@attr.s(auto_attribs=True)
8-
class Settings(BaseSettings):
9+
class Settings(utils.Settings):
910
"""Canada post connection settings."""
1011

1112
username: str
1213
password: str
1314
customer_number: str = None
1415
contract_id: str = None
15-
language: str = "en"
16+
language: utils.LanguageEnum = "en" # type: ignore
1617

1718
id: str = None
1819
test_mode: bool = False

‎modules/connectors/canadapost/karrio/providers/canadapost/utils.py‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@
55
import karrio.core.settings as settings
66

77

8+
LanguageEnum = lib.units.create_enum("LanguageEnum", ["en", "fr"])
9+
10+
811
class Settings(settings.Settings):
912
"""Canada post connection settings."""
1013

1114
username: str
1215
password: str
1316
customer_number: str
1417
contract_id: str = None
15-
language: str = "en"
16-
17-
id: str = None
18-
account_country_code: str = "CA"
19-
metadata: dict = {}
18+
language: LanguageEnum = "en" # type: ignore
2019

2120
@property
2221
def carrier_name(self):

‎modules/connectors/canpar/karrio/mappers/canpar/settings.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
"""Karrio Canpar client settings."""
22

33
import attr
4-
from karrio.providers.canpar import Settings as BaseSettings
4+
import karrio.providers.canpar.utils as utils
55

66

77
@attr.s(auto_attribs=True)
8-
class Settings(BaseSettings):
8+
class Settings(utils.Settings):
99
"""Canpar connection settings."""
1010

1111
username: str
1212
password: str
13-
language: str = "en"
13+
language: utils.LanguageEnum = "en" # type: ignore
1414

1515
id: str = None
1616
test_mode: bool = False

‎modules/connectors/canpar/karrio/providers/canpar/utils.py‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
"""Karrio Canpar client settings."""
22

3+
import karrio.lib as lib
34
from karrio.core.settings import Settings as BaseSettings
45
from karrio.core.utils import Envelope, apply_namespaceprefix, XP, Header
56

7+
LanguageEnum = lib.units.create_enum("LanguageEnum", ["en", "fr"])
8+
69

710
class Settings(BaseSettings):
811
"""Canpar connection settings."""
912

1013
username: str
1114
password: str
12-
language: str = "en"
15+
language: LanguageEnum = "en" # type: ignore
1316

14-
id: str = None
1517
account_country_code: str = "CA"
16-
metadata: dict = {}
1718

1819
@property
1920
def carrier_name(self):
@@ -29,7 +30,9 @@ def server_url(self):
2930

3031
@property
3132
def tracking_url(self):
32-
return "https://www.canpar.com/" + self.language + "/tracking/track.htm?barcode={}"
33+
return (
34+
"https://www.canpar.com/" + self.language + "/tracking/track.htm?barcode={}"
35+
)
3336

3437
@staticmethod
3538
def serialize(

‎modules/connectors/chronopost/karrio/mappers/chronopost/settings.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
"""Karrio Chronopost client settings."""
22

33
import attr
4-
from karrio.providers.chronopost.utils import Settings as BaseSettings
4+
from karrio.providers.chronopost import utils
55

66

77
@attr.s(auto_attribs=True)
8-
class Settings(BaseSettings):
8+
class Settings(utils.Settings):
99
"""Chronopost connection settings."""
1010

1111
account_number: str # type: ignore
1212
password: str # type: ignore
1313
id_emit: str = "CHRFR" # type: ignore
14-
language: str = "en_GB"
14+
language: utils.LanguageEnum = "en_GB" # type: ignore
1515

1616
id: str = None
1717
test_mode: bool = False

‎modules/connectors/chronopost/karrio/providers/chronopost/utils.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
"""Karrio Chronopost client settings."""
22

3+
import karrio.lib as lib
34
from karrio.schemas.chronopost.shippingservice import headerValue
45
from karrio.core.settings import Settings as BaseSettings
56

67

8+
LanguageEnum = lib.units.create_enum("LanguageEnum", ["en_GB", "fr_FR"])
9+
10+
711
class Settings(BaseSettings):
812
"""Chronopost connection settings."""
913

1014
account_number: str
1115
password: str
1216
id_emit: str = "CHRFR"
13-
language: str = "en_GB"
17+
language: LanguageEnum = "en_GB" # type: ignore
1418

1519
account_country_code: str = "FR"
1620
metadata: dict = {}

‎modules/connectors/dhl_universal/karrio/mappers/dhl_universal/settings.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
"""Karrio DHL Universal settings."""
22

33
import attr
4-
from karrio.providers.dhl_universal.utils import Settings as BaseSettings
4+
import karrio.providers.dhl_universal.utils as utils
55

66

77
@attr.s(auto_attribs=True)
8-
class Settings(BaseSettings):
8+
class Settings(utils.Settings):
99
"""DHL Universal connection settings."""
1010

1111
# Carrier specific properties
1212
consumer_key: str
1313
consumer_secret: str
14-
language: str = "en"
14+
language: utils.LanguageEnum = "en" # type: ignore
1515

1616
# Base properties
1717
id: str = None

‎modules/connectors/dhl_universal/karrio/providers/dhl_universal/utils.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
import karrio.lib as lib
12
from karrio.core import Settings as BaseSettings
23

4+
LanguageEnum = lib.units.create_enum("LanguageEnum", ["en", "de"])
5+
36

47
class Settings(BaseSettings):
58
"""DHL Universal connection settings."""
69

710
# Carrier specific properties
811
consumer_key: str
912
consumer_secret: str
10-
language: str = "en"
13+
language: LanguageEnum = "en" # type: ignore
1114

1215
account_country_code: str = "DE"
1316
metadata: dict = {}

‎modules/connectors/geodis/karrio/mappers/geodis/settings.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Settings(provider_utils.Settings):
1616
api_key: str
1717
identifier: str
1818
code_client: str = None
19-
language: str = "fr"
19+
language: provider_utils.LanguageEnum = "fr" # type: ignore
2020

2121
# generic properties
2222
id: str = None

‎modules/connectors/geodis/karrio/providers/geodis/utils.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
import karrio.lib as lib
55
import karrio.core as core
66

7+
LanguageEnum = lib.units.create_enum("LanguageEnum", ["fr", "en"])
8+
79

810
class Settings(core.Settings):
911
"""GEODIS connection settings."""
1012

1113
api_key: str
1214
identifier: str
1315
code_client: str = None
14-
language: str = "fr"
16+
language: LanguageEnum = "fr" # type: ignore
1517

1618
account_country_code: str = "FR"
1719
metadata: dict = {}

0 commit comments

Comments
 (0)