This repository has been archived by the owner on May 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
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
ad3be95
commit c5508ce
Showing
11 changed files
with
299 additions
and
9 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
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 |
---|---|---|
@@ -1 +1 @@ | ||
__VERSION__ = '0.0.1a77' | ||
__VERSION__ = '0.0.1a78' |
Empty file.
3 changes: 3 additions & 0 deletions
3
tests/Functional/Resources/Reports/_fixtures/request/create_basic.json
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,3 @@ | ||
{ | ||
"type": "transactions" | ||
} |
10 changes: 10 additions & 0 deletions
10
tests/Functional/Resources/Reports/_fixtures/request/create_full.json
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,10 @@ | ||
{ | ||
"type": "transactions", | ||
"filters": [ | ||
{ | ||
"name": "updated_at", | ||
"value": "2023-12-30", | ||
"operator": "lt" | ||
} | ||
] | ||
} |
21 changes: 21 additions & 0 deletions
21
tests/Functional/Resources/Reports/_fixtures/response/full_entity.json
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,21 @@ | ||
{ | ||
"data": { | ||
"id": "rep_01hhq4c3b03g3x2kpkj8aecjv6", | ||
"type": "transactions", | ||
"rows": null, | ||
"status": "pending", | ||
"filters": [ | ||
{ | ||
"name": "updated_at", | ||
"value": "2023-12-30", | ||
"operator": "lt" | ||
} | ||
], | ||
"expires_at": null, | ||
"created_at": "2024-01-05T16:18:53.92Z", | ||
"updated_at": "2024-01-05T16:18:53.92Z" | ||
}, | ||
"meta": { | ||
"request_id": "70d20619-e988-41ce-81f3-0c1a6a6136e2" | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
tests/Functional/Resources/Reports/_fixtures/response/list_default.json
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,36 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"id": "rep_01hhq4c3b03g3x2kpkj8aecjv6", | ||
"type": "transactions", | ||
"rows": 10, | ||
"status": "ready", | ||
"filters": [ | ||
{ | ||
"name": "updated_at", | ||
"value": "2023-12-30", | ||
"operator": "lt" | ||
}, | ||
{ | ||
"name": "collection_mode", | ||
"value": [ | ||
"manual" | ||
], | ||
"operator": null | ||
} | ||
], | ||
"expires_at": "2024-02-05T16:18:53.92Z", | ||
"created_at": "2024-01-05T16:18:53.92Z", | ||
"updated_at": "2024-01-05T16:18:53.92Z" | ||
} | ||
], | ||
"meta": { | ||
"request_id": "31858add-0308-4c26-90fb-266e16be0c8c", | ||
"pagination": { | ||
"per_page": 50, | ||
"next": "https://api.paddle.com/reports?after=rep_01hhq4c3b03g3x2kpkj8aecjv6", | ||
"has_more": false, | ||
"estimated_total": 1 | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
tests/Functional/Resources/Reports/_fixtures/response/report_csv_entity.json
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,8 @@ | ||
{ | ||
"data": { | ||
"url": "https://reports.paddle.com/transactions-10889-2023-12-05-17-44-51.csv" | ||
}, | ||
"meta": { | ||
"request_id": "f34d4a9c-2088-447d-a3a1-1da5ce74f507" | ||
} | ||
} |
203 changes: 203 additions & 0 deletions
203
tests/Functional/Resources/Reports/test_ReportsClient.py
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,203 @@ | ||
from json import loads | ||
from pytest import mark | ||
from urllib.parse import unquote | ||
|
||
from paddle_billing_python_sdk.Entities.Report import Report | ||
from paddle_billing_python_sdk.Entities.ReportCSV import ReportCSV | ||
from paddle_billing_python_sdk.Entities.Reports.ReportFilters import ReportFilters | ||
from paddle_billing_python_sdk.Entities.Reports.ReportName import ReportName | ||
from paddle_billing_python_sdk.Entities.Reports.ReportOperator import ReportOperator | ||
from paddle_billing_python_sdk.Entities.Reports.ReportStatus import ReportStatus | ||
from paddle_billing_python_sdk.Entities.Reports.ReportType import ReportType | ||
|
||
from paddle_billing_python_sdk.Entities.Collections.ReportCollection import ReportCollection | ||
|
||
from paddle_billing_python_sdk.Resources.Reports.Operations.CreateReport import CreateReport | ||
from paddle_billing_python_sdk.Resources.Reports.Operations.ListReports import ListReports | ||
from paddle_billing_python_sdk.Resources.Shared.Operations.List.Pager import Pager | ||
|
||
from tests.Utils.TestClient import mock_requests, test_client | ||
from tests.Utils.ReadsFixture import ReadsFixtures | ||
|
||
|
||
class TestReportsClient: | ||
@mark.parametrize( | ||
'operation, expected_request_body, expected_response_status, expected_response_body, expected_url', | ||
[ | ||
( | ||
CreateReport(type=ReportType.Transactions), | ||
ReadsFixtures.read_raw_json_fixture('request/create_basic'), | ||
200, | ||
ReadsFixtures.read_raw_json_fixture('response/full_entity'), | ||
'/reports', | ||
), ( | ||
CreateReport( | ||
type = ReportType.Transactions, | ||
filters = [ReportFilters(name=ReportName.UpdatedAt, operator=ReportOperator.Lt, value='2023-12-30')], | ||
), | ||
ReadsFixtures.read_raw_json_fixture('request/create_full'), | ||
200, | ||
ReadsFixtures.read_raw_json_fixture('response/full_entity'), | ||
'/reports', | ||
), | ||
], | ||
ids=[ | ||
"Create report with basic data", | ||
"Create report with filters", | ||
], | ||
) | ||
def test_create_report_uses_expected_payload( | ||
self, | ||
test_client, | ||
mock_requests, | ||
operation, | ||
expected_request_body, | ||
expected_response_status, | ||
expected_response_body, | ||
expected_url, | ||
): | ||
expected_url = f"{test_client.base_url}{expected_url}" | ||
mock_requests.post(expected_url, status_code=expected_response_status, text=expected_response_body) | ||
|
||
response = test_client.client.reports.create(operation) | ||
response_json = test_client.client.reports.response.json() | ||
request_json = test_client.client.payload | ||
last_request = mock_requests.last_request | ||
|
||
assert isinstance(response, Report) | ||
assert last_request is not None | ||
assert last_request.method == 'POST' | ||
assert test_client.client.status_code == expected_response_status | ||
assert unquote(last_request.url) == expected_url, \ | ||
"The URL does not match the expected URL, verify the query string is correct" | ||
assert loads(request_json) == loads(expected_request_body), \ | ||
"The request JSON doesn't match the expected fixture JSON" | ||
assert response_json == loads(str(expected_response_body)), \ | ||
"The response JSON doesn't match the expected fixture JSON" | ||
|
||
|
||
@mark.parametrize( | ||
'operation, expected_response_status, expected_response_body, expected_url', | ||
[ | ||
( | ||
ListReports(), | ||
200, | ||
ReadsFixtures.read_raw_json_fixture('response/list_default'), | ||
'/reports', | ||
), ( | ||
ListReports(Pager()), | ||
200, | ||
ReadsFixtures.read_raw_json_fixture('response/list_default'), | ||
'/reports?order_by=id[asc]&per_page=50', | ||
), ( | ||
ListReports(Pager(after='rep_01hhq4c3b03g3x2kpkj8aecjv6')), | ||
200, | ||
ReadsFixtures.read_raw_json_fixture('response/list_default'), | ||
'/reports?after=rep_01hhq4c3b03g3x2kpkj8aecjv6&order_by=id[asc]&per_page=50', | ||
), ( | ||
ListReports(statuses=[ReportStatus.Ready]), | ||
200, | ||
ReadsFixtures.read_raw_json_fixture('response/list_default'), | ||
'/reports?status=ready', | ||
), | ||
], | ||
ids=[ | ||
"List reports without pagination", | ||
"List reports with default pagination", | ||
"List paginated reports after specified report id", | ||
"List reports filtered by status", | ||
], | ||
) | ||
def test_list_reports_returns_expected_response( | ||
self, | ||
test_client, | ||
mock_requests, | ||
operation, | ||
expected_response_status, | ||
expected_response_body, | ||
expected_url, | ||
): | ||
expected_url = f"{test_client.base_url}{expected_url}" | ||
mock_requests.get(expected_url, status_code=expected_response_status) | ||
|
||
response = test_client.client.reports.list(operation) | ||
last_request = mock_requests.last_request | ||
|
||
assert isinstance(response, ReportCollection) | ||
assert last_request is not None | ||
assert last_request.method == 'GET' | ||
assert test_client.client.status_code == expected_response_status | ||
assert unquote(last_request.url) == expected_url, \ | ||
"The URL does not match the expected URL, verify the query string is correct" | ||
|
||
|
||
@mark.parametrize( | ||
'report_id, expected_response_status, expected_response_body, expected_url', | ||
[( | ||
'rep_01hhq4c3b03g3x2kpkj8aecjv6', | ||
200, | ||
ReadsFixtures.read_raw_json_fixture('response/full_entity'), | ||
'/reports/rep_01hhq4c3b03g3x2kpkj8aecjv6', | ||
)], | ||
ids=["Get a report by its id"], | ||
) | ||
def test_get_report_returns_expected_response( | ||
self, | ||
test_client, | ||
mock_requests, | ||
report_id, | ||
expected_response_status, | ||
expected_response_body, | ||
expected_url, | ||
): | ||
expected_url = f"{test_client.base_url}{expected_url}" | ||
mock_requests.get(expected_url, status_code=expected_response_status, text=expected_response_body) | ||
|
||
response = test_client.client.reports.get(report_id) | ||
response_json = test_client.client.reports.response.json() | ||
last_request = mock_requests.last_request | ||
|
||
assert isinstance(response, Report) | ||
assert last_request is not None | ||
assert last_request.method == 'GET' | ||
assert test_client.client.status_code == expected_response_status | ||
assert unquote(last_request.url) == expected_url, \ | ||
"The URL does not match the expected URL, verify the query string is correct" | ||
assert response_json == loads(str(expected_response_body)), \ | ||
"The response JSON generated by ResponseParser() doesn't match the expected fixture JSON" | ||
|
||
|
||
@mark.parametrize( | ||
'report_id, expected_response_status, expected_response_body, expected_url', | ||
[( | ||
'rep_01hhq4c3b03g3x2kpkj8aecjv6', | ||
200, | ||
ReadsFixtures.read_raw_json_fixture('response/report_csv_entity'), | ||
'/reports/rep_01hhq4c3b03g3x2kpkj8aecjv6/download-url', | ||
)], | ||
ids=["Get a report csv by its id"], | ||
) | ||
def test_get_report_csv_returns_expected_response( | ||
self, | ||
test_client, | ||
mock_requests, | ||
report_id, | ||
expected_response_status, | ||
expected_response_body, | ||
expected_url, | ||
): | ||
expected_url = f"{test_client.base_url}{expected_url}" | ||
mock_requests.get(expected_url, status_code=expected_response_status, text=expected_response_body) | ||
|
||
response = test_client.client.reports.get_report_csv(report_id) | ||
response_json = test_client.client.reports.response.json() | ||
last_request = mock_requests.last_request | ||
|
||
assert isinstance(response, ReportCSV) | ||
assert last_request is not None | ||
assert last_request.method == 'GET' | ||
assert test_client.client.status_code == expected_response_status | ||
assert unquote(last_request.url) == expected_url, \ | ||
"The URL does not match the expected URL, verify the query string is correct" | ||
assert response_json == loads(str(expected_response_body)), \ | ||
"The response JSON generated by ResponseParser() doesn't match the expected fixture JSON" |