-
Notifications
You must be signed in to change notification settings - Fork 603
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for allow_list, allow_list_match, regex_flags in REST API (…
- Loading branch information
Showing
3 changed files
with
100 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -480,3 +480,95 @@ def test_given_ad_hoc_deny_list_recognizer_the_right_entities_are_returned(): | |
assert equal_json_strings( | ||
expected_response, response_content, ignore_keys=["recognition_metadata"] | ||
) | ||
|
||
|
||
@pytest.mark.api | ||
def test_given_allow_list_then_no_entity_is_returned(): | ||
request_body = """ | ||
{ | ||
"text": "email: [email protected]", | ||
"language": "en", | ||
"allow_list": ["[email protected]"] | ||
} | ||
""" | ||
|
||
response_status, response_content = analyze(request_body) | ||
|
||
expected_response = """ | ||
[] | ||
""" | ||
assert response_status == 200 | ||
assert equal_json_strings( | ||
expected_response, response_content | ||
) | ||
|
||
|
||
@pytest.mark.api | ||
def test_given_allow_list_with_regex_match_then_no_entity_is_returned(): | ||
request_body = """ | ||
{ | ||
"text": "email: [email protected]", | ||
"language": "en", | ||
"allow_list": [".*@github.com"], | ||
"allow_list_match": "regex" | ||
} | ||
""" | ||
|
||
response_status, response_content = analyze(request_body) | ||
|
||
expected_response = """ | ||
[] | ||
""" | ||
assert response_status == 200 | ||
assert equal_json_strings( | ||
expected_response, response_content | ||
) | ||
|
||
|
||
@pytest.mark.api | ||
def test_given_allow_list_without_setting_allow_list_match_then_normal_entity_is_returned(): | ||
request_body = """ | ||
{ | ||
"text": "email: [email protected]", | ||
"language": "en", | ||
"allow_list": [".*@github.com"] | ||
} | ||
""" | ||
|
||
response_status, response_content = analyze(request_body) | ||
|
||
expected_response = """ | ||
[ | ||
{"entity_type": "EMAIL_ADDRESS", "start": 7, "end": 23, "score": 0.85, "analysis_explanation":null} | ||
] | ||
""" | ||
assert response_status == 200 | ||
assert equal_json_strings( | ||
expected_response, response_content, ignore_keys=["recognition_metadata"] | ||
) | ||
|
||
|
||
@pytest.mark.api | ||
def test_given_regex_flags_and_normal_entities_are_returned(): | ||
# case sensitive flags are turned off, GitHub != github | ||
request_body = """ | ||
{ | ||
"text": "email: [email protected]", | ||
"language": "en", | ||
"allow_list": [".*@github.com"], | ||
"allow_list_match": "regex", | ||
"regex_flags": 0 | ||
} | ||
""" | ||
|
||
response_status, response_content = analyze(request_body) | ||
|
||
expected_response = """ | ||
[ | ||
{"entity_type": "EMAIL_ADDRESS", "start": 7, "end": 23, "score": 0.85, "analysis_explanation":null} | ||
] | ||
""" | ||
assert response_status == 200 | ||
assert equal_json_strings( | ||
expected_response, response_content, ignore_keys=["recognition_metadata"] | ||
) |
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