11import json
22from unittest .mock import patch
33
4+ import grpc
45import pytest
56from google .protobuf import empty_pb2
67from sqlalchemy import select
@@ -21,13 +22,23 @@ def _(testconfig):
2122 pass
2223
2324
25+ def test_donations_disabled (db , feature_flags ):
26+ feature_flags .set ("donations_enabled" , False )
27+ _ , token = generate_user ()
28+
29+ with donations_session (token ) as donations :
30+ with pytest .raises (grpc .RpcError ) as e :
31+ donations .InitiateDonation (donations_pb2 .InitiateDonationReq (amount = 100 ))
32+ assert e .value .code () == grpc .StatusCode .UNAVAILABLE
33+ assert e .value .details () == "Donations are currently disabled."
34+
35+
2436def test_one_time_donation_flow (db , monkeypatch ):
2537 user , token = generate_user ()
2638 user_email = user .email
2739 user_id = user .id
2840
2941 new_config = config .copy ()
30- new_config ["ENABLE_DONATIONS" ] = True
3142 new_config ["STRIPE_API_KEY" ] = "dummy_api_key"
3243 new_config ["STRIPE_WEBHOOK_SECRET" ] = "dummy_webhook_secret"
3344 new_config ["STRIPE_RECURRING_PRODUCT_ID" ] = "price_1KIbmbIfR5z29g5kFWPEUnC6"
@@ -132,7 +143,6 @@ def test_recurring_donation_flow(db, monkeypatch):
132143 user_id = user .id
133144
134145 new_config = config .copy ()
135- new_config ["ENABLE_DONATIONS" ] = True
136146 new_config ["STRIPE_API_KEY" ] = "dummy_api_key"
137147 new_config ["STRIPE_WEBHOOK_SECRET" ] = "dummy_webhook_secret"
138148 new_config ["STRIPE_RECURRING_PRODUCT_ID" ] = "price_1IRoHdE5kUmYuPWz9tX8UpRv"
@@ -257,7 +267,6 @@ def test_customer_portal_url(db, monkeypatch):
257267 user_id = user .id
258268
259269 new_config = config .copy ()
260- new_config ["ENABLE_DONATIONS" ] = True
261270 new_config ["STRIPE_API_KEY" ] = "dummy_api_key"
262271
263272 monkeypatch .setattr (couchers .servicers .donations , "config" , new_config )
@@ -376,7 +385,6 @@ def test_slack_notification_on_one_time_donation(db, monkeypatch):
376385 user , token = generate_user ()
377386
378387 new_config = config .copy ()
379- new_config ["ENABLE_DONATIONS" ] = True
380388 new_config ["STRIPE_API_KEY" ] = "dummy_api_key"
381389 new_config ["STRIPE_WEBHOOK_SECRET" ] = "dummy_webhook_secret"
382390 new_config ["STRIPE_RECURRING_PRODUCT_ID" ] = "price_1KIbmbIfR5z29g5kFWPEUnC6"
@@ -407,7 +415,6 @@ def test_slack_notification_on_recurring_donation(db, monkeypatch):
407415 user , token = generate_user ()
408416
409417 new_config = config .copy ()
410- new_config ["ENABLE_DONATIONS" ] = True
411418 new_config ["STRIPE_API_KEY" ] = "dummy_api_key"
412419 new_config ["STRIPE_WEBHOOK_SECRET" ] = "dummy_webhook_secret"
413420 new_config ["STRIPE_RECURRING_PRODUCT_ID" ] = "price_1IRoHdE5kUmYuPWz9tX8UpRv"
0 commit comments