Skip to content
Snippets Groups Projects
Commit 32479b4e authored by Jean-Paul Calderone's avatar Jean-Paul Calderone
Browse files

Verify that double spent vouchers appears as such in the view

parent e251f187
No related branches found
No related tags found
1 merge request!63Expose voucher state
...@@ -186,6 +186,15 @@ def client_dummyredeemer_configurations(): ...@@ -186,6 +186,15 @@ def client_dummyredeemer_configurations():
}) })
def client_doublespendredeemer_configurations():
"""
Build DummyRedeemer-using configuration values for the client-side plugin.
"""
return just({
u"redeemer": u"double-spend",
})
def client_nonredeemer_configurations(): def client_nonredeemer_configurations():
""" """
Build NonRedeemer-using configuration values for the client-side plugin. Build NonRedeemer-using configuration values for the client-side plugin.
......
...@@ -122,6 +122,7 @@ from ..resource import ( ...@@ -122,6 +122,7 @@ from ..resource import (
from .strategies import ( from .strategies import (
tahoe_configs, tahoe_configs,
client_doublespendredeemer_configurations,
client_dummyredeemer_configurations, client_dummyredeemer_configurations,
client_nonredeemer_configurations, client_nonredeemer_configurations,
vouchers, vouchers,
...@@ -594,30 +595,75 @@ class VoucherTests(TestCase): ...@@ -594,30 +595,75 @@ class VoucherTests(TestCase):
) )
@given(tahoe_configs(client_nonredeemer_configurations()), datetimes(), vouchers()) @given(tahoe_configs(client_nonredeemer_configurations()), datetimes(), vouchers())
def test_get_known_voucher_unredeemed(self, get_config, now, voucher): def test_get_known_voucher_pending(self, get_config, now, voucher):
""" """
When a voucher is first ``PUT`` and then later a ``GET`` is issued for the When a voucher is first ``PUT`` and then later a ``GET`` is issued for the
same voucher then the response code is **OK** and details about the same voucher then the response code is **OK** and details, including
voucher are included in a json-encoded response body. those relevant to a voucher which is still pending redemption, about
the voucher are included in a json-encoded response body.
""" """
return self._test_get_known_voucher(get_config, now, voucher, False) return self._test_get_known_voucher(
get_config,
now,
voucher,
MatchesStructure(
number=Equals(voucher),
created=Equals(now),
state=Equals(u"pending"),
token_count=Is(None),
),
)
@given(tahoe_configs(client_dummyredeemer_configurations()), datetimes(), vouchers()) @given(tahoe_configs(client_dummyredeemer_configurations()), datetimes(), vouchers())
def test_get_known_voucher_redeemed(self, get_config, now, voucher): def test_get_known_voucher_redeemed(self, get_config, now, voucher):
""" """
When a voucher is first ``PUT`` and then later a ``GET`` is issued for the When a voucher is first ``PUT`` and then later a ``GET`` is issued for the
same voucher then the response code is **OK** and details about the same voucher then the response code is **OK** and details, including
voucher are included in a json-encoded response body. those relevant to a voucher which has been redeemed, about the voucher
are included in a json-encoded response body.
""" """
return self._test_get_known_voucher(get_config, now, voucher, True) return self._test_get_known_voucher(
get_config,
now,
voucher,
MatchesStructure(
number=Equals(voucher),
created=Equals(now),
state=Equals(u"redeemed"),
# Value duplicated from PaymentController.redeem default.
# Should do this better.
token_count=Equals(100),
),
)
def _test_get_known_voucher(self, get_config, now, voucher, redeemed): @given(tahoe_configs(client_doublespendredeemer_configurations()), datetimes(), vouchers())
def test_get_known_voucher_doublespend(self, get_config, now, voucher):
"""
When a voucher is first ``PUT`` and then later a ``GET`` is issued for the
same voucher then the response code is **OK** and details, including
those relevant to a voucher which has failed redemption because it was
already redeemed, about the voucher are included in a json-encoded
response body.
"""
return self._test_get_known_voucher(
get_config,
now,
voucher,
MatchesStructure(
number=Equals(voucher),
created=Equals(now),
state=Equals(u"double-spend"),
token_count=Is(None),
),
)
def _test_get_known_voucher(self, get_config, now, voucher, voucher_matcher):
""" """
Assert that a voucher that is ``PUT`` and then ``GET`` is represented in Assert that a voucher that is ``PUT`` and then ``GET`` is represented in
the JSON response. the JSON response.
:param bool redeemed: Whether the voucher is expected to be redeemed :param voucher_matcher: A matcher which matches the voucher expected
or not in the response. to be returned by the ``GET``.
""" """
tempdir = self.useFixture(TempDir()) tempdir = self.useFixture(TempDir())
config = get_config(tempdir.join(b"tahoe"), b"tub.port") config = get_config(tempdir.join(b"tahoe"), b"tub.port")
...@@ -649,13 +695,6 @@ class VoucherTests(TestCase): ...@@ -649,13 +695,6 @@ class VoucherTests(TestCase):
).decode("utf-8"), ).decode("utf-8"),
).encode("ascii"), ).encode("ascii"),
) )
if redeemed:
# Value duplicated from PaymentController.redeem default. Should
# do this better.
token_count_comparison = Equals(100)
else:
token_count_comparison = Is(None)
self.assertThat( self.assertThat(
getting, getting,
succeeded( succeeded(
...@@ -666,12 +705,7 @@ class VoucherTests(TestCase): ...@@ -666,12 +705,7 @@ class VoucherTests(TestCase):
succeeded( succeeded(
AfterPreprocessing( AfterPreprocessing(
Voucher.from_json, Voucher.from_json,
MatchesStructure( voucher_matcher,
number=Equals(voucher),
created=Equals(now),
state=Equals(u"redeemed" if redeemed else u"pending"),
token_count=token_count_comparison,
),
), ),
), ),
), ),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment