Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions incognia/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def register_new_signup(self,
address_coordinates: Optional[Coordinates] = None,
external_id: Optional[str] = None,
policy_id: Optional[str] = None,
account_id: Optional[str] = None) -> dict:
account_id: Optional[str] = None,
device_os: Optional[str] = None,
app_version: Optional[str] = None) -> dict:
if not request_token:
raise IncogniaError('request_token is required.')

Expand All @@ -48,7 +50,9 @@ def register_new_signup(self,
'address_coordinates': address_coordinates,
'external_id': external_id,
'policy_id': policy_id,
'account_id': account_id
'account_id': account_id,
'device_os': device_os.lower() if device_os is not None else None,
'app_version': app_version
}
data = encode(body)
return self.__request.post(Endpoints.SIGNUPS, headers=headers, data=data)
Expand Down
26 changes: 16 additions & 10 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class TestIncogniaAPI(TestCase):
ACCOUNT_ID: Final[str] = 'ANY_ACCOUNT_ID'
INVALID_ACCOUNT_ID: Final[str] = 'INVALID_ACCOUNT_ID'
ADDRESS_LINE: Final[str] = 'ANY_ADDRESS_LINE'
DEVICE_OS: Final[str] = 'ANY_DEVICE_OS'
APP_VERSION: Final[str] = 'ANY_APP_VERSION'
STRUCTURED_ADDRESS: Final[dict] = {
'locale': 'ANY_LOCALE',
'country_name': 'ANY_COUNTRY_NAME',
Expand Down Expand Up @@ -67,7 +69,9 @@ class TestIncogniaAPI(TestCase):
'address_coordinates': ADDRESS_COORDINATES,
'external_id': f'{EXTERNAL_ID}',
'policy_id': f'{POLICY_ID}',
'account_id': f'{ACCOUNT_ID}'
'account_id': f'{ACCOUNT_ID}',
'device_os': f'{DEVICE_OS.lower()}',
'app_version': f'{APP_VERSION}'
})
OK_STATUS_CODE: Final[int] = 200
CLIENT_ERROR_CODE: Final[int] = 400
Expand Down Expand Up @@ -195,7 +199,9 @@ def test_register_new_signup_when_request_token_is_valid_should_return_full_vali
external_id=self.EXTERNAL_ID,
policy_id=self.POLICY_ID,
account_id=self.ACCOUNT_ID,
request_token=self.REQUEST_TOKEN)
request_token=self.REQUEST_TOKEN,
device_os=self.DEVICE_OS,
app_version=self.APP_VERSION)

mock_token_manager_get.assert_called()
mock_base_request_post.assert_called_with(Endpoints.SIGNUPS,
Expand Down Expand Up @@ -533,7 +539,7 @@ def test_register_login_with_location_and_empty_latitude_should_raise_an_Incogni
self.ACCOUNT_ID,
location=self.INVALID_LOCATION_EMPTY_LATITUDE,
policy_id=self.POLICY_ID,
)
)

mock_token_manager_get.assert_not_called()
mock_base_request_post.assert_not_called()
Expand All @@ -554,7 +560,7 @@ def test_register_login_with_location_and_empty_longitude_should_raise_an_Incogn
self.ACCOUNT_ID,
location=self.INVALID_LOCATION_EMPTY_LONGITUDE,
policy_id=self.POLICY_ID,
)
)

mock_token_manager_get.assert_not_called()
mock_base_request_post.assert_not_called()
Expand All @@ -575,7 +581,7 @@ def test_register_login_with_location_and_wrong_timestamp_should_raise_an_Incogn
self.ACCOUNT_ID,
location=self.INVALID_LOCATION_WRONG_TIMESTAMP,
policy_id=self.POLICY_ID,
)
)

mock_token_manager_get.assert_not_called()
mock_base_request_post.assert_not_called()
Expand All @@ -594,15 +600,15 @@ def test_register_payment_with_valid_location_should_work(
self.ACCOUNT_ID,
location=self.LOCATION,
policy_id=self.POLICY_ID,
)
)

mock_token_manager_get.assert_called()
mock_base_request_post.assert_called_with(
Endpoints.TRANSACTIONS,
headers=self.AUTH_AND_JSON_CONTENT_HEADERS,
params=self.DEFAULT_PARAMS,
data=self.REGISTER_VALID_PAYMENT_DATA_WITH_LOCATION,
)
)

self.assertEqual(request_response, self.JSON_RESPONSE)

Expand All @@ -621,7 +627,7 @@ def test_register_payment_with_location_and_empty_latitude_should_raise_an_Incog
self.ACCOUNT_ID,
location=self.INVALID_LOCATION_EMPTY_LATITUDE,
policy_id=self.POLICY_ID,
)
)

mock_token_manager_get.assert_not_called()
mock_base_request_post.assert_not_called()
Expand All @@ -641,7 +647,7 @@ def test_register_payment_with_location_and_empty_longitude_should_raise_an_Inco
self.ACCOUNT_ID,
location=self.INVALID_LOCATION_EMPTY_LONGITUDE,
policy_id=self.POLICY_ID,
)
)

mock_token_manager_get.assert_not_called()
mock_base_request_post.assert_not_called()
Expand All @@ -662,7 +668,7 @@ def test_register_payment_with_location_and_wrong_timestamp_should_raise_an_Inco
self.ACCOUNT_ID,
location=self.INVALID_LOCATION_WRONG_TIMESTAMP,
policy_id=self.POLICY_ID,
)
)

mock_token_manager_get.assert_not_called()
mock_base_request_post.assert_not_called()