Skip to content

Commit

Permalink
Add script to create email tag test cases
Browse files Browse the repository at this point in the history
As #11 has a number of cases that we want to detect
and possibly handle differently, test cases are needed.

To create them reliably and without we use a script that creates
sql commands. An alternative is have been to go through the
fody-backend, but which would require one more component to run
for building the test cases.
  • Loading branch information
bernhardreiter committed Feb 25, 2021
1 parent fb27388 commit 33490a9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
To be placed in `intelmq/tests/bots/`.
`certbund_contact` is to be placed in `intelmq/tests/bots/`.
38 changes: 38 additions & 0 deletions tests/create_email_tag_cases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env python3
"""Create email tag example cases from a list of email addresses.
The convention is that email addresses in the db have been changed
by prepending an 'x-', so they differ from what the current ripe files have.
We call them emailA.
When run with ripe_diff the emails coming from the ripe files would be
imported, thus new, we call them emailB.
Precondition: At least we have tag_id 1 and 2 in the db.
We skip safety checks and ignore style as this is for development. :)
"""
import fileinput

def emailB(f):
return f.readline().rstrip('\n')

def emailA(f):
return 'x-' + emailB(f)

db_lines = []

with fileinput.input() as f:
# case 1: both addresses have no tags, we do nothing
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"))

# 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))

# TODO

for db_line in db_lines:
print(db_line)

0 comments on commit 33490a9

Please sign in to comment.