Skip to content

Commit 8da21e3

Browse files
committed
test: use vCards more in Python tests
1 parent 8298136 commit 8da21e3

File tree

3 files changed

+23
-42
lines changed

3 files changed

+23
-42
lines changed

deltachat-rpc-client/tests/test_chatlist_events.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ def test_delivery_status(acfactory: ACFactory) -> None:
4848
"""
4949
alice, bob = acfactory.get_online_accounts(2)
5050

51-
bob_addr = bob.get_config("addr")
52-
alice_contact_bob = alice.create_contact(bob_addr, "Bob")
51+
alice_contact_bob = alice.create_contact(bob, "Bob")
5352
alice_chat_bob = alice_contact_bob.create_chat()
5453

5554
alice.clear_all_events()
@@ -119,8 +118,7 @@ def test_download_on_demand(acfactory: ACFactory) -> None:
119118
"""
120119
alice, bob = acfactory.get_online_accounts(2)
121120

122-
bob_addr = bob.get_config("addr")
123-
alice_contact_bob = alice.create_contact(bob_addr, "Bob")
121+
alice_contact_bob = alice.create_contact(bob, "Bob")
124122
alice_chat_bob = alice_contact_bob.create_chat()
125123
alice_chat_bob.send_text("hi")
126124

@@ -150,8 +148,7 @@ def test_download_on_demand(acfactory: ACFactory) -> None:
150148
def get_multi_account_test_setup(acfactory: ACFactory) -> [Account, Account, Account]:
151149
alice, bob = acfactory.get_online_accounts(2)
152150

153-
bob_addr = bob.get_config("addr")
154-
alice_contact_bob = alice.create_contact(bob_addr, "Bob")
151+
alice_contact_bob = alice.create_contact(bob, "Bob")
155152
alice_chat_bob = alice_contact_bob.create_chat()
156153
alice_chat_bob.send_text("hi")
157154

deltachat-rpc-client/tests/test_securejoin.py

+9-13
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ def test_qr_securejoin_contact_request(acfactory) -> None:
117117
"""Alice invites Bob to a group when Bob's chat with Alice is in a contact request mode."""
118118
alice, bob = acfactory.get_online_accounts(2)
119119

120-
bob_addr = bob.get_config("addr")
121-
alice_contact_bob = alice.create_contact(bob_addr, "Bob")
120+
alice_contact_bob = alice.create_contact(bob, "Bob")
122121
alice_chat_bob = alice_contact_bob.create_chat()
123122
alice_chat_bob.send_text("Hello!")
124123

@@ -155,11 +154,8 @@ def test_qr_readreceipt(acfactory) -> None:
155154
logging.info("Alice creates a verified group")
156155
group = alice.create_group("Group", protect=True)
157156

158-
bob_addr = bob.get_config("addr")
159-
charlie_addr = charlie.get_config("addr")
160-
161-
alice_contact_bob = alice.create_contact(bob_addr, "Bob")
162-
alice_contact_charlie = alice.create_contact(charlie_addr, "Charlie")
157+
alice_contact_bob = alice.create_contact(bob, "Bob")
158+
alice_contact_charlie = alice.create_contact(charlie, "Charlie")
163159

164160
group.add_contact(alice_contact_bob)
165161
group.add_contact(alice_contact_charlie)
@@ -186,7 +182,7 @@ def test_qr_readreceipt(acfactory) -> None:
186182
charlie_snapshot = charlie_message.get_snapshot()
187183
assert charlie_snapshot.text == "Hi from Bob!"
188184

189-
bob_contact_charlie = bob.create_contact(charlie_addr, "Charlie")
185+
bob_contact_charlie = bob.create_contact(charlie, "Charlie")
190186
assert not bob.get_chat_by_contact(bob_contact_charlie)
191187

192188
logging.info("Charlie reads Bob's message")
@@ -517,9 +513,9 @@ def test_gossip_verification(acfactory) -> None:
517513
bob.secure_join(qr_code)
518514
bob.wait_for_securejoin_joiner_success()
519515

