def test_not_found_exception(self): pook.mock( url=BASE_URI + "/trial/connection/v1/testauthentication", method="GET", reply=404, ) with self.assertRaises(NotFoundException): self.api.test_authentication(mode="trial")
def test_unauthorized_exception(self): pook.mock( url=BASE_URI + "/trial/connection/v1/testauthentication", method="GET", reply=401, ) with self.assertRaises(UnauthorizedException): self.api.test_authentication(mode="trial")
def test_forbidden_exception(self): pook.mock( url=BASE_URI + "/trial/connection/v1/testauthentication", method="GET", reply=403, ) with self.assertRaises(ForbiddenException): self.api.test_authentication(mode="trial")
def test_service_exception(self): pook.mock( url=BASE_URI + "/trial/connection/v1/testauthentication", method="GET", reply=500, ) with self.assertRaises(ServiceException): self.api.test_authentication(mode="trial")
def test_get_test_entities(self): mock = pook.mock( url=BASE_URI + "/trial/configuration/v1/testentities/Identity%20Verification/AU", method="GET", headers={"x-trulioo-api-key": "test-api-key"}, reply=200, response_json=[{ "PersonInfo": { "FirstGivenName": "Test" }, "Location": { "BuildingNumber": "10" }, "Communication": { "MobileNumber": "076310691" }, }], ) result = self.api.get_test_entities( mode="trial", country_code="AU", configuration_name="Identity Verification") assert mock.calls == 1 assert result == [ TestEntityDataFields( person_info=PersonInfo(first_given_name="Test"), location=Location(building_number="10"), communication=Communication(mobile_number="076310691"), ) ]
def test_get_recommended_fields(self): mock = pook.mock( url=BASE_URI + "/trial/configuration/v1/recommendedfields/Identity%20Verification/AU", method="GET", headers={"x-trulioo-api-key": "test-api-key"}, reply=200, response_json={ "title": "DataFields", "type": "object", "properties": { "PersonInfo": {} }, }, ) result = self.api.get_recommended_fields( mode="trial", country_code="AU", configuration_name="Identity Verification") assert mock.calls == 1 assert result == { "title": "DataFields", "type": "object", "properties": { "PersonInfo": {} }, }
def test_get_transaction_status(self): mock = pook.mock( url=BASE_URI + "/trial/verifications/v1/transaction/test-transaction-guid-1/status", method="GET", headers={"x-trulioo-api-key": "test-api-key"}, reply=200, response_json={ "TransactionId": "test-transaction-guid-1", "TransactionRecordId": "test-transaction-guid-2", "Status": "InProgress", "UploadedDt": "2017-07-11T21:47:50", "IsTimedOut": False, }, ) result = self.api.get_transaction_status(mode="trial", id="test-transaction-guid-1") assert mock.calls == 1 assert result == TransactionStatus( transaction_id="test-transaction-guid-1", transaction_record_id="test-transaction-guid-2", status="InProgress", uploaded_dt=datetime.fromisoformat("2017-07-11T21:47:50"), is_timed_out=False, )
def test_api_exception(self): pook.mock( url=BASE_URI + "/trial/connection/v1/testauthentication", method="GET", reply=300, ) try: self.api.test_authentication(mode="trial") except ApiException as e: e.headers = "headers" e.body = "body" assert str(e) == ("(300)\n" "Reason: Multiple Choices\n" "HTTP response headers: headers\n" "HTTP response body: body\n") error = ApiException() assert str(error) == "(None)\nReason: None\n"
def test_verify(self): mock = pook.mock( url=BASE_URI + "/trial/verifications/v1/verify", method="POST", headers={"x-trulioo-api-key": "test-api-key"}, reply=200, response_json={ "TransactionID": "test-transaction-guid-1", "UploadedDt": "2017-07-11T21:47:50", "Record": { "TransactionRecordID": "test-transaction-guid-2", "RecordStatus": "match", "DatasourceResults": [{ "DatasourceName": "Datasource", "DatasourceFields": [{ "FieldName": "FirstName", "Status": "match" }], }], "Errors": [], }, "CustomerReferenceID": "abc-1234", "Errors": [], }, ) result = self.api.verify( mode="trial", verify_request=VerifyRequest(country_code="AU", data_fields=DataFields()), ) assert mock.calls == 1 assert result == VerifyResult( transaction_id="test-transaction-guid-1", uploaded_dt=datetime.fromisoformat("2017-07-11T21:47:50"), record=Record( transaction_record_id="test-transaction-guid-2", record_status="match", datasource_results=[ DatasourceResult( datasource_name="Datasource", datasource_fields=[ DatasourceField(field_name="FirstName", status="match") ], ) ], errors=[], ), customer_reference_id="abc-1234", errors=[], )
def test_say_hello(self): mock = pook.mock( url=BASE_URI + "/trial/connection/v1/sayhello/Trulioo%20User", method="GET", reply=200, response_json="Hello Trulioo User", ) result = self.api.say_hello(mode="trial", name="Trulioo User") assert mock.calls == 1 assert result == "Hello Trulioo User"
def test_test_authentication(self): mock = pook.mock( url=BASE_URI + "/trial/connection/v1/testauthentication", method="GET", headers={"x-trulioo-api-key": "test-api-key"}, reply=200, response_json="Hello Trulioo User", ) result = self.api.test_authentication(mode="trial") assert mock.calls == 1 assert result == "Hello Trulioo User"
def test_get_document_types(self): mock = pook.mock( url=BASE_URI + "/trial/configuration/v1/documentTypes/AU", method="GET", headers={"x-trulioo-api-key": "test-api-key"}, reply=200, response_json={"AU": ["Passport"]}, ) result = self.api.get_document_types(mode="trial", country_code="AU") assert mock.calls == 1 assert result == {"AU": ["Passport"]}
def test_get_transaction_record(self): mock = pook.mock( url=BASE_URI + "/trial/verifications/v1/transactionrecord/test-transaction-guid", method="GET", headers={"x-trulioo-api-key": "test-api-key"}, reply=200, response_json={ "InputFields": [{ "FieldName": "FirstName", "Value": "Test" }], "UploadedDt": "2017-07-11T21:47:50", "Record": { "TransactionRecordID": "test-transaction-guid", "RecordStatus": "match", "DatasourceResults": [{ "DatasourceName": "Datasource", "DatasourceFields": [{ "FieldName": "FirstName", "Status": "match" }], }], }, "Errors": [], }, ) result = self.api.get_transaction_record(mode="trial", id="test-transaction-guid") assert mock.calls == 1 assert result == TransactionRecordResult( input_fields=[DataField(field_name="FirstName", value="Test")], uploaded_dt=datetime.fromisoformat("2017-07-11T21:47:50"), record=Record( transaction_record_id="test-transaction-guid", record_status="match", datasource_results=[ DatasourceResult( datasource_name="Datasource", datasource_fields=[ DatasourceField(field_name="FirstName", status="match") ], ) ], ), errors=[], )
def test_connection_async_callback_url(self): mock = pook.mock( url=BASE_URI + "/trial/connection/v1/async-callback", method="POST", reply=200, response_json={}, ) result = self.api.connection_async_callback_url( mode="trial", transaction_status=TransactionStatus() ) assert mock.calls == 1 assert result == {}
def test_get_country_codes(self): mock = pook.mock( url=BASE_URI + "/trial/configuration/v1/countrycodes/Identity%20Verification", method="GET", headers={"x-trulioo-api-key": "test-api-key"}, reply=200, response_json=["AU"], ) result = self.api.get_country_codes( mode="trial", configuration_name="Identity Verification") assert mock.calls == 1 assert result == ["AU"]
def test_get_world_check_profile(self): mock = pook.mock( url=BASE_URI + "/trial/worldcheck/v1/profile/test-guid/ref-123", method="GET", headers={"x-trulioo-api-key": "test-api-key"}, reply=200, response_json={"content": "test"}, ) result = self.api.get_world_check_profile( mode="trial", original_transaction_id="test-guid", reference_id="ref-123") assert mock.calls == 1 assert result == {"content": "test"}
def test_document_download(self): mock = pook.mock( url=BASE_URI + "/trial/verifications/v1/documentdownload/test-transaction-guid/DocumentFrontImage", method="GET", headers={"x-trulioo-api-key": "test-api-key"}, reply=200, response_json={"Image": "base64"}, ) result = self.api.document_download( mode="trial", transaction_record_id="test-transaction-guid", field_name="DocumentFrontImage", ) assert mock.calls == 1 assert result == {"Image": "base64"}
def test_search(self): mock = pook.mock( url=BASE_URI + "/trial/business/v1/search", method="POST", headers={"x-trulioo-api-key": "test-api-key"}, reply=200, response_json={ "TransactionID": "test-transaction-guid-1", "UploadedDt": "2017-07-11T21:47:50", "ProductName": "Business Search", "Record": { "DatasourceResults": [{ "DatasourceName": "Datasource", "Results": [{ "BusinessName": "test", "MatchingScore": "1" }], }], "Errors": [], }, }, ) result = self.api.search( mode="trial", business_search_request=BusinessSearchRequest(country_code="AU"), ) assert mock.calls == 1 assert result == BusinessSearchResponse( transaction_id="test-transaction-guid-1", uploaded_dt=datetime.fromisoformat("2017-07-11T21:47:50"), product_name="Business Search", record=BusinessRecord( datasource_results=[ BusinessResult( datasource_name="Datasource", results=[ Result(business_name="test", matching_score="1") ], ) ], errors=[], ), )
def test_get_detailed_consents(self): mock = pook.mock( url=BASE_URI + "/trial/configuration/v1/detailedConsents/Identity%20Verification/AU", method="GET", headers={"x-trulioo-api-key": "test-api-key"}, reply=200, response_json=[{ "Name": "Australia Driver Licence", "Text": "Test" }], ) result = self.api.get_detailed_consents( mode="trial", country_code="AU", configuration_name="Identity Verification") assert mock.calls == 1 assert result == [ Consent(name="Australia Driver Licence", text="Test") ]
def test_get_business_registration_numbers(self): mock = pook.mock( url=BASE_URI + "/trial/configuration/v1/businessregistrationnumbers/CA/CA-BC", method="GET", headers={"x-trulioo-api-key": "test-api-key"}, reply=200, response_json=[{ "Name": "test1" }, { "Name": "test2" }], ) result = self.api.get_business_registration_numbers( mode="trial", country_code="CA", jurisdiction_code="CA-BC") assert mock.calls == 1 assert result == [ BusinessRegistrationNumber(name="test1"), BusinessRegistrationNumber(name="test2"), ]
def test_get_country_subdivisions(self): mock = pook.mock( url=BASE_URI + "/trial/configuration/v1/countrysubdivisions/AU", method="GET", headers={"x-trulioo-api-key": "test-api-key"}, reply=200, response_json=[{ "Name": "Northern Territory", "Code": "NT", "ParentCode": "" }], ) result = self.api.get_country_subdivisions(mode="trial", country_code="AU") assert mock.calls == 1 assert result == [ CountrySubdivision(name="Northern Territory", code="NT", parent_code="") ]
def test_get_business_search_result(self): mock = pook.mock( url=BASE_URI + "/trial/business/v1/search/transactionrecord/test-transaction-guid", method="GET", headers={"x-trulioo-api-key": "test-api-key"}, reply=200, response_json={ "TransactionID": "test-transaction-guid", "Record": { "RecordStatus": "match" }, }, ) result = self.api.get_business_search_result( mode="trial", id="test-transaction-guid") assert mock.calls == 1 assert result == BusinessSearchResponse( transaction_id="test-transaction-guid", record=BusinessRecord(record_status="match"), )
def test_get_datasources(self): mock = pook.mock( url=BASE_URI + "/trial/configuration/v1/datasources/Identity%20Verification/AU", method="GET", headers={"x-trulioo-api-key": "test-api-key"}, reply=200, response_json=[{ "Name": "Credit Agency", "Description": "Test", "Coverage": "25%" }], ) result = self.api.get_datasources( mode="trial", country_code="AU", configuration_name="Identity Verification") assert mock.calls == 1 assert result == [ NormalizedDatasourceGroupCountry(name="Credit Agency", description="Test", coverage="25%") ]
def test_webhook_github(self): # Mocks # method: GET mock_list = [ { 'url': 'https://api.github.com/repos/umisora/github-checklist-by-filetype/contents/.github/CHECKLIST?ref=master', 'response_type': 'json', 'method': 'GET', 'response_body': 'test/sample-webhook/sample-response/get_github_object-github-CHECKLIST.json' }, { 'url': 'https://api.github.com/repos/umisora/github-checklist-by-filetype/contents/.github/DEFAULT.md', 'response_type': 'json', 'method': 'GET', 'response_body': 'test/sample-webhook/sample-response/get_github_object-github-DEFAULTmd.json' }, { 'url': 'https://api.github.com/repos/umisora/github-checklist-by-filetype/contents/.github/SERVERSIDE_CHECKLIST.md', 'response_type': 'json', 'method': 'GET', 'response_body': 'test/sample-webhook/sample-response/get_github_object-github-SERVERSIDE_CHECKLISTmd.json' }, { 'url': 'https://raw.githubusercontent.com/umisora/github-checklist-by-filetype/master/.github/CHECKLIST', 'response_type': 'text/plai', 'method': 'GET', 'response_body': 'test/sample-webhook/sample-response/get_github_object-github-CHECKLIST-raw.txt' }, { 'url': 'https://raw.githubusercontent.com/umisora/github-checklist-by-filetype/master/.github/DEFAULT.md', 'response_type': 'text/plain', 'method': 'GET', 'response_body': 'test/sample-webhook/sample-response/get_github_object-github-DEFAULTmd-raw.txt' }, { 'url': 'https://raw.githubusercontent.com/umisora/github-checklist-by-filetype/master/.github/SERVERSIDE_CHECKLIST.md', 'response_type': 'text/plain', 'method': 'GET', 'response_body': 'test/sample-webhook/sample-response/get_github_object-github-SERVERSIDE_CHECKLISTmd-raw.txt' }, { 'url': 'https://api.github.com/repos/umisora/github-checklist-by-filetype/pulls/1/files', 'response_type': 'json', 'method': 'GET', 'response_body': 'test/sample-webhook/sample-response/get_files_of_pr.json' }, { 'url': 'https://api.github.com/repos/umisora/github-checklist-by-filetype/pulls/1', 'response_type': 'json', 'method': 'PATCH', 'response_body': 'test/sample-webhook/sample-response/update_pr_description.json' }, ] mocks = [] for mock in mock_list: mocks.append(pook.mock( mock['url'], method=mock['method'], reply=200, response_type=mock['response_type'], response_body=open(mock['response_body'], 'r').read() )) # Test request_data = "test/sample-webhook/sample-webhook-pr-open.json" post_endpoint = "/webhook/github?token=dummy" response = self.app.post( post_endpoint, data=open(request_data, 'r'), content_type='application/json', headers={'X-Hub-Signature': 'dummy', 'X-GitHub-Event': 'pull_request'} ) for mock in mocks: print("mock call count is ", mock.calls) self.assertEqual(response.status_code, 200)