Skip to content

Commit

Permalink
Adds support for Reports (CS2)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinseco committed Oct 24, 2022
1 parent 0206be2 commit c8cae78
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 2 deletions.
2 changes: 2 additions & 0 deletions checkout_sdk/checkout_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from checkout_sdk.tokens.tokens_client import TokensClient
from checkout_sdk.transfers.transfers_client import TransfersClient
from checkout_sdk.workflows.workflows_client import WorkflowsClient
from checkout_sdk.reports.reports_client import ReportsClient


def _base_api_client(configuration: CheckoutConfiguration) -> ApiClient:
Expand Down Expand Up @@ -56,3 +57,4 @@ def __init__(self, configuration: CheckoutConfiguration):
self.accounts = AccountsClient(api_client=base_api_client,
files_client=_files_api_client(configuration),
configuration=configuration)
self.reports = ReportsClient(api_client=base_api_client, configuration=configuration)
2 changes: 2 additions & 0 deletions checkout_sdk/oauth_scopes.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class OAuthScopes(str, Enum):
TRANSFERS_VIEW = 'transfers:view'
BALANCES = 'balances'
BALANCES_VIEW = 'balances:view'
REPORTING = 'reporting'
REPORTING_VIEW = 'reporting:view'

MIDDLEWARE = 'middleware'
MIDDLEWARE_MERCHANTS_SECRET = 'middleware:merchants-secret'
Expand Down
Empty file.
9 changes: 9 additions & 0 deletions checkout_sdk/reports/reports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from datetime import datetime


class ReportsQuery:
created_after: datetime
created_before: datetime
entity_id: str
limit: int
pagination_token: str
23 changes: 23 additions & 0 deletions checkout_sdk/reports/reports_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from __future__ import absolute_import

from checkout_sdk.api_client import ApiClient
from checkout_sdk.authorization_type import AuthorizationType
from checkout_sdk.checkout_configuration import CheckoutConfiguration
from checkout_sdk.client import Client
from checkout_sdk.reports.reports import ReportsQuery


class ReportsClient(Client):
__REPORTS_PATH = 'reports'
__FILES_PATH = 'files'

def __init__(self, api_client: ApiClient, configuration: CheckoutConfiguration):
super().__init__(api_client=api_client,
configuration=configuration,
authorization_type=AuthorizationType.SECRET_KEY_OR_OAUTH)

def get_all_reports(self, query: ReportsQuery):
return self._api_client.get(self.__REPORTS_PATH, self._sdk_authorization(), query)

def get_report_details(self, report_id: str):
return self._api_client.get(self.build_path(self.__REPORTS_PATH, report_id), self._sdk_authorization())
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def oauth_api():
.http_client_builder(CustomHttpClientBuilder()) \
.scopes([OAuthScopes.GATEWAY, OAuthScopes.VAULT, OAuthScopes.PAYOUTS_BANK_DETAILS,
OAuthScopes.SESSIONS_APP, OAuthScopes.SESSIONS_BROWSER, OAuthScopes.FX, OAuthScopes.MARKETPLACE,
OAuthScopes.FILES, OAuthScopes.TRANSFERS, OAuthScopes.BALANCES_VIEW]) \
OAuthScopes.FILES, OAuthScopes.TRANSFERS, OAuthScopes.BALANCES_VIEW, OAuthScopes.REPORTING]) \
.build()


Expand Down
2 changes: 1 addition & 1 deletion tests/payments/request_apm_payments_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def test_should_make_stc_pay_payment(default_api):
payment_request.customer = customer_request

check_error_item(callback=default_api.payments.request_payment,
error_item=APM_SERVICE_UNAVAILABLE,
error_item='merchant_data_delegated_authentication_failed',
payment_request=payment_request)


Expand Down
20 changes: 20 additions & 0 deletions tests/reports/reports_client_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pytest

from checkout_sdk.reports.reports import ReportsQuery
from checkout_sdk.reports.reports_client import ReportsClient


@pytest.fixture(scope='class')
def client(mock_sdk_configuration, mock_api_client):
return ReportsClient(api_client=mock_api_client, configuration=mock_sdk_configuration)


class TestReportsClient:

def test_should_get_all_reports(self, mocker, client: ReportsClient):
mocker.patch('checkout_sdk.api_client.ApiClient.get', return_value='response')
assert client.get_all_reports(ReportsQuery()) == 'response'

def test_should_get_report_details(self, mocker, client: ReportsClient):
mocker.patch('checkout_sdk.api_client.ApiClient.get', return_value='response')
assert client.get_report_details('report_id') == 'response'
63 changes: 63 additions & 0 deletions tests/reports/reports_integration_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from __future__ import absolute_import

from datetime import datetime, timezone

from dateutil.relativedelta import relativedelta

from checkout_sdk.reports.reports import ReportsQuery
from tests.checkout_test_utils import assert_response


__query = ReportsQuery()
__query.created_after = datetime.now(timezone.utc) - relativedelta(days=7)
__query.created_before = datetime.now(timezone.utc)


def test_should_get_all_reports(default_api):
response = default_api.reports.get_all_reports(__query)
assert_response(response,
'http_metadata',
'count',
'limit',
'data',
'_links')

if response.data:
reports = response.data
for report in reports:
assert_response(report,
'id',
'created_on',
'type',
'description',
'account',
'from',
'to')


def test_should_get_report_details(default_api):
response = default_api.reports.get_all_reports(__query)
assert_response(response,
'http_metadata',
'count',
'limit',
'data',
'_links')

if response.data:
report = response.data[0]

details = default_api.reports.get_report_details(report.id)
assert_response(details,
'id',
'created_on',
'type',
'description',
'account',
'from',
'to')

assert report.id == details.id
assert report.created_on == details.created_on
assert report.type == details.type
assert report.description == details.description

0 comments on commit c8cae78

Please sign in to comment.