mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-02-26 03:28:17 +00:00
Tests pass on Python 3.
This commit is contained in:
parent
aacdf9906d
commit
6bfcda2a3d
@ -1,10 +1,10 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
from past.builtins import unicode
|
||||||
|
|
||||||
from datetime import (
|
from datetime import (
|
||||||
datetime,
|
datetime,
|
||||||
timedelta,
|
timedelta,
|
||||||
)
|
)
|
||||||
import json
|
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
@ -23,6 +23,7 @@ from allmydata.grid_manager import (
|
|||||||
save_grid_manager,
|
save_grid_manager,
|
||||||
load_grid_manager,
|
load_grid_manager,
|
||||||
)
|
)
|
||||||
|
from allmydata.util import jsonbytes as json
|
||||||
|
|
||||||
|
|
||||||
@click.group()
|
@click.group()
|
||||||
@ -102,7 +103,7 @@ def public_identity(config):
|
|||||||
|
|
||||||
@grid_manager.command()
|
@grid_manager.command()
|
||||||
@click.argument("name")
|
@click.argument("name")
|
||||||
@click.argument("public_key", type=click.UNPROCESSED)
|
@click.argument("public_key", type=click.STRING)
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def add(ctx, name, public_key):
|
def add(ctx, name, public_key):
|
||||||
"""
|
"""
|
||||||
@ -160,7 +161,9 @@ def list(ctx):
|
|||||||
"""
|
"""
|
||||||
for name in sorted(ctx.obj.grid_manager.storage_servers.keys()):
|
for name in sorted(ctx.obj.grid_manager.storage_servers.keys()):
|
||||||
blank_name = " " * len(name)
|
blank_name = " " * len(name)
|
||||||
click.echo("{}: {}".format(name, ctx.obj.grid_manager.storage_servers[name].public_key_string()))
|
click.echo("{}: {}".format(
|
||||||
|
name,
|
||||||
|
unicode(ctx.obj.grid_manager.storage_servers[name].public_key_string(), "utf-8")))
|
||||||
for cert in ctx.obj.grid_manager.storage_servers[name].certificates:
|
for cert in ctx.obj.grid_manager.storage_servers[name].certificates:
|
||||||
delta = datetime.utcnow() - cert.expires
|
delta = datetime.utcnow() - cert.expires
|
||||||
click.echo("{} cert {}: ".format(blank_name, cert.index), nl=False)
|
click.echo("{} cert {}: ".format(blank_name, cert.index), nl=False)
|
||||||
@ -209,7 +212,7 @@ def sign(ctx, name, expiry_days):
|
|||||||
)
|
)
|
||||||
next_serial += 1
|
next_serial += 1
|
||||||
with f:
|
with f:
|
||||||
f.write(certificate_data)
|
f.write(certificate_data.encode("ascii"))
|
||||||
|
|
||||||
|
|
||||||
def _config_path_from_option(config):
|
def _config_path_from_option(config):
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
from future.utils import raise_
|
from future.utils import raise_
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import json
|
|
||||||
from io import (
|
from io import (
|
||||||
BytesIO,
|
BytesIO,
|
||||||
)
|
)
|
||||||
@ -31,6 +30,7 @@ from twisted.python.filepath import (
|
|||||||
from twisted.python.runtime import (
|
from twisted.python.runtime import (
|
||||||
platform,
|
platform,
|
||||||
)
|
)
|
||||||
|
from allmydata.util import jsonbytes as json
|
||||||
|
|
||||||
|
|
||||||
class GridManagerCommandLine(TestCase):
|
class GridManagerCommandLine(TestCase):
|
||||||
@ -66,8 +66,8 @@ class GridManagerCommandLine(TestCase):
|
|||||||
An invalid config is reported to the user
|
An invalid config is reported to the user
|
||||||
"""
|
"""
|
||||||
with self.runner.isolated_filesystem():
|
with self.runner.isolated_filesystem():
|
||||||
with open("config.json", "w") as f:
|
with open("config.json", "wb") as f:
|
||||||
json.dump({"not": "valid"}, f)
|
f.write(json.dumps_bytes({"not": "valid"}))
|
||||||
result = self.runner.invoke(grid_manager, ["--config", ".", "public-identity"])
|
result = self.runner.invoke(grid_manager, ["--config", ".", "public-identity"])
|
||||||
self.assertNotEqual(result.exit_code, 0)
|
self.assertNotEqual(result.exit_code, 0)
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
@ -117,7 +117,7 @@ class GridManagerCommandLine(TestCase):
|
|||||||
}
|
}
|
||||||
result = self.invoke_and_check(
|
result = self.invoke_and_check(
|
||||||
grid_manager, ["--config", "-", "list"],
|
grid_manager, ["--config", "-", "list"],
|
||||||
input=BytesIO(json.dumps(config)),
|
input=BytesIO(json.dumps_bytes(config)),
|
||||||
)
|
)
|
||||||
self.assertEqual(result.exit_code, 0)
|
self.assertEqual(result.exit_code, 0)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
@ -260,7 +260,7 @@ class TahoeAddGridManagerCert(TestCase):
|
|||||||
"""
|
"""
|
||||||
code, out, err = yield run_cli(
|
code, out, err = yield run_cli(
|
||||||
"admin", "add-grid-manager-cert", "--filename", "-",
|
"admin", "add-grid-manager-cert", "--filename", "-",
|
||||||
stdin="the cert",
|
stdin=b"the cert",
|
||||||
)
|
)
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
"Must provide --name",
|
"Must provide --name",
|
||||||
@ -274,7 +274,7 @@ class TahoeAddGridManagerCert(TestCase):
|
|||||||
"""
|
"""
|
||||||
code, out, err = yield run_cli(
|
code, out, err = yield run_cli(
|
||||||
"admin", "add-grid-manager-cert", "--name", "foo",
|
"admin", "add-grid-manager-cert", "--name", "foo",
|
||||||
stdin="the cert",
|
stdin=b"the cert",
|
||||||
)
|
)
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
"Must provide --filename",
|
"Must provide --filename",
|
||||||
@ -287,7 +287,7 @@ class TahoeAddGridManagerCert(TestCase):
|
|||||||
we can add a certificate
|
we can add a certificate
|
||||||
"""
|
"""
|
||||||
nodedir = self.mktemp()
|
nodedir = self.mktemp()
|
||||||
fake_cert = """{"certificate": "", "signature": ""}"""
|
fake_cert = b"""{"certificate": "", "signature": ""}"""
|
||||||
|
|
||||||
code, out, err = yield run_cli(
|
code, out, err = yield run_cli(
|
||||||
"--node-directory", nodedir,
|
"--node-directory", nodedir,
|
||||||
@ -301,7 +301,7 @@ class TahoeAddGridManagerCert(TestCase):
|
|||||||
|
|
||||||
self.assertIn("tahoe.cfg", nodepath.listdir())
|
self.assertIn("tahoe.cfg", nodepath.listdir())
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
"foo = foo.cert",
|
b"foo = foo.cert",
|
||||||
config_data,
|
config_data,
|
||||||
)
|
)
|
||||||
self.assertIn("foo.cert", nodepath.listdir())
|
self.assertIn("foo.cert", nodepath.listdir())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user