diff --git a/src/_zkapauthorizer/resource.py b/src/_zkapauthorizer/resource.py index c53114e1983d86163982c0221fdc520b55ea4559..961aea71b7f268e0c23924ded4504795ea136cca 100644 --- a/src/_zkapauthorizer/resource.py +++ b/src/_zkapauthorizer/resource.py @@ -162,7 +162,7 @@ class _UnblindedTokenCollection(Resource): if activity is None: return activity return { - u"when": activity.finished, + u"when": activity.finished.isoformat(), u"count": activity.passes_required, } diff --git a/src/_zkapauthorizer/tests/test_client_resource.py b/src/_zkapauthorizer/tests/test_client_resource.py index 9d620c5971c84e0811d78a53522ff250d0bffdd3..8694ea1ced95185c21a4a0b2302592426b4b9e41 100644 --- a/src/_zkapauthorizer/tests/test_client_resource.py +++ b/src/_zkapauthorizer/tests/test_client_resource.py @@ -440,6 +440,50 @@ class UnblindedTokenTests(TestCase): ), ) + @given( + tahoe_configs(), + lists( + lists( + integers(min_value=0), + min_size=1, + ), + ), + datetimes(), + ) + def test_latest_lease_maintenance_spending(self, get_config, size_observations, now): + """ + The most recently completed record of lease maintenance spending activity + is reported in the response to a **GET** request. + """ + tempdir = self.useFixture(TempDir()) + config = get_config(tempdir.join(b"tahoe"), b"tub.port") + root = root_from_config(config, lambda: now) + + # Put some activity into it. + total = 0 + activity = root.store.start_lease_maintenance() + for sizes in size_observations: + total += sum(sizes) + activity.observe(sizes) + activity.finish() + + agent = RequestTraversalAgent(root) + d = agent.request( + b"GET", + b"http://127.0.0.1/unblinded-token", + ) + d.addCallback(readBody) + d.addCallback( + lambda body: loads(body)[u"lease-maintenance-spending"], + ) + self.assertThat( + d, + succeeded(Equals({ + "when": now.isoformat(), + "count": total, + })), + ) + def succeeded_with_unblinded_tokens_with_matcher( all_token_count,