Mercurial > libervia-backend
diff tests/e2e/libervia-cli/test_libervia-cli.py @ 4305:4cd4922de876
tests: reformat tests using black.
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 26 Sep 2024 16:11:56 +0200 |
parents | f59e9421a650 |
children |
line wrap: on
line diff
--- a/tests/e2e/libervia-cli/test_libervia-cli.py Fri Sep 06 18:07:44 2024 +0200 +++ b/tests/e2e/libervia-cli/test_libervia-cli.py Thu Sep 26 16:11:56 2024 +0200 @@ -34,7 +34,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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=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=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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ assert source_file_hash == dest_file_hash - class TestE2EEncryption: def test_pubsub_encryption_oxps(self, li_elt): @@ -324,9 +314,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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"