From a2350c459150e32bf383f6c79d96b0b680e582e6 Mon Sep 17 00:00:00 2001 From: Wolfgang Steitz Date: Thu, 2 Feb 2017 16:50:39 +0100 Subject: [PATCH] test: code cleanup --- test/test_backup.py | 9 ++++----- test/test_carddav.py | 2 -- test/test_mail.py | 39 ++------------------------------------- 3 files changed, 6 insertions(+), 44 deletions(-) diff --git a/test/test_backup.py b/test/test_backup.py index 28be8c94..b8edc9da 100644 --- a/test/test_backup.py +++ b/test/test_backup.py @@ -4,7 +4,6 @@ from subprocess import check_call, check_output import smtplib from settings import * -from common import random_id from test_mail import new_message, check_imap_received @@ -16,7 +15,7 @@ def test_backup_mail(): s.login(TEST_ADDRESS, TEST_PASSWORD) s.sendmail(TEST_ADDRESS, [TEST_ADDRESS], msg) s.quit() - + # trigger a backup sleep(2) cmd_ssh = "sshpass -p vagrant ssh vagrant@{} -p {} ".format(TEST_SERVER, TEST_PORT) @@ -26,11 +25,11 @@ def test_backup_mail(): check_call(cmd, shell=True) num_backup_files_new = int(check_output(cmd_count, shell=True)) assert num_backup_files_new > num_backup_files - + # delete mail assert check_imap_received(subject) assert not check_imap_received(subject) - + # restore backup path = "/home/user-data" passphrase = "export PASSPHRASE=\$(sudo cat /home/user-data/backup/secret_key.txt) &&" @@ -40,6 +39,6 @@ def test_backup_mail(): move = "sudo rsync -av {0}/restore/* {0}/ &&".format(path) rm = "sudo rm -rf {0}/restore/".format(path) check_call(cmd_ssh + "\"" + passphrase + restore + move + rm + "\"", shell=True) - + # check the mail is there again assert check_imap_received(subject) diff --git a/test/test_carddav.py b/test/test_carddav.py index a19b1435..a23c96dc 100644 --- a/test/test_carddav.py +++ b/test/test_carddav.py @@ -1,9 +1,7 @@ import pytest from pycarddav import carddav -from time import sleep from settings import * -from common import random_id test_vcf = """ diff --git a/test/test_mail.py b/test/test_mail.py index 80003e1f..227fc0eb 100644 --- a/test/test_mail.py +++ b/test/test_mail.py @@ -18,7 +18,7 @@ def new_message(from_email, to_email): msg['From'] = from_email msg['To'] = to_email return msg.as_string(), msg['subject'] - + def check_imap_received(subject): @@ -34,7 +34,7 @@ def check_imap_received(subject): # check the message exists typ, data = m.search(None, '(SUBJECT \"{}\")'.format(subject)) res = len(data[0].split()) == 1 - + if res: m.store(data[0].strip(), '+FLAGS', '\\Deleted') m.expunge() @@ -132,41 +132,6 @@ def test_smtp_tls(): assert check_imap_received(subject) -# FIXME -#def test_smtps_headers(): -# """Email sent from an MUA has DKIM and TLS headers""" -# import smtplib -# import imaplib -# -# # Send a message to admin -# mail_address = "admin@" + TEST_DOMAIN -# msg, subject = new_message(TEST_ADDRESS, mail_address) -# s = smtplib.SMTP(TEST_DOMAIN, 587) -# s.starttls() -# s.login(TEST_ADDRESS, TEST_PASSWORD) -# s.sendmail(TEST_ADDRESS, [mail_address], msg) -# s.quit() -# -# sleep(3) -# -# # Get the message -# m = imaplib.IMAP4_SSL(TEST_DOMAIN, 993) -# m.login(TEST_ADDRESS, TEST_PASSWORD) -# m.select() -# _, res = m.search(None, '(SUBJECT \"{}\")'.format(subject)) -# _, data = m.fetch(res[0], '(RFC822)') -# -# assert 'DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailinabox.lan;' in data[0][1] -# -# assert 'ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)' in data[0][1] -# -# # Clean up -# m.store(res[0].strip(), '+FLAGS', '\\Deleted') -# m.expunge() -# m.close() -# m.logout() - - def test_smtp_headers(): """Email sent from an MTA via SMTP+TLS has TLS headers""" # Send a message to root