From d2f23ae6c8bb92ed72f135edc1eb5f593067d4bb Mon Sep 17 00:00:00 2001 From: Colin Maudry Date: Mon, 29 Jun 2026 16:53:19 +0200 Subject: [PATCH] =?UTF-8?q?Am=C3=A9lioration=20des=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/subscriptions/conftest.py | 4 +-- tests/subscriptions/test_client.py | 32 ++++++++++-------- tests/subscriptions/test_compte_abonnement.py | 2 +- tests/subscriptions/test_routes.py | 25 ++++++++------ tests/users.test.sqlite | Bin 53248 -> 61440 bytes 5 files changed, 35 insertions(+), 28 deletions(-) diff --git a/tests/subscriptions/conftest.py b/tests/subscriptions/conftest.py index 4563f68..58e3ff2 100644 --- a/tests/subscriptions/conftest.py +++ b/tests/subscriptions/conftest.py @@ -6,9 +6,9 @@ import pytest # unitaires de pages (pas besoin du serveur complet — juste que CONFIG soit peuplé). from dash import Dash as _Dash -from src.pages import compte_abonnement # noqa: F401 +_Dash(__name__, use_pages=True, pages_folder="", assets_folder="assets") -_Dash(__name__, assets_folder="assets") +from src.pages import compte_abonnement # noqa: F401, E402 # doit venir après Dash() class FakeResponse: diff --git a/tests/subscriptions/test_client.py b/tests/subscriptions/test_client.py index 011e727..9878ecd 100644 --- a/tests/subscriptions/test_client.py +++ b/tests/subscriptions/test_client.py @@ -5,29 +5,27 @@ from src.subscriptions import client def test_auth_and_base_url_used(fake_httpx): fake_httpx["queue"].append(fake_httpx["Response"](200, {"handle": "decpinfo-1"})) - client.get_or_create_customer("decpinfo-1", "a@b.fr") + client.get_customer("decpinfo-1") call = fake_httpx["calls"][0] assert call["url"] == "https://api.test/v1/customer/decpinfo-1" assert call["auth"] == ("priv_test", "") -def test_get_or_create_customer_existing(fake_httpx): +def test_get_customer(fake_httpx): fake_httpx["queue"].append(fake_httpx["Response"](200, {"handle": "decpinfo-1"})) - result = client.get_or_create_customer("decpinfo-1", "a@b.fr") + result = client.get_customer("decpinfo-1") assert result == {"handle": "decpinfo-1"} - assert len(fake_httpx["calls"]) == 1 # pas de POST de création -def test_get_or_create_customer_creates_on_404(fake_httpx): - fake_httpx["queue"].append(fake_httpx["Response"](404, {"error": "not found"})) +def test_update_customer(fake_httpx): fake_httpx["queue"].append(fake_httpx["Response"](200, {"handle": "decpinfo-1"})) - result = client.get_or_create_customer("decpinfo-1", "a@b.fr") - assert result == {"handle": "decpinfo-1"} - assert fake_httpx["calls"][1]["method"] == "POST" - assert fake_httpx["calls"][1]["json"] == {"handle": "decpinfo-1", "email": "a@b.fr"} + client.update_customer("decpinfo-1", {"email": "a@b.fr"}) + call = fake_httpx["calls"][0] + assert call["method"] == "PUT" + assert call["json"] == {"email": "a@b.fr"} -def test_create_subscription_session_returns_url(fake_httpx): +def test_create_subscription_session_with_customer_handle(fake_httpx): fake_httpx["queue"].append( fake_httpx["Response"]( 200, @@ -39,7 +37,10 @@ def test_create_subscription_session_returns_url(fake_httpx): ) ) url = client.create_subscription_session( - "plan_simple", "decpinfo-1", "https://app/ok", "https://app/ko" + "plan_simple", + "https://app/ok", + "https://app/ko", + customer_handle="decpinfo-1", ) assert url == "https://checkout.reepay.com/#/sub-1" body = fake_httpx["calls"][0]["json"] @@ -47,7 +48,6 @@ def test_create_subscription_session_returns_url(fake_httpx): assert body["customer"] == "decpinfo-1" assert body["signup_method"] == "link" assert "prepare_subscription" not in body - assert "accept_url" not in body def test_create_subscription_session_no_trial(fake_httpx): @@ -62,7 +62,11 @@ def test_create_subscription_session_no_trial(fake_httpx): ) ) client.create_subscription_session( - "plan_simple", "decpinfo-1", "https://app/ok", "https://app/ko", no_trial=True + "plan_simple", + "https://app/ok", + "https://app/ko", + no_trial=True, + customer_handle="decpinfo-1", ) assert fake_httpx["calls"][0]["json"]["no_trial"] is True diff --git a/tests/subscriptions/test_compte_abonnement.py b/tests/subscriptions/test_compte_abonnement.py index 2daeda0..e623781 100644 --- a/tests/subscriptions/test_compte_abonnement.py +++ b/tests/subscriptions/test_compte_abonnement.py @@ -29,7 +29,7 @@ def test_active_view_shows_cancel(monkeypatch): "current_period_end": "2099-01-01T00:00:00+00:00", } view = compte_abonnement._active_view(row) - assert "Résilier" in str(view) + assert "Me désabonner" in str(view) def test_active_view_trial_banner(monkeypatch): diff --git a/tests/subscriptions/test_routes.py b/tests/subscriptions/test_routes.py index f2ba6a8..3812fac 100644 --- a/tests/subscriptions/test_routes.py +++ b/tests/subscriptions/test_routes.py @@ -13,13 +13,16 @@ def _sign(secret, timestamp, event_id): def test_subscribe_redirects_to_hosted_url(logged_in_client, monkeypatch): client, uid = logged_in_client - monkeypatch.setattr( - frisbii_client, "get_or_create_customer", lambda h, e: {"handle": h} - ) + monkeypatch.setattr(frisbii_client, "update_customer", lambda h, d: {}) monkeypatch.setattr( frisbii_client, "create_subscription_session", - lambda plan, cust, ok, ko, no_trial=False: "https://pay.test/cs_1", + lambda plan, + ok, + ko, + no_trial=False, + customer_handle=None, + create_customer=None: "https://pay.test/cs_1", ) resp = client.post("/subscriptions/subscribe", data={"plan": "simple"}) assert resp.status_code == 303 @@ -39,11 +42,11 @@ def test_subscribe_disables_trial_after_first_use(logged_in_client, monkeypatch) "decpinfo-%d" % uid, "sub_42", "expired", "2020-01-01T00:00:00+00:00" ) captured = {} - monkeypatch.setattr( - frisbii_client, "get_or_create_customer", lambda h, e: {"handle": h} - ) + monkeypatch.setattr(frisbii_client, "update_customer", lambda h, d: {}) - def fake_session(plan, cust, ok, ko, no_trial=False): + def fake_session( + plan, ok, ko, no_trial=False, customer_handle=None, create_customer=None + ): captured["no_trial"] = no_trial return "https://pay.test/cs_9" @@ -62,10 +65,10 @@ def test_subscribe_unknown_plan(logged_in_client): def test_subscribe_api_error_redirects_with_error(logged_in_client, monkeypatch): client, _ = logged_in_client - def boom(h, e): + def boom(h, d): raise frisbii_client.FrisbiiError(500, "boom") - monkeypatch.setattr(frisbii_client, "get_or_create_customer", boom) + monkeypatch.setattr(frisbii_client, "update_customer", boom) resp = client.post("/subscriptions/subscribe", data={"plan": "simple"}) assert resp.status_code == 302 assert "error=frisbii" in resp.headers["Location"] @@ -139,7 +142,7 @@ def test_subscribe_skips_if_already_active(logged_in_client, monkeypatch): ) called = [] monkeypatch.setattr( - frisbii_client, "get_or_create_customer", lambda h, e: called.append(h) + frisbii_client, "update_customer", lambda h, d: called.append(h) ) resp = client.post("/subscriptions/subscribe", data={"plan": "simple"}) # Doit rediriger vers la page abonnement, sans appeler Frisbii. diff --git a/tests/users.test.sqlite b/tests/users.test.sqlite index 6370d61770f88526c3495620a8a53670c2ed1d3f..a98af71e20d0382cf10ed964fb5baefb350c4991 100644 GIT binary patch delta 585 zcmZozz})bFd4jYc8v_FaKM=zJ|3n>QO*RI--e0`zZ47+O4;c8$c$V>=nIdw7NwRbgt$h8XtpTw zv5Tv#Gj=d;u3|mO$fHnDlvxpNwev-Iaw)jj?Rw#3IJce>gN)MTKDQfY6SD zY~rE%lM{I)REv`{QgajIb2HP65=%1k^NQmQF@*Rhm+^%%+D@EknO!TuF0QZ7*r-{O zn3R)>p%O!Y&l%{T5Lbl|M<*Xw1q^8gjm#9VhZF*WJbfL5A{D${BXtxK3kq^FCvW5s zX4kamViOP61vz!|BL27olN4AunE2}$_;>NwZ59+L;;*-2Vz%}*FfcHRPfSUP2M1An zNq&53acWVqk%5t!u7R1Zk!6UXiIt(5m5GU-iLsfvftj{}ft7)Q3nQ~XNUtGSFEj{2 zx{FJbij#{n3&0_Q*A#xBFB+iAjaopOc`S0N>}R AH~;_u delta 149 zcmZp8z}&Ead4jYcD+2=qFA&23&qN(#RaOSQ-e0_2Y79KA1q^&;Jj-~`aoh7mbNu0N zVQ=FW;o8qyz-7EyP~Z&