tests: reformat tests using black.
This commit is contained in:
parent
42263d05f9
commit
5005ca346b
2 changed files with 161 additions and 140 deletions
|
|
@ -35,13 +35,13 @@ class LiberviaCliJson:
|
|||
def __call__(self, *args, **kwargs):
|
||||
args = self.subcommands + list(args)
|
||||
self.subcommands.clear()
|
||||
kwargs['output'] = 'json-raw'
|
||||
kwargs['_tty_out'] = False
|
||||
kwargs["output"] = "json-raw"
|
||||
kwargs["_tty_out"] = False
|
||||
cmd = li(*args, **kwargs)
|
||||
return json.loads(cmd)
|
||||
|
||||
def __getattr__(self, name):
|
||||
if name.startswith('_'):
|
||||
if name.startswith("_"):
|
||||
# no li subcommand starts with a "_",
|
||||
# and pytest uses some attributes with this name scheme
|
||||
return super().__getattr__(name)
|
||||
|
|
@ -55,13 +55,14 @@ class LiberviaCliElt(LiberviaCliJson):
|
|||
def __init__(self):
|
||||
super().__init__()
|
||||
from libervia.backend.tools.xml_tools import ElementParser
|
||||
|
||||
self.parser = ElementParser()
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
args = self.subcommands + list(args)
|
||||
self.subcommands.clear()
|
||||
kwargs['output'] = 'xml-raw'
|
||||
kwargs['_tty_out'] = False
|
||||
kwargs["output"] = "xml-raw"
|
||||
kwargs["_tty_out"] = False
|
||||
cmd = li(*args, **kwargs)
|
||||
return self.parser(cmd.strip())
|
||||
|
||||
|
|
@ -79,7 +80,8 @@ class Editor:
|
|||
self.editor_path = self.tmp_dir_path / "editor.py"
|
||||
self.ori_content_path = self.tmp_dir_path / "original_content"
|
||||
self.new_content_path = self.tmp_dir_path / "new_content"
|
||||
self.base_script = dedent(f"""\
|
||||
self.base_script = dedent(
|
||||
f"""\
|
||||
#!{sys.executable}
|
||||
import sys
|
||||
|
||||
|
|
@ -111,9 +113,9 @@ class Editor:
|
|||
If filter_ is not specified, original content is written unmodified.
|
||||
Code must be on a single line.
|
||||
"""
|
||||
if '\n' in content_filter:
|
||||
if "\n" in content_filter:
|
||||
raise ValueError("new lines can't be used in filter_")
|
||||
with self.editor_path.open('w') as f:
|
||||
with self.editor_path.open("w") as f:
|
||||
f.write(self.base_script.format(content_filter=content_filter))
|
||||
self.editor_path.chmod(0o700)
|
||||
self.editor_set = True
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ from libervia.backend.tools.common import uri
|
|||
if os.getenv("LIBERVIA_TEST_ENV_E2E") is None:
|
||||
pytest.skip(
|
||||
"skipping end-to-end tests, we are not in a test environment",
|
||||
allow_module_level=True
|
||||
allow_module_level=True,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -52,10 +52,7 @@ class TestLiberviaCliAccount:
|
|||
def test_create_and_delete(self, li_json):
|
||||
"""Create an account in-band, connect it, then delete it and its profile"""
|
||||
li.account.create(
|
||||
"test_create@server1.test",
|
||||
"test",
|
||||
profile="test_create",
|
||||
host="server1.test"
|
||||
"test_create@server1.test", "test", profile="test_create", host="server1.test"
|
||||
)
|
||||
profiles = li_json.profile.list()
|
||||
assert "test_create" in profiles
|
||||
|
|
@ -96,15 +93,15 @@ class TestLiberviaCliPubsub:
|
|||
item3_id = li.pubsub.set(node="test", quiet=True, _in=payload)
|
||||
parsed_elt = li_elt.pubsub.get(node="test", item=item1_id)
|
||||
payload = parsed_elt.firstChildElement()
|
||||
assert payload.name == 'test'
|
||||
assert payload.name == "test"
|
||||
assert str(payload) == content
|
||||
parsed_elt = li_elt.pubsub.get(node="test", item=item2_id)
|
||||
payload = parsed_elt.firstChildElement()
|
||||
assert payload.name == 'test'
|
||||
assert payload.name == "test"
|
||||
assert str(payload) == content
|
||||
parsed_elt = li_elt.pubsub.get(node="test", item=item3_id)
|
||||
payload = parsed_elt.firstChildElement()
|
||||
assert payload.name == 'test'
|
||||
assert payload.name == "test"
|
||||
assert str(payload) == content
|
||||
|
||||
# deleting first item should work
|
||||
|
|
@ -131,7 +128,7 @@ class TestLiberviaCliPubsub:
|
|||
parsed_elt = li_elt.pubsub.get(node="test", item=item_id)
|
||||
edited_payload = parsed_elt.firstChildElement()
|
||||
expected_edited_content = content.replace("original", "edited")
|
||||
assert edited_payload.name == 'test'
|
||||
assert edited_payload.name == "test"
|
||||
assert str(edited_payload) == expected_edited_content
|
||||
|
||||
def test_affiliations(self, li_json):
|
||||
|
|
@ -139,9 +136,7 @@ class TestLiberviaCliPubsub:
|
|||
assert affiliations["test"] == "owner"
|
||||
|
||||
def test_uri(self):
|
||||
built_uri = li.pubsub.uri(
|
||||
service="pubsub.example.net", node="some_node"
|
||||
).strip()
|
||||
built_uri = li.pubsub.uri(service="pubsub.example.net", node="some_node").strip()
|
||||
assert built_uri == "xmpp:pubsub.example.net?;node=some_node"
|
||||
built_uri = li.pubsub.uri(
|
||||
service="pubsub.example.net", node="some_node", item="some_item"
|
||||
|
|
@ -154,26 +149,17 @@ class TestLiberviaCliPubsub:
|
|||
fr_txt = "this is a blog post about France"
|
||||
nc_txt = "this is a blog post about New Caledonia"
|
||||
au_txt = "this is a blog post about Australia"
|
||||
li.blog.set("-t", "travel", "-t", "europe", _in=sk_txt, syntax="markdown")
|
||||
li.blog.set("-t", "travel", "-t", "europe", _in=fr_txt, syntax="markdown")
|
||||
li.blog.set("-t", "travel", "-t", "south pacific", _in=nc_txt, syntax="markdown")
|
||||
li.blog.set(
|
||||
"-t", "travel", "-t", "europe",
|
||||
_in=sk_txt,
|
||||
syntax="markdown"
|
||||
)
|
||||
li.blog.set(
|
||||
"-t", "travel", "-t", "europe",
|
||||
_in=fr_txt,
|
||||
syntax="markdown"
|
||||
)
|
||||
li.blog.set(
|
||||
"-t", "travel", "-t", "south pacific",
|
||||
_in=nc_txt,
|
||||
syntax="markdown"
|
||||
)
|
||||
li.blog.set(
|
||||
"-t", "travel", "-t", "south pacific",
|
||||
"-t",
|
||||
"travel",
|
||||
"-t",
|
||||
"south pacific",
|
||||
_in="this is a blog post about Australia",
|
||||
title=au_txt,
|
||||
syntax="markdown"
|
||||
syntax="markdown",
|
||||
)
|
||||
# we get the blog to activate the cache for it
|
||||
li.blog.get(max_items=1)
|
||||
|
|
@ -215,25 +201,28 @@ class TestLiberviaCliBlog:
|
|||
item_data = li_json.blog.get(max=1, before="")
|
||||
item = item_data[0][0]
|
||||
metadata = item_data[1]
|
||||
assert metadata['service'] == "account1@server1.test"
|
||||
assert metadata['node'] == self.MICROBLOG_NS
|
||||
assert metadata['rsm'].keys() <= {"first", "last", "index", "count"}
|
||||
item_id = item['id']
|
||||
assert metadata["service"] == "account1@server1.test"
|
||||
assert metadata["node"] == self.MICROBLOG_NS
|
||||
assert metadata["rsm"].keys() <= {"first", "last", "index", "count"}
|
||||
item_id = item["id"]
|
||||
expected_uri = uri.build_xmpp_uri(
|
||||
'pubsub', subtype="microblog", path="account1@server1.test",
|
||||
node=self.MICROBLOG_NS, item=item_id
|
||||
"pubsub",
|
||||
subtype="microblog",
|
||||
path="account1@server1.test",
|
||||
node=self.MICROBLOG_NS,
|
||||
item=item_id,
|
||||
)
|
||||
assert item['uri'] == expected_uri
|
||||
assert item['content_xhtml'] == (
|
||||
'<div><p>markdown <strong>bold</strong> '
|
||||
assert item["uri"] == expected_uri
|
||||
assert item["content_xhtml"] == (
|
||||
"<div><p>markdown <strong>bold</strong> "
|
||||
'<a href="https://example.net">link</a></p></div>'
|
||||
)
|
||||
assert isinstance(item['published'], int)
|
||||
assert isinstance(item['updated'], int)
|
||||
assert isinstance(item['comments'], list)
|
||||
assert isinstance(item['tags'], list)
|
||||
assert item['author'] == 'account1'
|
||||
assert item['author_jid'] == 'account1@server1.test'
|
||||
assert isinstance(item["published"], int)
|
||||
assert isinstance(item["updated"], int)
|
||||
assert isinstance(item["comments"], list)
|
||||
assert isinstance(item["tags"], list)
|
||||
assert item["author"] == "account1"
|
||||
assert item["author_jid"] == "account1@server1.test"
|
||||
|
||||
def test_edit(self, editor, li_json):
|
||||
payload_md = "content in **markdown**"
|
||||
|
|
@ -243,9 +232,9 @@ class TestLiberviaCliBlog:
|
|||
assert editor.new_content == payload_md
|
||||
items_data = li_json.blog.get(max_items=1)
|
||||
last_item = items_data[0][0]
|
||||
last_item_id = last_item['id']
|
||||
assert last_item['content'] == "content in markdown"
|
||||
assert last_item['content_xhtml'] == (
|
||||
last_item_id = last_item["id"]
|
||||
assert last_item["content"] == "content in markdown"
|
||||
assert last_item["content_xhtml"] == (
|
||||
"<div><p>content in <strong>markdown</strong></p></div>"
|
||||
)
|
||||
editor.set_filter('f"{content} extended"')
|
||||
|
|
@ -255,9 +244,9 @@ class TestLiberviaCliBlog:
|
|||
items_data = li_json.blog.get(max_items=1)
|
||||
last_item = items_data[0][0]
|
||||
# we check that the id hasn't been modified
|
||||
assert last_item['id'] == last_item_id
|
||||
assert last_item['content'] == "content in markdown extended"
|
||||
assert last_item['content_xhtml'] == (
|
||||
assert last_item["id"] == last_item_id
|
||||
assert last_item["content"] == "content in markdown extended"
|
||||
assert last_item["content_xhtml"] == (
|
||||
"<div><p>content in <strong>markdown</strong> extended</p></div>"
|
||||
)
|
||||
|
||||
|
|
@ -286,7 +275,8 @@ class TestLiberviaCliFile:
|
|||
dest_path.mkdir()
|
||||
try:
|
||||
li.file.receive(
|
||||
"account1@server1.test", profile="account1_s2", path=dest_path)
|
||||
"account1@server1.test", profile="account1_s2", path=dest_path
|
||||
)
|
||||
dest_file = dest_path / source_file.name
|
||||
dest_file_hash = fake_file.get_dest_hash(dest_file)
|
||||
finally:
|
||||
|
|
@ -305,7 +295,8 @@ class TestLiberviaCliFile:
|
|||
dest_path.mkdir()
|
||||
try:
|
||||
li.file.receive(
|
||||
"account1@server1.test", profile="account1_s2", path=dest_path)
|
||||
"account1@server1.test", profile="account1_s2", path=dest_path
|
||||
)
|
||||
dest_file = dest_path / source_file.name
|
||||
dest_file_hash = fake_file.get_dest_hash(dest_file)
|
||||
finally:
|
||||
|
|
@ -315,7 +306,6 @@ class TestLiberviaCliFile:
|
|||
assert source_file_hash == dest_file_hash
|
||||
|
||||
|
||||
|
||||
class TestE2EEncryption:
|
||||
|
||||
def test_pubsub_encryption_oxps(self, li_elt):
|
||||
|
|
@ -324,9 +314,7 @@ class TestE2EEncryption:
|
|||
li.blog.set(_in=secret_blog, node="e2ee_blog", item="test_e2ee", encrypt=True)
|
||||
|
||||
# the item should be transparently decrypted
|
||||
parsed_decrypted = li_elt.pubsub.get(
|
||||
node=node, item="test_e2ee", no_cache=True
|
||||
)
|
||||
parsed_decrypted = li_elt.pubsub.get(node=node, item="test_e2ee", no_cache=True)
|
||||
entry_elt = parsed_decrypted.firstChildElement()
|
||||
assert entry_elt.name == "entry"
|
||||
assert entry_elt.uri == NS_ATOM
|
||||
|
|
@ -344,14 +332,17 @@ class TestE2EEncryption:
|
|||
|
||||
def test_pubsub_secrets_sharing_oxps(self, li_elt):
|
||||
secret_blog = "this is a secret blog post"
|
||||
node="secret_sharing"
|
||||
node = "secret_sharing"
|
||||
|
||||
li.blog.set(_in=secret_blog, node=node, item="test_e2ee", encrypt=True)
|
||||
|
||||
# the item must not be decrypted for account1_s2 (secret is not known)
|
||||
parsed_item = li_elt.pubsub.get(
|
||||
service="account1@server1.test", node=node, item="test_e2ee", no_cache=True,
|
||||
profile="account1_s2"
|
||||
service="account1@server1.test",
|
||||
node=node,
|
||||
item="test_e2ee",
|
||||
no_cache=True,
|
||||
profile="account1_s2",
|
||||
)
|
||||
encrypted_elt = parsed_item.firstChildElement()
|
||||
assert encrypted_elt.name == "encrypted"
|
||||
|
|
@ -360,12 +351,17 @@ class TestE2EEncryption:
|
|||
assert secret_blog not in parsed_item.toXml()
|
||||
|
||||
# we share the secrets
|
||||
li.pubsub.secret.share("account1@server2.test", service="account1@server1.test", node=node)
|
||||
li.pubsub.secret.share(
|
||||
"account1@server2.test", service="account1@server1.test", node=node
|
||||
)
|
||||
|
||||
# and get the item again
|
||||
parsed_item = li_elt.pubsub.get(
|
||||
service="account1@server1.test", node=node, item="test_e2ee", no_cache=True,
|
||||
profile="account1_s2"
|
||||
service="account1@server1.test",
|
||||
node=node,
|
||||
item="test_e2ee",
|
||||
no_cache=True,
|
||||
profile="account1_s2",
|
||||
)
|
||||
# now it should be decrypted
|
||||
entry_elt = parsed_item.firstChildElement()
|
||||
|
|
@ -376,9 +372,9 @@ class TestE2EEncryption:
|
|||
def test_pubsub_signature(self, li_json):
|
||||
"""A pubsub item can be signed, and the signature can be verified"""
|
||||
body = "this message is signed"
|
||||
service="account1@server1.test"
|
||||
node ="blog_signing"
|
||||
item="signed_item"
|
||||
service = "account1@server1.test"
|
||||
node = "blog_signing"
|
||||
item = "signed_item"
|
||||
li.blog.set(_in=body, service=service, node=node, item=item, sign=True)
|
||||
attachments = li_json.pubsub.attachments.get(
|
||||
service=service, node=node, item=item
|
||||
|
|
@ -388,7 +384,10 @@ class TestE2EEncryption:
|
|||
assert attachment["from"] == "account1@server1.test"
|
||||
signature_json = attachment["signature"]
|
||||
sign_data = li_json.pubsub.signature.check(
|
||||
json.dumps(signature_json), service=service, node=node, item=item,
|
||||
json.dumps(signature_json),
|
||||
service=service,
|
||||
node=node,
|
||||
item=item,
|
||||
)
|
||||
assert sign_data["signer"] == "account1@server1.test"
|
||||
assert sign_data["validated"] == True
|
||||
|
|
@ -402,13 +401,18 @@ class TestE2EEncryption:
|
|||
source_file = fake_file.size(10240)
|
||||
source_file_hash = fake_file.get_source_hash(source_file)
|
||||
send_cmd = li.file.send(
|
||||
source_file, "account1@server2.test", encrypt=True, _bg=True,
|
||||
source_file,
|
||||
"account1@server2.test",
|
||||
encrypt=True,
|
||||
_bg=True,
|
||||
)
|
||||
dest_path = fake_file.dest_files / "test_send_receive"
|
||||
dest_path.mkdir()
|
||||
try:
|
||||
li.file.receive(
|
||||
"account1@server1.test", profile="account1_s2", path=dest_path,
|
||||
"account1@server1.test",
|
||||
profile="account1_s2",
|
||||
path=dest_path,
|
||||
)
|
||||
dest_file = dest_path / source_file.name
|
||||
dest_file_hash = fake_file.get_dest_hash(dest_file)
|
||||
|
|
@ -425,18 +429,21 @@ class TestE2EEncryption:
|
|||
node = "e2ee_blog"
|
||||
item = "test_pte"
|
||||
li.encryption.start("account1@server2.test", name="omemo")
|
||||
li.encryption.start(
|
||||
"account1@server1.test", name="omemo", profile="account1_s2"
|
||||
)
|
||||
li.encryption.start("account1@server1.test", name="omemo", profile="account1_s2")
|
||||
li.blog.set(
|
||||
_in=secret_blog, node="e2ee_blog", item=item,
|
||||
encrypt_for="account1@server2.test"
|
||||
_in=secret_blog,
|
||||
node="e2ee_blog",
|
||||
item=item,
|
||||
encrypt_for="account1@server2.test",
|
||||
)
|
||||
|
||||
# the item should be transparently decrypted
|
||||
parsed_decrypted = li_elt.pubsub.get(
|
||||
service="account1@server1.test", node=node, item=item, no_cache=True,
|
||||
profile="account1_s2"
|
||||
service="account1@server1.test",
|
||||
node=node,
|
||||
item=item,
|
||||
no_cache=True,
|
||||
profile="account1_s2",
|
||||
)
|
||||
entry_elt = parsed_decrypted.firstChildElement()
|
||||
assert entry_elt.name == "entry"
|
||||
|
|
|
|||
Loading…
Reference in a new issue