From bed6ca638984d68b3f57ac23c5d882a4827aeb94 Mon Sep 17 00:00:00 2001 From: Bernhard Reiter Date: Fri, 26 Feb 2021 16:57:43 +0100 Subject: [PATCH] complete create_email_tag_cases.py with all cases useful for #11 --- tests/create_email_tag_cases.py | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/tests/create_email_tag_cases.py b/tests/create_email_tag_cases.py index fa62ae1..369c915 100755 --- a/tests/create_email_tag_cases.py +++ b/tests/create_email_tag_cases.py @@ -14,25 +14,41 @@ """ import fileinput -def emailB(f): - return f.readline().rstrip('\n') +def emailB(line): + if not line: + raise EOFError("not enough email addresses") + return line.rstrip('\n') -def emailA(f): - return 'x-' + emailB(f) +def emailA(line): + return 'x-' + emailB(line) db_lines = [] with fileinput.input() as f: # case 1: both addresses have no tags, we do nothing - f.readline() + db_lines.append("-- leaving '{}' alone".format(emailA(f.readline()))) # case 2.1.1: emailA is disabled, emailB not - db_lines.append("INSERT INTO email_status (email, enabled) VALUES ('{}','{}');".format(emailA(f), "false")) + db_lines.append("INSERT INTO email_status (email, enabled) VALUES ('{}','{}');".format(emailA(f.readline()), "false")) # case 2.1.2: emailA has a tag, emailB not - db_lines.append("INSERT INTO email_tag (email, tag_id) VALUES ('{}','{}');".format(emailA(f), 1)) + db_lines.append("INSERT INTO email_tag (email, tag_id) VALUES ('{}','{}');".format(emailA(f.readline()), 1)) - # TODO + # case 3.1: emailA is enabled (no entry), emailB is disabled + db_lines.append("INSERT INTO email_status (email, enabled) VALUES ('{}','{}');".format(emailB(f.readline()), "false")) + + # case 3.2: emailA has no tag, emailB has a tag + db_lines.append("INSERT INTO email_tag (email, tag_id) VALUES ('{}','{}');".format(emailB(f.readline()), 1)) + + # case 4.1: both are disabled + line = f.readline() + db_lines.append("INSERT INTO email_status (email, enabled) VALUES ('{}','{}');".format(emailA(line), "false")) + db_lines.append("INSERT INTO email_status (email, enabled) VALUES ('{}','{}');".format(emailB(line), "false")) + + # case 4.2: both have a tag + line = f.readline() + db_lines.append("INSERT INTO email_tag (email, tag_id) VALUES ('{}','{}');".format(emailA(line), 1)) + db_lines.append("INSERT INTO email_tag (email, tag_id) VALUES ('{}','{}');".format(emailB(line), 1)) for db_line in db_lines: print(db_line)