Skip to content

Commit

Permalink
complete create_email_tag_cases.py with all cases
Browse files Browse the repository at this point in the history
useful for #11
  • Loading branch information
bernhardreiter committed Feb 26, 2021
1 parent 0975c26 commit bed6ca6
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions tests/create_email_tag_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit bed6ca6

Please sign in to comment.