|
| 1 | +import os |
| 2 | + |
| 3 | +import pytest |
| 4 | +from pytest_httpx import HTTPXMock |
| 5 | + |
| 6 | +from lago_python_client.client import Client |
| 7 | +from lago_python_client.exceptions import LagoApiError |
| 8 | + |
| 9 | + |
| 10 | +def mock_response(): |
| 11 | + this_dir = os.path.dirname(os.path.abspath(__file__)) |
| 12 | + data_path = os.path.join(this_dir, "fixtures/payment_receipt.json") |
| 13 | + |
| 14 | + with open(data_path, "rb") as payment_receipt_response: |
| 15 | + return payment_receipt_response.read() |
| 16 | + |
| 17 | + |
| 18 | +def mock_collection_response(): |
| 19 | + current_dir = os.path.dirname(os.path.abspath(__file__)) |
| 20 | + data_path = os.path.join(current_dir, "fixtures/payment_receipt_index.json") |
| 21 | + |
| 22 | + with open(data_path, "rb") as payment_receipts_response: |
| 23 | + return payment_receipts_response.read() |
| 24 | + |
| 25 | + |
| 26 | +def test_valid_find_all_payment_receipts_request(httpx_mock: HTTPXMock): |
| 27 | + client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d") |
| 28 | + |
| 29 | + httpx_mock.add_response( |
| 30 | + method="GET", |
| 31 | + url="https://api.getlago.com/api/v1/payment_receipts", |
| 32 | + content=mock_collection_response(), |
| 33 | + ) |
| 34 | + response = client.payment_receipts.find_all() |
| 35 | + |
| 36 | + assert response["payment_receipts"][0].lago_id == "89b6b61e-4dbc-4307-ac96-4abcfa9e3e2d" |
| 37 | + assert response["meta"]["current_page"] == 1 |
| 38 | + |
| 39 | + |
| 40 | +def test_valid_find_all_payment_receipts_request_with_options(httpx_mock: HTTPXMock): |
| 41 | + client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d") |
| 42 | + |
| 43 | + httpx_mock.add_response( |
| 44 | + method="GET", |
| 45 | + url="https://api.getlago.com/api/v1/payment_receipts?per_page=2&page=1", |
| 46 | + content=mock_collection_response(), |
| 47 | + ) |
| 48 | + response = client.payment_receipts.find_all({"per_page": 2, "page": 1}) |
| 49 | + |
| 50 | + assert response["payment_receipts"][0].lago_id == "89b6b61e-4dbc-4307-ac96-4abcfa9e3e2d" |
| 51 | + assert response["meta"]["current_page"] == 1 |
| 52 | + |
| 53 | + |
| 54 | +def test_invalid_find_all_payment_receipts_request(httpx_mock: HTTPXMock): |
| 55 | + client = Client(api_key="invalid") |
| 56 | + |
| 57 | + httpx_mock.add_response( |
| 58 | + method="GET", |
| 59 | + url="https://api.getlago.com/api/v1/payment_receipts", |
| 60 | + status_code=404, |
| 61 | + content=b"", |
| 62 | + ) |
| 63 | + |
| 64 | + with pytest.raises(LagoApiError): |
| 65 | + client.payment_receipts.find_all() |
0 commit comments