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

Add a very boring zkap collection resource

parent 1342a6e1
No related branches found
No related tags found
1 merge request!59Unblinded token web interface
......@@ -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
......
......@@ -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):
"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment