diff --git a/src/_zkapauthorizer/resource.py b/src/_zkapauthorizer/resource.py index 7e411a244a5ad0899ca1100fec0c23019fd2abea..c180a5b064a9a74e8bfb38126dd446f3fdab3d1a 100644 --- a/src/_zkapauthorizer/resource.py +++ b/src/_zkapauthorizer/resource.py @@ -77,6 +77,13 @@ def from_configuration(node_config, store, redeemer=None): controller, ), ) + root.putChild( + b"zkap", + _ZKAPCollection( + store, + controller, + ), + ) return root @@ -89,6 +96,27 @@ def application_json(request): request.responseHeaders.setRawHeaders(u"content-type", [u"application/json"]) +class _ZKAPCollection(Resource): + """ + This class implements inspection of ZKAPs. Users **GET** this resource to + find out about ZKAPs in the system. + """ + _log = Logger() + + def __init__(self, store, controller): + self._store = store + self._controller = controller + Resource.__init__(self) + + def render_GET(self, request): + """ + Retrieve some ZKAPs and associated informatin. + """ + application_json(request) + return dumps({u"total": 0, u"zkaps": []}) + + + class _VoucherCollection(Resource): """ This class implements redemption of vouchers. Users **PUT** such numbers diff --git a/src/_zkapauthorizer/tests/test_client_resource.py b/src/_zkapauthorizer/tests/test_client_resource.py index 20047d3cf2b986112c386dd99e1cf782d87cb573..0bab6d268c3bad30a0869c90d146519b40647f4d 100644 --- a/src/_zkapauthorizer/tests/test_client_resource.py +++ b/src/_zkapauthorizer/tests/test_client_resource.py @@ -205,32 +205,81 @@ def root_from_config(config): ) -class VoucherTests(TestCase): +class ResourceTests(TestCase): """ - Tests relating to ``/voucher`` as implemented by the - ``_zkapauthorizer.resource`` module and its handling of - vouchers. + General tests for the resources exposed by the plugin. + """ + @given(tahoe_configs(), requests(just([u"zkap"]) | just([u"voucher"]))) + def test_reachable(self, get_config, request): + """ + A resource is reachable at a child of the resource returned by + ``from_configuration``. + """ + tempdir = self.useFixture(TempDir()) + config = get_config(tempdir.join(b"tahoe"), b"tub.port") + root = root_from_config(config) + self.assertThat( + getChildForRequest(root, request), + Provides([IResource]), + ) + + +class ZKAPTests(TestCase): + """ + Tests relating to ``/zkap`` as implemented by the + ``_zkapauthorizer.resource`` module. """ def setUp(self): - super(VoucherTests, self).setUp() + super(ZKAPTests, self).setUp() self.useFixture(CaptureTwistedLogs()) - @given(tahoe_configs(), requests(just([u"voucher"]))) - def test_reachable(self, get_config, request): + @given(tahoe_configs()) + def test_get(self, get_config): """ - A resource is reachable at the ``voucher`` child of a the resource - returned by ``from_configuration``. """ tempdir = self.useFixture(TempDir()) config = get_config(tempdir.join(b"tahoe"), b"tub.port") root = root_from_config(config) + agent = RequestTraversalAgent(root) + requesting = agent.request( + b"GET", + b"http://127.0.0.1/zkap", + ) + self.addDetail( + u"requesting result", + text_content(u"{}".format(vars(requesting.result))), + ) self.assertThat( - getChildForRequest(root, request), - Provides([IResource]), + requesting, + succeeded( + MatchesAll( + ok_response(headers=application_json()), + AfterPreprocessing( + json_content, + succeeded( + Equals({ + u"total": 0, + u"zkaps": [], + }), + ) + ), + ), + ), ) +class VoucherTests(TestCase): + """ + Tests relating to ``/voucher`` as implemented by the + ``_zkapauthorizer.resource`` module and its handling of + vouchers. + """ + def setUp(self): + super(VoucherTests, self).setUp() + self.useFixture(CaptureTwistedLogs()) + + @given(tahoe_configs(), vouchers()) def test_put_voucher(self, get_config, voucher): """