Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lago_python_client/models/fixed_charge.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class FixedChargePropertiesResponse(BaseResponseModel):
class FixedChargeResponse(BaseResponseModel):
lago_id: str
lago_add_on_id: str
invoice_display_name: str
invoice_display_name: Optional[str]
add_on_code: str
created_at: str
code: Optional[str]
Expand Down
39 changes: 39 additions & 0 deletions tests/test_plan_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import os

import pytest
Expand Down Expand Up @@ -290,6 +291,26 @@ def test_valid_find_plan_request(httpx_mock: HTTPXMock):
assert response.minimum_commitment.amount_cents == 1000


def test_valid_find_plan_request_with_fixed_charge_without_invoice_display_name(httpx_mock: HTTPXMock):
client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d")
code = "plan_code"
plan_body = json.loads(mock_response())
fixed_charge = json.loads(mock_plan_fixed_charge_response())["fixed_charge"]
fixed_charge["invoice_display_name"] = None
plan_body["plan"]["fixed_charges"] = [fixed_charge]

httpx_mock.add_response(
method="GET",
url="https://api.getlago.com/api/v1/plans/" + code,
json=plan_body,
)
response = client.plans.find(code)

assert response.invoice_display_name == "test plan 1"
assert response.fixed_charges.__root__[0].lago_id == "fc901a90-1a90-1a90-1a90-1a901a901a90"
assert response.fixed_charges.__root__[0].invoice_display_name is None


def test_invalid_find_plan_request(httpx_mock: HTTPXMock):
client = Client(api_key="invalid")
code = "invalid"
Expand Down Expand Up @@ -643,6 +664,24 @@ def test_valid_find_fixed_charge_request(httpx_mock: HTTPXMock):
assert response.properties.amount == "500"


def test_valid_find_fixed_charge_request_without_invoice_display_name(httpx_mock: HTTPXMock):
client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d")
plan_code = "plan_code"
fixed_charge_code = "fixed_setup"
body = json.loads(mock_plan_fixed_charge_response())
body["fixed_charge"]["invoice_display_name"] = None

httpx_mock.add_response(
method="GET",
url="https://api.getlago.com/api/v1/plans/" + plan_code + "/fixed_charges/" + fixed_charge_code,
json=body,
)
response = client.plan_fixed_charges.find(plan_code, fixed_charge_code)

assert response.lago_id == "fc901a90-1a90-1a90-1a90-1a901a901a90"
assert response.invoice_display_name is None


def test_valid_create_fixed_charge_request(httpx_mock: HTTPXMock):
client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d")
plan_code = "plan_code"
Expand Down
39 changes: 39 additions & 0 deletions tests/test_subscription_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import os

import httpx
Expand Down Expand Up @@ -460,6 +461,25 @@ def test_valid_find_all_fixed_charges_request(httpx_mock: HTTPXMock):
assert response["meta"]["current_page"] == 1


def test_valid_find_all_fixed_charges_request_without_invoice_display_name(httpx_mock: HTTPXMock):
client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d")
external_id = "sub_external_123"
body = json.loads(mock_fixed_charges_response())
body["fixed_charges"][0]["invoice_display_name"] = None

httpx_mock.add_response(
method="GET",
url="https://api.getlago.com/api/v1/subscriptions/" + external_id + "/fixed_charges",
json=body,
)
response = client.subscription_fixed_charges.find_all(external_id)

assert len(response["fixed_charges"]) == 2
assert response["fixed_charges"][0].lago_id == "1a901a90-1a90-1a90-1a90-1a901a901a90"
assert response["fixed_charges"][0].invoice_display_name is None
assert response["meta"]["current_page"] == 1


def test_invalid_find_all_fixed_charges_request(httpx_mock: HTTPXMock):
client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d")
external_id = "invalid_sub"
Expand Down Expand Up @@ -741,6 +761,25 @@ def test_valid_update_fixed_charge_request(httpx_mock: HTTPXMock):
assert response.lago_id == "fc901a90-1a90-1a90-1a90-1a901a901a90"


def test_valid_update_fixed_charge_request_without_invoice_display_name(httpx_mock: HTTPXMock):
client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d")
external_id = "sub_external_123"
fixed_charge_code = "fixed_setup"
response_body = json.loads(mock_subscription_fixed_charge_response())
response_body["fixed_charge"]["invoice_display_name"] = None

httpx_mock.add_response(
method="PUT",
url="https://api.getlago.com/api/v1/subscriptions/" + external_id + "/fixed_charges/" + fixed_charge_code,
json=response_body,
)
fixed_charge = FixedCharge(units=20, apply_units_immediately=True)
response = client.subscription_fixed_charges.update(external_id, fixed_charge_code, fixed_charge)

assert response.lago_id == "fc901a90-1a90-1a90-1a90-1a901a901a90"
assert response.invoice_display_name is None


# --- Charge Filters ---


Expand Down
Loading