mailbox-org-api 2.4__tar.gz → 2.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (21) hide show
  1. {mailbox_org_api-2.4 → mailbox_org_api-2.5}/PKG-INFO +1 -1
  2. {mailbox_org_api-2.4 → mailbox_org_api-2.5}/mailbox_org_api/APIClient.py +18 -13
  3. {mailbox_org_api-2.4 → mailbox_org_api-2.5}/mailbox_org_api.egg-info/PKG-INFO +1 -1
  4. {mailbox_org_api-2.4 → mailbox_org_api-2.5}/pyproject.toml +1 -1
  5. {mailbox_org_api-2.4 → mailbox_org_api-2.5}/setup.py +1 -1
  6. {mailbox_org_api-2.4 → mailbox_org_api-2.5}/tests/TestAPIClient.py +7 -3
  7. {mailbox_org_api-2.4 → mailbox_org_api-2.5}/LICENSE +0 -0
  8. {mailbox_org_api-2.4 → mailbox_org_api-2.5}/README.md +0 -0
  9. {mailbox_org_api-2.4 → mailbox_org_api-2.5}/mailbox_org_api/APIError.py +0 -0
  10. {mailbox_org_api-2.4 → mailbox_org_api-2.5}/mailbox_org_api/Account.py +0 -0
  11. {mailbox_org_api-2.4 → mailbox_org_api-2.5}/mailbox_org_api/Invoice.py +0 -0
  12. {mailbox_org_api-2.4 → mailbox_org_api-2.5}/mailbox_org_api/Mail.py +0 -0
  13. {mailbox_org_api-2.4 → mailbox_org_api-2.5}/mailbox_org_api/__init__.py +0 -0
  14. {mailbox_org_api-2.4 → mailbox_org_api-2.5}/mailbox_org_api.egg-info/SOURCES.txt +0 -0
  15. {mailbox_org_api-2.4 → mailbox_org_api-2.5}/mailbox_org_api.egg-info/dependency_links.txt +0 -0
  16. {mailbox_org_api-2.4 → mailbox_org_api-2.5}/mailbox_org_api.egg-info/top_level.txt +0 -0
  17. {mailbox_org_api-2.4 → mailbox_org_api-2.5}/setup.cfg +0 -0
  18. {mailbox_org_api-2.4 → mailbox_org_api-2.5}/tests/TestAccount.py +0 -0
  19. {mailbox_org_api-2.4 → mailbox_org_api-2.5}/tests/TestInvoice.py +0 -0
  20. {mailbox_org_api-2.4 → mailbox_org_api-2.5}/tests/TestMail.py +0 -0
  21. {mailbox_org_api-2.4 → mailbox_org_api-2.5}/tests/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mailbox-org-api
3
- Version: 2.4
3
+ Version: 2.5
4
4
  Summary: A library to access the mailbox Business API.
5
5
  Author: Hendrik Schlange
6
6
  Author-email: Hendrik Schlange <mail@heshsum.de>
@@ -24,7 +24,7 @@ class APIClient:
24
24
  Object for API Client
