Skip to content

Commit

Permalink
validation for not valid service providers
Browse files Browse the repository at this point in the history
  • Loading branch information
felipao-mx committed Jan 29, 2019
1 parent 65ba23e commit b742d50
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
3 changes: 2 additions & 1 deletion arcusd/daemon/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from ..callbacks import CallbackHelper
from ..contracts.operationinfo import OpInfo
from ..data_access.tasks import update_task_info
from ..exc import UnknownServiceProvider
from ..types import OperationStatus, OperationType, ServiceProvider


Expand All @@ -29,4 +30,4 @@ def mapping(service_provider: str) -> int:
if service_provider in ServiceProvider.__members__:
return ServiceProvider[service_provider].value
else:
raise NotImplemented
raise UnknownServiceProvider(service_provider)
3 changes: 3 additions & 0 deletions arcusd/exc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class UnknownServiceProvider(Exception):
def __init__(self, service_provider: str):
self.message = f'Unknown service provider: {service_provider}'
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
interactions:
- request:
body: '{"biller_id": 2901, "account_number": "1111322016"}'
headers:
Accept: [application/vnd.regalii.v3.1+json]
Accept-Encoding: ['gzip, deflate']
Authorization: ['APIAuth 88879c1b066dc9aea6201f27be2bbba9:+TTf4cRhwxkSwXX4JlnGk/1ePY0=']
Connection: [keep-alive]
Content-Length: ['51']
Content-MD5: [ZkNGR5IItPT5UO5fquuDpg==]
Content-Type: [application/json]
Date: ['Tue, 29 Jan 2019 17:26:20 GMT']
User-Agent: [python-requests/2.20.1]
method: POST
uri: https://api.casiregalii.com/bills
response:
body: {string: '{"code":"R16","message":"Failed to make the consult, please try
again later","id":8393}'}
headers:
Cache-Control: [no-cache]
Connection: [keep-alive]
Content-Type: [application/json; charset=utf-8]
Date: ['Tue, 29 Jan 2019 17:26:21 GMT']
Strict-Transport-Security: [max-age=31536000]
Transfer-Encoding: [chunked]
X-Content-Type-Options: [nosniff]
X-Frame-Options: [SAMEORIGIN]
X-Request-Id: [edc24444-4346-4fba-8a30-0c990eb8c019]
X-Runtime: ['1.061626']
X-XSS-Protection: [1; mode=block]
status: {code: 422, message: Unprocessable Entity}
version: 1
8 changes: 8 additions & 0 deletions tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import arcusd.arcusactions
from arcusd.daemon.tasks import (cancel_transaction, pay_bill, pay_bill_id,
query_bill, topup)
from arcusd.exc import UnknownServiceProvider
from arcusd.types import OperationStatus, OperationType, ServiceProvider


Expand Down Expand Up @@ -186,3 +187,10 @@ def test_cancel_bill(callback_helper):
assert cancel_op_info.status == OperationStatus.success
assert cancel_op_info.operation.transaction_id == transaction.id
assert cancel_op_info.operation.code == 'R0'


def test_invalid_service_provider():
with pytest.raises(UnknownServiceProvider) as exc:
query_bill('abcdfeghijoklmn', 'fake-provider',
'501000000007')
assert exc.value.message == 'Unknown service provider: fake-provider'

0 comments on commit b742d50

Please sign in to comment.