Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
rjambrecic committed May 14, 2024
1 parent 5a9d1ca commit d72d99e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from captn.google_ads.client import (
ALREADY_AUTHENTICATED,
AUTHENTICATION_ERROR,
FIELDS_ARE_NOT_MENTIONED_ERROR_MSG,
NOT_APPROVED,
NOT_IN_QUESTION_ANSWER_LIST,
Expand Down Expand Up @@ -149,7 +150,21 @@ def test_google_ads_create_update_raises_error() -> None:
)


def test_execute_query_when_acount_isnt_acivated() -> None:
@pytest.mark.parametrize(
"error_message", ["account_not_enabled", "authentication_error"]
)
def test_execute_query_when_google_ads_api_raises_error(error_message) -> None:
error_dict = {
"account_not_enabled": {
"content": b'{"detail":"(<_InactiveRpcError of RPC that terminated with:\\n\\tstatus = StatusCode.PERMISSION_DENIED\\n\\tdetails = \\"The caller does not have permission\\"\\n\\tdebug_error_string = \\"UNKNOWN:Error received from peer {created_time:\\"2024-05-14T10:33:11\\", grpc_status:7, grpc_message:\\"The caller does not have permission\\"}\\"\\n>, <_InactiveRpcError of RPC that terminated with:\\n\\tstatus = StatusCode.PERMISSION_DENIED\\n\\tdetails = \\"The caller does not have permission\\"\\n\\tdebug_error_string = \\"UNKNOWN:Error received from peer ipv4:142.250.184.138:443 {created_time:\\"2024-05-14T10:33:11\\", grpc_status:7, grpc_message:\\"The caller does not have permission\\"}\\"\\n>, errors {\\n error_code {\\n authorization_error: CUSTOMER_NOT_ENABLED\\n }\\n message: \\"The customer account can\\\\\'t be accessed because it is not yet enabled or has been deactivated.\\"})"}',
"excepted_substr": "If you have just created the account, please wait for a few hours before trying again.",
},
"authentication_error": {
"content": b'{"detail":"Please try to execute the command again."}',
"excepted_substr": AUTHENTICATION_ERROR,
},
}

with (
unittest.mock.patch(
"captn.google_ads.client.get_login_url",
Expand All @@ -161,11 +176,12 @@ def test_execute_query_when_acount_isnt_acivated() -> None:
):
response = Response()
response.status_code = 500
response._content = b'{"detail":"(<_InactiveRpcError of RPC that terminated with:\\n\\tstatus = StatusCode.PERMISSION_DENIED\\n\\tdetails = \\"The caller does not have permission\\"\\n\\tdebug_error_string = \\"UNKNOWN:Error received from peer {created_time:\\"2024-05-14T10:33:11\\", grpc_status:7, grpc_message:\\"The caller does not have permission\\"}\\"\\n>, <_InactiveRpcError of RPC that terminated with:\\n\\tstatus = StatusCode.PERMISSION_DENIED\\n\\tdetails = \\"The caller does not have permission\\"\\n\\tdebug_error_string = \\"UNKNOWN:Error received from peer ipv4:142.250.184.138:443 {created_time:\\"2024-05-14T10:33:11\\", grpc_status:7, grpc_message:\\"The caller does not have permission\\"}\\"\\n>, errors {\\n error_code {\\n authorization_error: CUSTOMER_NOT_ENABLED\\n }\\n message: \\"The customer account can\\\\\'t be accessed because it is not yet enabled or has been deactivated.\\"})"}'
response._content = error_dict[error_message]["content"]
mock_requests_get.return_value = response

with pytest.raises(ValueError) as exc_info:
execute_query(user_id=-1, conv_id=-1)

excepted_substr = "If you have just created the account, please wait for a few hours before trying again."
assert excepted_substr in exc_info.value.args[0], exc_info.value.args[0]
assert (
error_dict[error_message]["excepted_substr"] in exc_info.value.args[0]
), exc_info.value.args[0]
32 changes: 0 additions & 32 deletions tests/ci/test_google_ads_client.py

This file was deleted.

0 comments on commit d72d99e

Please sign in to comment.