25
25
  """
26
26
 
27
- def __init__(self, debug_output=False, max_retries=5):
27
+ def __init__(self, debug_output=False, max_retries=5, request_timeout: int = 30):
28
28
  # URL of the API
29
29
  self.url = "https://api.mailbox.org/v1/"
30
30
 
@@ -60,6 +60,8 @@ class APIClient:
60
60
  adapter = HTTPAdapter(max_retries=retry_strategy)
61
61
  self.session.mount('https://', adapter)
62
62
 
63
+ self.request_timeout = request_timeout
64
+
63
65
  # Increment the request ID
64
66
  def get_jsonrpc_id(self):
65
67
  """Method to create the JSON RPC request ID. """
@@ -90,20 +92,26 @@ class APIClient:
90
92
  # Check if any parameter is 'password' or 'pass'.
91
93
  # Check explicit for these strings as not to interfere with possible other
92
94
  # parameters containing a substring.
95
+ sensitive_keys = ['password', 'pass', 'password_hash', 'new_account_password', 'token',
96
+ 'HPLS-AUTH', 'auth_id', 'telephone_password']
93
97
  for param in print_request['params']:
94
- if param == 'password' or param == 'pass':
95
- # If True, replace the logged value with 'xxx'
98
+ if param in sensitive_keys:
96
99
  print_request['params'][param] = 'xxx'
97
100
 
98
101
  # Print the clean version of the request
99
102
  print('API full request:\t', print_request)
100
103
 
101
- api_response = self.session.post(self.url, data=json.dumps(request))
102
104
  try:
103
- api_response = api_response.json()
105
+ response = self.session.post(self.url, json=request, timeout=self.request_timeout)
106
+ response.raise_for_status()
104
107
  except RequestException as error:
105
- print('Non-JSON response received.\nFull response:\t', api_response,
106
- '\nError:', {error})
108
+ raise APIError(message=f"HTTP request failed: {error}", code=-32000) from error
109
+
110
+ try:
111
+ api_response = response.json()
112
+ except (ValueError, requests.exceptions.JSONDecodeError) as error:
113
+ print(f'API Full response: {response.content}')
114
+ raise APIError(message="Non-JSON response received from API", code=-32700) from error
107
115
  if self.debug_output:
108
116
  print('API full response:\t', api_response)
109
117
 
@@ -584,7 +592,7 @@ class APIClient:
584
592
  if 'password' in kwargs and 'password_hash' in kwargs:
585
593
  raise KeyError('''Simultaneous usage of 'password' and 'password_hash' not allowed.''')
586
594
 
587
- if 'additional_mail_quota' in kwargs or 'additional_cloud_quota' in kwargs and 'plan' not in kwargs:
595
+ if ('additional_mail_quota' in kwargs or 'additional_cloud_quota' in kwargs) and 'plan' not in kwargs:
588
596
  raise KeyError('''If setting additional quota, 'plan' must be given.''')
589
597
 
590
598
  # Check for each argument in kwargs if it is a valid function parameter.
@@ -1111,16 +1119,13 @@ class APIClient:
1111
1119
  {'delete_mail_accounts_and_domains': delete_mail_accounts_and_domains})
1112
1120
 
1113
1121
 
1114
- def validate_params(allowed: dict, actual: dict) -> bool | None:
1122
+ def validate_params(allowed: dict, actual: dict) -> bool:
1115
1123
  for arg in actual:
1116
1124
  if arg not in allowed:
1117
1125
  raise ValueError(f'Parameter {arg} not a valid parameter.')
1118
-
1119
1126
  if not isinstance(actual[arg], allowed[arg]):
1120
1127
  raise TypeError(f'Attribute {arg} must be of type {str(allowed[arg])}. {str(type(actual[arg]))} given')
1121
- else:
1122
- return True
1123
- return None
1128
+ return True
1124
1129
 
1125
1130
 
1126
1131
  def bool2str(state: bool) -> str:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mailbox-org-api
3
- Version: 2.4
3
+ Version: 2.5
4
4
  Summary: A library to access the mailbox Business API.
5
5
  Author: Hendrik Schlange
6
6
  Author-email: Hendrik Schlange <mail@heshsum.de>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "mailbox-org-api"
3
- version = "2.4"
3
+ version = "2.5"
4
4
  authors = [
5
5
  { name="Hendrik Schlange", email="mail@heshsum.de" },
6
6
  ]
@@ -3,7 +3,7 @@ from setuptools import find_packages, setup
3
3
  setup(
4
4
  name='mailbox_org_api',
5
5
  packages=find_packages(),
6
- version='2.4',
6
+ version='2.5',
7
7
  description='A library to access the mailbox Business API',
8
8
  author='Hendrik Schlange',
9
9
  install_requires=['requests'],
@@ -379,6 +379,9 @@ class TestAPIClient:
379
379
  api = APIClient.APIClient()
380
380
  api.auth(api_test_user, api_test_pass)
381
381
  mail = test_id + '@' + domain
382
+
383
+ # Ensure that the plan supports capabilities
384
+ api.mail_set_plan(mail, 'standard')
382
385
  for i in capabilities:
383
386
  api.mail_capabilities_set(mail, [i])
384
387
  # The API returns a list of capabilities
@@ -406,7 +409,7 @@ class TestAPIClient:
406
409
  api.auth(api_test_user, api_test_pass)
407
410
  mails = api.mail_list(domain)
408
411
  mail = mails[0]['mail']
409
- plans = ['premium', 'light', 'standard']
412
+ plans = ['premium', 'standard']
410
413
  for plan in plans:
411
414
  api.mail_set_plan(mail, plan)
412
415
  assert str(api.mail_get(mail)['plan']).lower() == plan
@@ -468,16 +471,17 @@ class TestAPIClient:
468
471
  mail = test_id + '@' + domain
469
472
  additional_mail_quota = 23
470
473
  api.mail_set_additional_mail_quota(mail, additional_mail_quota)
471
- assert additional_mail_quota == api.mail_get(mail)['additional_mail_quota']
474
+ assert int(api.mail_get(mail)['additional_mail_quota']) == additional_mail_quota
472
475
  api.deauth()
473
476
 
477
+ @pytest.mark.depends(name="test_mail_add")
474
478
  def test_mail_set_additional_cloud_quota(self):
475
479
  api = APIClient.APIClient()
476
480
  api.auth(api_test_user, api_test_pass)
477
481
  mail = test_id + '@' + domain
478
482
  additional_cloud_quota = 42
479
483
  api.mail_set_additional_cloud_quota(mail, additional_cloud_quota)
480
- assert additional_cloud_quota == api.mail_get(mail)['additional_cloud_quota']
484
+ assert int(api.mail_get(mail)['additional_cloud_quota']) == additional_cloud_quota
481
485
  api.deauth()
482
486
 
483
487
  @pytest.mark.depends(name="test_mail_add")
File without changes
File without changes
File without changes