-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0206be2
commit c8cae78
Showing
9 changed files
with
121 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |