Commit dd43d6ac authored by Swergas's avatar Swergas

implement steps 'credential authority sends credentials to voters' and...

implement steps 'credential authority sends credentials to voters' and 'administrator invites trustees'
parent f5958091
......@@ -22,3 +22,10 @@ ADMINISTRATOR_USERNAME = "user1" # This value comes from file `demo/password_db.
ADMINISTRATOR_PASSWORD = "phiexoey" # This value comes from file `demo/password_db.csv`, first row, 4th column
GIT_REPOSITORY_ABSOLUTE_PATH = dirname(dirname(abspath(__file__)))
# These variables are used by Scenario 2 only
BROWSER_DOWNLOAD_FOLDER = "/tmp"
ADMINISTRATOR_EMAIL_ADDRESS = "alice_aka_election_administrator@mailinator.com"
CREDENTIAL_AUTHORITY_EMAIL_ADDRESS = "cecily_aka_election_credential_authority@mailinator.com"
TRUSTEES_EMAIL_ADDRESSES = ["tom_aka_trustee_1@mailinator.com", "taylor_aka_trustee_2@mailinator.com"]
\ No newline at end of file
......@@ -229,14 +229,30 @@ def initialize_server():
return server
def initialize_browser():
def initialize_browser(for_scenario_2=False):
browser = None
if for_scenario_2:
# Test Scenario 2 requires users to download things from their browser.
# Define a custom profile for Firefox, to automatically download files that a page asks user to download, without asking. This is because Selenium can't control downloads.
profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.folderList', 2) # Can be set to either 0, 1, or 2. When set to 0, Firefox will save all files downloaded via the browser on the user's desktop. When set to 1, these downloads are stored in the Downloads folder. When set to 2, the location specified for the most recent download is utilized again.
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference('browser.download.dir', settings.BROWSER_DOWNLOAD_FOLDER)
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'text/plain')
if settings.USE_HEADLESS_BROWSER:
from selenium.webdriver.firefox.options import Options
options = Options()
options.add_argument("--headless")
options.log.level = "trace"
if for_scenario_2:
browser = webdriver.Firefox(profile, options=options)
else:
browser = webdriver.Firefox(options=options)
else:
if for_scenario_2:
browser = webdriver.Firefox(profile)
else:
browser = webdriver.Firefox()
browser.implicitly_wait(settings.WAIT_TIME_BETWEEN_EACH_STEP) # In seconds
......
This diff is collapsed.
......@@ -60,3 +60,28 @@ class FakeSentEmailsManager:
def uninstall_fake_sendmail_log_file(self):
subprocess.run(["rm", "-f", self.log_file_path]) # TODO: Execute a command that works on other OS, like `os.remove()`
def send_email(self, from_email_address, to_email_address, subject, content):
from datetime import datetime
username_and_email_format = "\"{username}\" <{email_address}>"
from_label = username_and_email_format.format(username=from_email_address, email_address=from_email_address)
to_label = username_and_email_format.format(username=to_email_address, email_address=to_email_address)
date_label = datetime.now().strftime("%a, %d %b %Y %H:%M:%S %z")
full_content_format = """\
Content-type: text/plain; charset="UTF-8"
Content-transfer-encoding: quoted-printable
From: {from_label}
To: {to_label}
Subject: {subject}
MIME-Version: 1.0
X-Mailer: Belenios Automated Tests
Date: {date_label}
{content}
--=20\
"""
full_content = full_content_format.format(from_label=from_label, to_label=to_label, subject=subject, date_label=date_label, content=content)
with open(self.log_file_path, "a") as myfile:
myfile.write(full_content)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment