Skip to content

Commit f53ac6e

Browse files
authored
Ignore services endpoint (#98)
* Ignore calls to services endpoint * Add changelog * Remove type ignore * Bump version * Revert request version * Add deprecation warning * Add test for deprecation warning when validate_id_params * Add tests for deprecation warnings
1 parent 311bf62 commit f53ac6e

File tree

10 files changed

+129
-197
lines changed

10 files changed

+129
-197
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ repos:
3636
rev: v1.4.1
3737
hooks:
3838
- id: mypy
39+
additional_dependencies:
40+
- "types-requests"
3941
- repo: https://github.com/pycqa/isort
4042
rev: 5.12.0
4143
hooks:

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Changed
9+
- Ignore `use_validation_api` in `submit_job`, method deprecated and will be removed
10+
- Ignore `use_validation_api` and `sid_server` in `Utilities.validate_id_params`, methods deprecated and will be removed
811
### Added
912
- Add git commit hook with pre-commit
1013

poetry.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "smile-id-core"
3-
version = "2.1.2"
3+
version = "2.1.3"
44
description = "The official Smile Identity package exposes four classes namely; the WebApi class, the IDApi class, the Signature class and the Utilities class."
55
license = "MIT"
66
authors = ["Smile Identity <[email protected]>"]

smile_id_core/IdApi.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""ID API class for kyc services."""
22
from typing import Any, Dict, Optional, Union
3+
from warnings import warn
34

45
from requests import Response
56

@@ -38,7 +39,7 @@ def submit_job(
3839
self,
3940
partner_params: Dict[str, Any],
4041
id_params: Dict[str, str],
41-
use_validation_api: bool = True,
42+
use_validation_api: bool = False,
4243
options_params: Optional[OptionsParams] = None,
4344
) -> Response:
4445
"""Validate data params & query id_verification endpoint for KYC jobs.
@@ -57,6 +58,13 @@ def submit_job(
5758
Returns: https post request output of type Response. Alternatively,
5859
raises a server or value error if there's an exception.
5960
"""
61+
if use_validation_api:
62+
warn(
63+
"The field use_validation_api is deprecated and "
64+
"will be removed in the future.",
65+
category=DeprecationWarning,
66+
stacklevel=2,
67+
)
6068
if not options_params:
6169
options_params = OptionsParams(
6270
return_job_status=False,
@@ -80,7 +88,7 @@ def submit_job(
8088
self.url,
8189
id_params,
8290
partner_params,
83-
use_validation_api,
91+
False,
8492
)
8593

8694
if partner_params.get("job_type") != JobType.ENHANCED_KYC:

smile_id_core/Utilities.py

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import json
77
import sys
88
from typing import Any, Dict, Optional, Union
9+
from warnings import warn
910

1011
import requests
1112
from requests import Response
@@ -229,6 +230,14 @@ def validate_id_params(
229230
partner_params:
230231
use_validation_api:
231232
"""
233+
if use_validation_api:
234+
warn(
235+
"The field use_validation_api is deprecated and "
236+
"will be removed in the future.",
237+
category=DeprecationWarning,
238+
stacklevel=2,
239+
)
240+
232241
job_type = partner_params.get("job_type")
233242
if (
234243
job_type != JobType.DOCUMENT_VERIFICATION
@@ -247,50 +256,6 @@ def validate_id_params(
247256
raise ValueError(f"key {field} cannot be empty")
248257
else:
249258
raise ValueError(f"key {field} cannot be empty")
250-
if not use_validation_api:
251-
return
252-
253-
response = Utilities.get_smile_id_services(sid_server)
254-
if response.status_code != 200:
255-
raise ServerError(
256-
f"Failed to get to /services, status={response.status_code},"
257-
f" response={response.json()}"
258-
)
259-
response_json = response.json()
260-
if job_type == JobType.DOCUMENT_VERIFICATION:
261-
doc_verification = response_json["hosted_web"]["doc_verification"]
262-
if id_info_params["country"] not in doc_verification:
263-
raise ValueError(
264-
f"country {id_info_params['country']} is invalid"
265-
)
266-
selected_country = doc_verification[id_info_params["country"]][
267-
"id_types"
268-
]
269-
if id_info_params["id_type"] not in selected_country:
270-
raise ValueError(
271-
f"id_type {id_info_params['id_type']} is invalid"
272-
)
273-
else:
274-
id_types_by_country = response_json["id_types"]
275-
if id_info_params["country"] not in id_types_by_country:
276-
raise ValueError(
277-
f"country {id_info_params['country']} is invalid"
278-
)
279-
selected_country = response_json["id_types"][
280-
id_info_params["country"]
281-
]
282-
if id_info_params["id_type"] not in selected_country:
283-
raise ValueError(
284-
f"id_type {id_info_params['id_type']} is invalid"
285-
)
286-
id_params = selected_country[id_info_params["id_type"]]
287-
for key in id_params:
288-
if key not in id_info_params and key not in partner_params:
289-
raise ValueError(f"key {key} is required")
290-
if key in id_info_params and not id_info_params[key]:
291-
raise ValueError(f"key {key} cannot be empty")
292-
if key in partner_params and not partner_params.get(key):
293-
raise ValueError(f"key {key} cannot be empty")
294259

295260
@staticmethod
296261
def get_smile_id_services(sid_server: Union[str, int]) -> Response:

smile_id_core/WebApi.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import time
44
from datetime import datetime
55
from typing import Any, Dict, List, Optional, Union
6+
from warnings import warn
67

78
import requests
89
from requests import Response
@@ -78,9 +79,16 @@ def submit_job(
7879
images_params: List[ImageParams],
7980
id_info_params: Dict[str, Any],
8081
options_params: OptionsParams,
81-
use_validation_api: bool = True,
82+
use_validation_api: bool = False,
8283
) -> Union[Response, Dict[str, Any]]:
8384
"""Perform key/parameter validation, creates zipped file and uploads."""
85+
if use_validation_api:
86+
warn(
87+
"The field use_validation_api is deprecated and"
88+
" will be removed in the future.",
89+
category=DeprecationWarning,
90+
stacklevel=2,
91+
)
8492
Utilities.validate_partner_params(partner_params)
8593
job_type = partner_params.get("job_type")
8694

@@ -100,7 +108,7 @@ def submit_job(
100108
self.url,
101109
id_info_params,
102110
partner_params,
103-
use_validation_api,
111+
False,
104112
)
105113
id_info_params = {
106114
"first_name": None,
@@ -129,7 +137,7 @@ def submit_job(
129137
return self.__call_id_api(
130138
partner_params,
131139
id_info_params,
132-
use_validation_api,
140+
False,
133141
options_params,
134142
)
135143

@@ -145,7 +153,7 @@ def submit_job(
145153
job_type=job_type,
146154
)
147155
Utilities.validate_id_params(
148-
self.url, id_info_params, partner_params, use_validation_api
156+
self.url, id_info_params, partner_params, False
149157
)
150158
self.__validate_return_data(options_params)
151159

tests/test_id_api.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,32 @@ def test_validate_return_data(
322322
)
323323

324324

325+
def test_show_deprecation_warning_for_use_validation_api(
326+
kyc_partner_params: Dict[str, Any],
327+
kyc_id_info: Dict[str, str],
328+
signature_fixture: Signature,
329+
client: IdApi,
330+
) -> None:
331+
"""Uses mocked examples for payload responses; checks that
332+
response status code is 200 and response body is not empty"""
333+
partner_params, id_info_params = (
334+
kyc_partner_params,
335+
kyc_id_info,
336+
)
337+
with patch("requests.post") as mocked_post:
338+
mocked_post.return_value.status_code = 200
339+
mocked_post.return_value.ok = True
340+
mocked_post.return_value.text.return_value = get_id_response(
341+
signature_fixture,
342+
)
343+
mocked_post.return_value.json.return_value = get_id_response(
344+
signature_fixture,
345+
)
346+
347+
with pytest.deprecated_call():
348+
client.submit_job(partner_params, id_info_params, True)
349+
350+
325351
def test_validate_return_data_business_verification(
326352
kyc_partner_params: Dict[str, Any],
327353
kyc_id_info: Dict[str, str],

tests/test_utilities.py

Lines changed: 25 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,31 @@ def get_smile_services_response() -> Dict[str, Any]:
141141
}
142142

143143

144+
def test_show_deprecation_when_use_validation_is_true(
145+
setup_client: Tuple[str, str, str]
146+
) -> None:
147+
api_key, partner_id, _ = setup_client
148+
id_info_params = {
149+
"first_name": "",
150+
"last_name": "",
151+
"country": "",
152+
"id_type": "",
153+
"id_number": "",
154+
"dob": "",
155+
"entered": None,
156+
}
157+
partner_params = {
158+
"job_id": f"job-{uuid.uuid4()}",
159+
"user_id": f"user-{uuid.uuid4()}",
160+
"job_type": JobType.BUSINESS_VERIFICATION,
161+
}
162+
utilities = Utilities(partner_id, api_key, 0)
163+
with pytest.deprecated_call():
164+
utilities.validate_id_params(
165+
0, id_info_params, partner_params, use_validation_api=True
166+
)
167+
168+
144169
def test_validate_id_params(
145170
setup_client: Tuple[str, str, str], signature_fixture: Signature
146171
) -> None:
@@ -305,7 +330,6 @@ def test_validate_id_params_should_raise_when_provided_with_invalid_input(
305330
"""Validate id parameters using the smile services endpoint which
306331
checks the provided id params, and partner params"""
307332

308-
stub_service("https://testapi.smileidentity.com/v1")
309333
kyc_id_info["country"] = ""
310334
with pytest.raises(ValueError) as value_error:
311335
Utilities.validate_id_params(
@@ -332,59 +356,6 @@ def test_validate_id_params_should_raise_when_provided_with_invalid_input(
332356
kyc_partner_params,
333357
)
334358
assert str(value_error.value) == "key id_number cannot be empty"
335-
kyc_id_info["id_number"] = "A00000000"
336-
kyc_id_info["country"] = "ZW"
337-
with pytest.raises(ValueError) as value_error:
338-
Utilities.validate_id_params(
339-
client_utilities.url,
340-
kyc_id_info,
341-
kyc_partner_params,
342-
use_validation_api=True,
343-
)
344-
assert str(value_error.value) == "country ZW is invalid"
345-
346-
kyc_id_info["country"] = "NG"
347-
kyc_id_info["id_type"] = "Not_Supported"
348-
with pytest.raises(ValueError) as value_error:
349-
Utilities.validate_id_params(
350-
client_utilities.url,
351-
kyc_id_info,
352-
kyc_partner_params,
353-
use_validation_api=True,
354-
)
355-
assert str(value_error.value) == "id_type Not_Supported is invalid"
356-
kyc_id_info["id_type"] = "PASSPORT"
357-
kyc_partner_params["user_id"] = None
358-
with pytest.raises(ValueError) as value_error:
359-
Utilities.validate_id_params(
360-
client_utilities.url,
361-
kyc_id_info,
362-
kyc_partner_params,
363-
use_validation_api=True,
364-
)
365-
assert str(value_error.value) == "key user_id cannot be empty"
366-
367-
kyc_partner_params["user_id"] = "kyb_test_user_008"
368-
kyc_id_info["first_name"] = ""
369-
with pytest.raises(ValueError) as value_error:
370-
Utilities.validate_id_params(
371-
client_utilities.url,
372-
kyc_id_info,
373-
kyc_partner_params,
374-
use_validation_api=True,
375-
)
376-
assert str(value_error.value) == "key first_name cannot be empty"
377-
kyc_id_info["first_name"] = "FirstName"
378-
updated_partner_params = dict(kyc_partner_params)
379-
del updated_partner_params["user_id"]
380-
with pytest.raises(ValueError) as value_error:
381-
Utilities.validate_id_params(
382-
client_utilities.url,
383-
kyc_id_info,
384-
updated_partner_params,
385-
use_validation_api=True,
386-
)
387-
assert str(value_error.value) == "key user_id is required"
388359

389360

390361
@responses.activate
@@ -414,28 +385,6 @@ def test_validate_id_params_raise_when_given_invalid_input_for_jt6(
414385
)
415386
assert str(value_error.value) == "key id_type cannot be empty"
416387

417-
kyc_id_info["id_type"] = "PASSPORT"
418-
kyc_id_info["country"] = "ZW"
419-
with pytest.raises(ValueError) as value_error:
420-
Utilities.validate_id_params(
421-
client_utilities.url,
422-
kyc_id_info,
423-
partner_params_jt6,
424-
use_validation_api=True,
425-
)
426-
assert str(value_error.value) == "country ZW is invalid"
427-
428-
kyc_id_info["country"] = "NG"
429-
kyc_id_info["id_type"] = "Not_Supported"
430-
with pytest.raises(ValueError) as value_error:
431-
Utilities.validate_id_params(
432-
client_utilities.url,
433-
kyc_id_info,
434-
partner_params_jt6,
435-
use_validation_api=True,
436-
)
437-
assert str(value_error.value) == "id_type Not_Supported is invalid"
438-
439388

440389
@responses.activate
441390
def test_get_job_status(

0 commit comments

Comments
 (0)