SHKeeper
This commit is contained in:
@@ -8,6 +8,7 @@ from django.test import TransactionTestCase, override_settings
|
||||
|
||||
from members.billing import sync_account
|
||||
from members.models import Account, ManagedGroup
|
||||
from members.models import CryptoInvoice
|
||||
|
||||
|
||||
@skipUnless(connection.vendor == "postgresql", "Requires real PostgreSQL row locks")
|
||||
@@ -53,3 +54,27 @@ class PostgreSQLLockTests(TransactionTestCase):
|
||||
# A later failed external side effect rolls back its own transaction,
|
||||
# not the previously committed record of the managed group.
|
||||
self.assertEqual(ManagedGroup.objects.get(account=self.account).dn, "cn=paid,dc=example,dc=org")
|
||||
|
||||
@override_settings(SHKEEPER_ENABLED=True, MEMBERSHIP_TIERS={"test": {"group_dn": "cn=paid,dc=example,dc=org"}})
|
||||
def test_concurrent_crypto_verification_credits_one_month(self):
|
||||
invoice = CryptoInvoice.objects.create(account=self.account, tier="test", usd_amount="5.00", crypto="BTC", provider_id="61", wallet="test-wallet", crypto_amount="0.0001", status="UNPAID")
|
||||
data = {"status": "success", "invoices": [{"external_id": f"www-membership-{invoice.pk}", "fiat": "USD", "amount_fiat": "5.00", "balance_fiat": "5.00", "status": "PAID", "txs": [{"addr": "test-wallet", "crypto": "BTC", "status": "CONFIRMED", "txid": "tx-confirmed", "amount": "0.0001"}]}]}
|
||||
|
||||
def verify():
|
||||
close_old_connections()
|
||||
try:
|
||||
return sync_account(self.account.pk)
|
||||
finally:
|
||||
close_old_connections()
|
||||
|
||||
from members.shkeeper import add_month
|
||||
|
||||
with patch("members.shkeeper.request", return_value=data), patch("members.billing.reconcile_groups", return_value=self.account.ldap_dn):
|
||||
with ThreadPoolExecutor(max_workers=2) as pool:
|
||||
results = list(pool.map(lambda _: verify(), range(2)))
|
||||
self.assertTrue(all(results))
|
||||
invoice.refresh_from_db()
|
||||
self.assertIsNotNone(invoice.credited_at)
|
||||
assert invoice.access_start is not None
|
||||
self.assertEqual(invoice.access_end, add_month(invoice.access_start))
|
||||
self.assertEqual(CryptoInvoice.objects.count(), 1)
|
||||
|
||||
Reference in New Issue
Block a user