diff --git a/src/_zkapauthorizer/resource.py b/src/_zkapauthorizer/resource.py index 1601d7054ca7f74bbb6553f18e2da20d4ebb3551..fb7e61aab584103c48ffee628e8835d28b73d9bb 100644 --- a/src/_zkapauthorizer/resource.py +++ b/src/_zkapauthorizer/resource.py @@ -196,7 +196,7 @@ class _VoucherCollection(Resource): application_json(request) return dumps({ u"vouchers": list( - voucher.marshal() + self._controller.incorporate_transient_state(voucher).marshal() for voucher in self._store.list() ), @@ -211,7 +211,6 @@ class _VoucherCollection(Resource): voucher = self._store.get(voucher) except KeyError: return NoResource() - # TODO Apply the same treatment to the list result return VoucherView(self._controller.incorporate_transient_state(voucher)) diff --git a/src/_zkapauthorizer/tests/test_client_resource.py b/src/_zkapauthorizer/tests/test_client_resource.py index 22d2f544783374379d4ca340b2170d6d468f7d1b..653574423654bd9c5d0cb73da3c37f4b01406d4d 100644 --- a/src/_zkapauthorizer/tests/test_client_resource.py +++ b/src/_zkapauthorizer/tests/test_client_resource.py @@ -776,6 +776,59 @@ class VoucherTests(TestCase): A ``GET`` to the ``VoucherCollection`` itself returns a list of existing vouchers. """ + return self._test_list_vouchers( + get_config, + now, + vouchers, + Equals({ + u"vouchers": list( + Voucher( + voucher, + created=now, + state=Redeemed( + finished=now, + # Value duplicated from + # PaymentController.redeem + # default. Should do this better. + token_count=100, + ), + ).marshal() + for voucher + in vouchers + ), + }), + ) + + @given( + tahoe_configs(client_unpaidredeemer_configurations()), + datetimes(), + lists(vouchers(), unique=True), + ) + def test_list_vouchers_transient_states(self, get_config, now, vouchers): + """ + A ``GET`` to the ``VoucherCollection`` itself returns a list of existing + vouchers including state information that reflects transient states. + """ + return self._test_list_vouchers( + get_config, + now, + vouchers, + Equals({ + u"vouchers": list( + Voucher( + voucher, + created=now, + state=Unpaid( + finished=now, + ), + ).marshal() + for voucher + in vouchers + ), + }), + ) + + def _test_list_vouchers(self, get_config, now, vouchers, match_response_object): # Hypothesis causes our test case instances to be re-used many times # between setUp and tearDown. Avoid re-using the same temporary # directory for every Hypothesis iteration because this test leaves @@ -817,23 +870,7 @@ class VoucherTests(TestCase): AfterPreprocessing( json_content, succeeded( - Equals({ - u"vouchers": list( - Voucher( - voucher, - created=now, - state=Redeemed( - finished=now, - # Value duplicated from - # PaymentController.redeem - # default. Should do this better. - token_count=100, - ), - ).marshal() - for voucher - in vouchers - ), - }), + match_response_object, ), ), ),