520-
bob_contact_alice = bob.create_contact(alice.get_config("addr"), "Alice")
521-
bob_contact_carol = bob.create_contact(carol.get_config("addr"), "Carol")
522-
carol_contact_alice = carol.create_contact(alice.get_config("addr"), "Alice")
516+
bob_contact_alice = bob.create_contact(alice, "Alice")
517+
bob_contact_carol = bob.create_contact(carol, "Carol")
518+
carol_contact_alice = carol.create_contact(alice, "Alice")
523519

524520
logging.info("Bob creates an Autocrypt group")
525521
bob_group_chat = bob.create_group("Autocrypt Group")
@@ -579,7 +575,7 @@ def test_securejoin_after_contact_resetup(acfactory) -> None:
579575
ac2.wait_for_securejoin_joiner_success()
580576

581577
# ac1 is verified for ac2.
582-
ac2_contact_ac1 = ac2.create_contact(ac1.get_config("addr"), "")
578+
ac2_contact_ac1 = ac2.create_contact(ac1, "")
583579
assert ac2_contact_ac1.get_snapshot().is_verified
584580

585581
# ac1 resetups the account.
@@ -594,7 +590,7 @@ def test_securejoin_after_contact_resetup(acfactory) -> None:
594590
# header sent by old ac1.
595591
while True:
596592
# ac1 sends a message to ac2.
597-
ac1_contact_ac2 = ac1.create_contact(ac2.get_config("addr"), "")
593+
ac1_contact_ac2 = ac1.create_contact(ac2, "")
598594
ac1_chat_ac2 = ac1_contact_ac2.create_chat()
599595
ac1_chat_ac2.send_text("Hello!")
600596

deltachat-rpc-client/tests/test_something.py

+11-23
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def test_account(acfactory) -> None:
106106
alice, bob = acfactory.get_online_accounts(2)
107107

108108
bob_addr = bob.get_config("addr")
109-
alice_contact_bob = alice.create_contact(bob_addr, "Bob")
109+
alice_contact_bob = alice.create_contact(bob, "Bob")
110110
alice_chat_bob = alice_contact_bob.create_chat()
111111
alice_chat_bob.send_text("Hello!")
112112

@@ -171,8 +171,7 @@ def test_account(acfactory) -> None:
171171
def test_chat(acfactory) -> None:
172172
alice, bob = acfactory.get_online_accounts(2)
173173

174-
bob_addr = bob.get_config("addr")
175-
alice_contact_bob = alice.create_contact(bob_addr, "Bob")
174+
alice_contact_bob = alice.create_contact(bob, "Bob")
176175
alice_chat_bob = alice_contact_bob.create_chat()
177176
alice_chat_bob.send_text("Hello!")
178177

@@ -238,7 +237,7 @@ def test_contact(acfactory) -> None:
238237
alice, bob = acfactory.get_online_accounts(2)
239238

240239
bob_addr = bob.get_config("addr")
241-
alice_contact_bob = alice.create_contact(bob_addr, "Bob")
240+
alice_contact_bob = alice.create_contact(bob, "Bob")
242241

243242
assert alice_contact_bob == alice.get_contact_by_id(alice_contact_bob.id)
244243
assert repr(alice_contact_bob)
@@ -255,8 +254,7 @@ def test_contact(acfactory) -> None:
255254
def test_message(acfactory) -> None:
256255
alice, bob = acfactory.get_online_accounts(2)
257256

258-
bob_addr = bob.get_config("addr")
259-
alice_contact_bob = alice.create_contact(bob_addr, "Bob")
257+
alice_contact_bob = alice.create_contact(bob, "Bob")
260258
alice_chat_bob = alice_contact_bob.create_chat()
261259
alice_chat_bob.send_text("Hello!")
262260

@@ -314,8 +312,7 @@ def test_reaction_seen_on_another_dev(acfactory) -> None:
314312
alice2 = alice.clone()
315313
alice2.start_io()
316314

