mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-04-15 06:36:40 +00:00
Finish porting testing & test_testing
This commit is contained in:
parent
4b6f84b821
commit
bde424c7f9
@ -9,7 +9,18 @@
|
||||
|
||||
"""
|
||||
Tests for the allmydata.testing helpers
|
||||
|
||||
Ported to Python 3.
|
||||
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from future.utils import PY2
|
||||
if PY2:
|
||||
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
|
||||
|
||||
from twisted.internet.defer import (
|
||||
inlineCallbacks,
|
||||
@ -79,7 +90,7 @@ class FakeWebTest(TestCase):
|
||||
self.assertThat(cap, IsInstance(CHKFileURI))
|
||||
|
||||
resp = yield http_client.get(
|
||||
"http://example.com/uri?uri={}".format(cap.to_string())
|
||||
b"http://example.com/uri?uri=" + cap.to_string()
|
||||
)
|
||||
self.assertThat(resp.code, Equals(200))
|
||||
|
||||
@ -88,7 +99,7 @@ class FakeWebTest(TestCase):
|
||||
# using the form "/uri/<cap>" is also valid
|
||||
|
||||
resp = yield http_client.get(
|
||||
"http://example.com/uri/{}".format(cap.to_string())
|
||||
b"http://example.com/uri?uri=" + cap.to_string()
|
||||
)
|
||||
self.assertEqual(resp.code, 200)
|
||||
|
||||
@ -136,9 +147,9 @@ class FakeWebTest(TestCase):
|
||||
"""
|
||||
|
||||
http_client = create_tahoe_treq_client()
|
||||
cap_gen = capability_generator("URI:CHK:")
|
||||
|
||||
uri = DecodedURL.from_text(u"http://example.com/uri?uri={}".format(next(cap_gen)))
|
||||
cap_gen = capability_generator(b"URI:CHK:")
|
||||
cap = next(cap_gen).decode('ascii')
|
||||
uri = DecodedURL.from_text(u"http://example.com/uri?uri={}".format(cap))
|
||||
resp = http_client.get(uri.to_uri().to_text())
|
||||
|
||||
self.assertThat(
|
||||
|
@ -94,16 +94,19 @@ def capability_generator(kind):
|
||||
given kind. The N, K and size values aren't related to anything
|
||||
real.
|
||||
|
||||
:param str kind: the kind of capability, like `URI:CHK`
|
||||
:param bytes kind: the kind of capability, like `URI:CHK`
|
||||
|
||||
:returns: a generator that yields new capablities of a particular
|
||||
kind.
|
||||
"""
|
||||
if not isinstance(kind, bytes):
|
||||
raise TypeError("'kind' must be bytes")
|
||||
|
||||
if kind not in KNOWN_CAPABILITIES:
|
||||
raise ValueError(
|
||||
"Unknown capability kind '{} (valid are {})'".format(
|
||||
kind,
|
||||
", ".join(KNOWN_CAPABILITIES),
|
||||
b", ".join(KNOWN_CAPABILITIES),
|
||||
)
|
||||
)
|
||||
# what we do here is to start with empty hashers for the key and
|
||||
@ -118,16 +121,16 @@ def capability_generator(kind):
|
||||
# capabilities are "prefix:<128-bits-base32>:<256-bits-base32>:N:K:size"
|
||||
while True:
|
||||
number += 1
|
||||
key_hasher.update("\x00")
|
||||
ueb_hasher.update("\x00")
|
||||
key_hasher.update(b"\x00")
|
||||
ueb_hasher.update(b"\x00")
|
||||
|
||||
key = base32.b2a(key_hasher.digest()[:16]) # key is 16 bytes
|
||||
ueb_hash = base32.b2a(ueb_hasher.digest()) # ueb hash is 32 bytes
|
||||
|
||||
cap = u"{kind}{key}:{ueb_hash}:{n}:{k}:{size}".format(
|
||||
kind=kind,
|
||||
key=key,
|
||||
ueb_hash=ueb_hash,
|
||||
kind=kind.decode('ascii'),
|
||||
key=key.decode('ascii'),
|
||||
ueb_hash=ueb_hash.decode('ascii'),
|
||||
n=1,
|
||||
k=1,
|
||||
size=number * 1000,
|
||||
@ -164,6 +167,8 @@ class _FakeTahoeUriHandler(Resource, object):
|
||||
|
||||
:returns: a two-tuple: a bool (True if the data is freshly added) and a capability-string
|
||||
"""
|
||||
if not isinstance(kind, bytes):
|
||||
raise TypeError("'kind' must be bytes")
|
||||
if not isinstance(data, bytes):
|
||||
raise TypeError("'data' must be bytes")
|
||||
|
||||
@ -181,7 +186,7 @@ class _FakeTahoeUriHandler(Resource, object):
|
||||
|
||||
def render_PUT(self, request):
|
||||
data = request.content.read()
|
||||
fresh, cap = self.add_data("URI:CHK:", data)
|
||||
fresh, cap = self.add_data(b"URI:CHK:", data)
|
||||
if fresh:
|
||||
request.setResponseCode(http.CREATED) # real code does this for brand-new files
|
||||
else:
|
||||
@ -193,7 +198,7 @@ class _FakeTahoeUriHandler(Resource, object):
|
||||
data = request.content.read()
|
||||
|
||||
type_to_kind = {
|
||||
"mkdir-immutable": "URI:DIR2-CHK:"
|
||||
"mkdir-immutable": b"URI:DIR2-CHK:"
|
||||
}
|
||||
kind = type_to_kind[t]
|
||||
fresh, cap = self.add_data(kind, data)
|
||||
@ -216,9 +221,10 @@ class _FakeTahoeUriHandler(Resource, object):
|
||||
|
||||
# the user gave us a capability; if our Grid doesn't have any
|
||||
# data for it, that's an error.
|
||||
capability = capability.encode('ascii')
|
||||
if capability not in self.data:
|
||||
request.setResponseCode(http.BAD_REQUEST)
|
||||
return u"No data for '{}'".format(capability).decode("ascii")
|
||||
return u"No data for '{}'".format(capability.decode('ascii'))
|
||||
|
||||
return self.data[capability]
|
||||
|
||||
|
@ -87,6 +87,7 @@ PORTED_MODULES = [
|
||||
"allmydata.storage.shares",
|
||||
"allmydata.test.no_network",
|
||||
"allmydata.test.mutable.util",
|
||||
"allmydata.testing",
|
||||
"allmydata.unknown",
|
||||
"allmydata.uri",
|
||||
"allmydata.util._python3",
|
||||
@ -205,6 +206,7 @@ PORTED_TEST_MODULES = [
|
||||
# should be done once CLI is ported.
|
||||
"allmydata.test.test_system",
|
||||
|
||||
"allmydata.test.test_testing",
|
||||
"allmydata.test.test_time_format",
|
||||
"allmydata.test.test_upload",
|
||||
"allmydata.test.test_uri",
|
||||
|
Loading…
x
Reference in New Issue
Block a user