def test_entity_match_when_not_found(self, mock_post):
        result = issue_entity_match_request(not_found_keyword)

        expected_result = default_not_found_result(resolution_algorithm=ResolutionAlgo.ENTITY_MATCH.value,
                                                   keyword=get_correct_keyword(not_found_keyword))
        self.assertEqual(result, expected_result)
        pass
    def test_entity_match_when_found(self, mock_post):
        result = issue_entity_match_request(found_keyword)

        self.assertEqual(result['confidence'], found_match_confidence)
        self.assertEqual(result['perm_id'], found_perm_id)
        self.assertEqual(result['org_name'], found_org_name)
        self.assertEqual(result['keyword'], found_keyword)
        pass
def search_tr(keyword):
    entity_match_result = issue_entity_match_request(keyword_arg=keyword)
    open_calais_result = issue_open_calais_request(keyword_arg=keyword)

    if not entity_match_result and not open_calais_result:
        return None

    resolved_entity = ResolvedItem(
        keyword=keyword,
        entity_match=entity_match_result,
        open_calais=open_calais_result,
        manual_override=__get_previous_manual_override(keyword))

    if resolved_entity is not None:
        dynamo_save_entity(resolved_entity)
        return resolved_entity.__dict__
    else:
        return None
    def test_entity_match_when_api_error(self, mock_post):
        result = issue_entity_match_request(api_error_keyword)

        self.assertEqual(result, None)
        pass
def __issue_em_oc_request(keyword_orig):
    em_result = issue_entity_match_request(keyword_arg=keyword_orig)
    oc_result = issue_open_calais_request(keyword_arg=keyword_orig,
                                          max_retry=10)

    return em_result, oc_result
force_ers_url = f'{base_url}/resolve/force/keyword'

tr_url = 'https://api.thomsonreuters.com/permid'
tr_api_key = "'hWRwzOxar9YGo0A0BnhqKvxF5s5CpwNS', 'hWRwzOxar9YGo0A0BnhqKvxF5s5CpwNS'"

os.environ['TR_URL'] = tr_url
os.environ['TR_API_KEY'] = tr_api_key

# Lookup
result = requests.get(url=f'{lookup_ers_url}/{quoted_keyword}')
print(f'LOOKUP: {result.status_code}, {result.text}\n')

# Force Resolve
if force_resolve:
    result = requests.post(url=f'{smart_ers_url}/{quoted_keyword}/0')
    if result.status_code is not requests.codes.ok:
        result = requests.post(url=f'{force_ers_url}/{quoted_keyword}')
        print(f'FORCE-RESOLVE: {result.status_code}, {result.text}\n')

# Smart Resolve
result = requests.post(url=f'{smart_ers_url}/{quoted_keyword}/0')
print(f'SMART-RESOLVE: {result.status_code}, {result.text}\n')

# Entity Match
result = issue_entity_match_request(keyword_arg=keyword_arg)
print(f'ENTITY-MATCH: {result}')

# Open Calais
result = issue_open_calais_request(keyword_arg=keyword_arg, max_retry=10)
print(f'OPEN-CALAIS: {result}')