|
| 1 | +import json |
| 2 | +import unittest |
| 3 | + |
| 4 | +from yoti_python_sdk.doc_scan import constants |
| 5 | +from yoti_python_sdk.doc_scan.session.create.check import ( |
| 6 | + WatchlistScreeningCheckBuilder, |
| 7 | +) |
| 8 | +from yoti_python_sdk.doc_scan.session.create.check.requested_check import RequestedCheck |
| 9 | +from yoti_python_sdk.doc_scan.session.create.check.watchlist_screen import ( |
| 10 | + WatchlistScreeningCheck, |
| 11 | + WatchlistScreeningCheckConfig, |
| 12 | +) |
| 13 | +from yoti_python_sdk.utils import YotiEncoder |
| 14 | +from yoti_python_sdk.doc_scan.constants import WATCHLIST_SCREENING_CHECK_TYPE |
| 15 | + |
| 16 | + |
| 17 | +class WatchlistScreeningCheckTest(unittest.TestCase): |
| 18 | + def test_should_build_correctly_with_manual_check(self): |
| 19 | + dummy_manual_check = "DUMMY_VALUE" |
| 20 | + |
| 21 | + result = ( |
| 22 | + WatchlistScreeningCheckBuilder() |
| 23 | + .with_manual_check(dummy_manual_check) |
| 24 | + .build() |
| 25 | + ) |
| 26 | + |
| 27 | + assert isinstance(result, RequestedCheck) |
| 28 | + assert isinstance(result, WatchlistScreeningCheck) |
| 29 | + |
| 30 | + assert result.type == constants.WATCHLIST_SCREENING_CHECK_TYPE |
| 31 | + assert result.config.manual_check == dummy_manual_check |
| 32 | + assert result.config.categories == [] |
| 33 | + |
| 34 | + def test_should_build_corretly_with_categories(self): |
| 35 | + dummy_categories = ["FIRST", "SECOND"] |
| 36 | + |
| 37 | + result = ( |
| 38 | + WatchlistScreeningCheckBuilder() |
| 39 | + .with_categories(dummy_categories) |
| 40 | + .build() |
| 41 | + ) |
| 42 | + |
| 43 | + assert isinstance(result, RequestedCheck) |
| 44 | + assert isinstance(result, WatchlistScreeningCheck) |
| 45 | + |
| 46 | + assert result.type == constants.WATCHLIST_SCREENING_CHECK_TYPE |
| 47 | + assert result.config.categories == dummy_categories |
| 48 | + assert result.config.manual_check is None |
| 49 | + |
| 50 | + def test_should_build_correctly_with_manual_check_and_categories(self): |
| 51 | + dummy_manual_check = "DUMMY_VALUE" |
| 52 | + dummy_categories = ["FIRST", "SECOND"] |
| 53 | + |
| 54 | + result = ( |
| 55 | + WatchlistScreeningCheckBuilder() |
| 56 | + .with_manual_check(dummy_manual_check) |
| 57 | + .with_categories(dummy_categories) |
| 58 | + .build() |
| 59 | + ) |
| 60 | + |
| 61 | + assert isinstance(result, RequestedCheck) |
| 62 | + assert isinstance(result, WatchlistScreeningCheck) |
| 63 | + |
| 64 | + assert result.type == constants.WATCHLIST_SCREENING_CHECK_TYPE |
| 65 | + assert result.config.manual_check == dummy_manual_check |
| 66 | + assert result.config.categories == dummy_categories |
| 67 | + |
| 68 | + def test_should_serialize_to_json_without_error(self): |
| 69 | + another_dummy_manual_check = "DUMMY_VALUE" |
| 70 | + another_dummy_categories = ["FIRST", "SECOND"] |
| 71 | + |
| 72 | + result = ( |
| 73 | + WatchlistScreeningCheckBuilder() |
| 74 | + .with_manual_check(another_dummy_manual_check) |
| 75 | + .with_categories(another_dummy_categories) |
| 76 | + .build() |
| 77 | + ) |
| 78 | + |
| 79 | + s = json.dumps(result, cls=YotiEncoder) |
| 80 | + assert s is not None and s != "" |
| 81 | + |
| 82 | + result = ( |
| 83 | + WatchlistScreeningCheckBuilder() |
| 84 | + .with_categories(another_dummy_categories) |
| 85 | + .build() |
| 86 | + ) |
| 87 | + |
| 88 | + s = json.dumps(result, cls=YotiEncoder) |
| 89 | + assert s is not None and s != "" |
| 90 | + |
| 91 | + s = json.loads(s) |
| 92 | + assert s.get("type") == WATCHLIST_SCREENING_CHECK_TYPE |
| 93 | + assert s.get("config") == {"categories": another_dummy_categories} |
| 94 | + |
| 95 | + result = ( |
| 96 | + WatchlistScreeningCheckBuilder() |
| 97 | + .with_manual_check(another_dummy_manual_check) |
| 98 | + .build() |
| 99 | + ) |
| 100 | + |
| 101 | + s = json.dumps(result, cls=YotiEncoder) |
| 102 | + assert s is not None and s != "" |
| 103 | + |
| 104 | + s = json.loads(s) |
| 105 | + assert s.get("type") == WATCHLIST_SCREENING_CHECK_TYPE |
| 106 | + assert s.get("config") == {"manual_check": "DUMMY_VALUE", "categories": []} |
0 commit comments