317-
bob_addr = bob.get_config("addr")
318-
alice_contact_bob = alice.create_contact(bob_addr, "Bob")
315+
alice_contact_bob = alice.create_contact(bob, "Bob")
319316
alice_chat_bob = alice_contact_bob.create_chat()
320317
alice_chat_bob.send_text("Hello!")
321318

@@ -332,17 +329,15 @@ def test_reaction_seen_on_another_dev(acfactory) -> None:
332329
alice2.clear_all_events()
333330
alice_chat_bob.mark_noticed()
334331
chat_id = alice2.wait_for_event(EventType.MSGS_NOTICED).chat_id
335-
alice2_contact_bob = alice2.get_contact_by_addr(bob_addr)
336-
alice2_chat_bob = alice2_contact_bob.create_chat()
332+
alice2_chat_bob = alice2.create_chat(bob)
337333
assert chat_id == alice2_chat_bob.id
338334

339335

340336
def test_is_bot(acfactory) -> None:
341337
"""Test that we can recognize messages submitted by bots."""
342338
alice, bob = acfactory.get_online_accounts(2)
343339

344-
bob_addr = bob.get_config("addr")
345-
alice_contact_bob = alice.create_contact(bob_addr, "Bob")
340+
alice_contact_bob = alice.create_contact(bob, "Bob")
346341
alice_chat_bob = alice_contact_bob.create_chat()
347342

348343
# Alice becomes a bot.
@@ -412,8 +407,7 @@ def test_wait_next_messages(acfactory) -> None:
412407
# Bot starts waiting for messages.
413408
next_messages_task = executor.submit(bot.wait_next_messages)
414409

415-
bot_addr = bot.get_config("addr")
416-
alice_contact_bot = alice.create_contact(bot_addr, "Bot")
410+
alice_contact_bot = alice.create_contact(bot, "Bot")
417411
alice_chat_bot = alice_contact_bot.create_chat()
418412
alice_chat_bot.send_text("Hello!")
419413

@@ -437,9 +431,7 @@ def test_import_export_backup(acfactory, tmp_path) -> None:
437431
def test_import_export_keys(acfactory, tmp_path) -> None:
438432
alice, bob = acfactory.get_online_accounts(2)
439433

440-
bob_addr = bob.get_config("addr")
441-
alice_contact_bob = alice.create_contact(bob_addr, "Bob")
442-
alice_chat_bob = alice_contact_bob.create_chat()
434+
alice_chat_bob = alice.create_chat(bob)
443435
alice_chat_bob.send_text("Hello Bob!")
444436

445437
snapshot = bob.get_message_by_id(bob.wait_for_incoming_msg_event().msg_id).get_snapshot()
@@ -489,9 +481,7 @@ def test_provider_info(rpc) -> None:
489481
def test_mdn_doesnt_break_autocrypt(acfactory) -> None:
490482
alice, bob = acfactory.get_online_accounts(2)
491483

492-
bob_addr = bob.get_config("addr")
493-
494-
alice_contact_bob = alice.create_contact(bob_addr, "Bob")
484+
alice_contact_bob = alice.create_contact(bob, "Bob")
495485

496486
# Bob creates chat manually so chat with Alice is accepted.
497487
alice_chat_bob = alice_contact_bob.create_chat()
@@ -633,9 +623,7 @@ def test_download_limit_chat_assignment(acfactory, tmp_path, n_accounts):
633623
chat.send_text("Hello Alice!")
634624
assert alice.get_message_by_id(alice.wait_for_incoming_msg_event().msg_id).get_snapshot().text == "Hello Alice!"
635625

636-
contact_addr = account.get_config("addr")
637-
contact = alice.create_contact(contact_addr, "")
638-
626+
contact = alice.create_contact(account)
639627
alice_group.add_contact(contact)
640628

641629
if n_accounts == 2:

0 commit comments

Comments
 (0)