Commit b69badfb authored by Swergas's avatar Swergas

code style: respect PEP8 except line length and E501,E261,E303

parent 9fbdfc0e
......@@ -62,11 +62,12 @@ def count_occurences_in_sent_emails(text):
return count
"""
Converts the file that gathers all sent emails to an array with one element per sent email. Each element is a dictionary with fields "to", "subject", and "full_content".
:return: array
"""
def separate_sent_emails():
"""
Converts the file that gathers all sent emails to an array with one element per sent email. Each element is a dictionary with fields "to", "subject", and "full_content".
:return: array
"""
# Email content is encoded using "quoted-printable" encoding. Please refer to https://en.wikipedia.org/wiki/Quoted-printable for more information. For example, this enconding transforms "@" into "=40". TODO: We could improve this function by having it directly decode the part of the email that is encoded, using `quopri` library for example.
marker_for_end_of_email = "--=20"
result = []
......@@ -97,11 +98,12 @@ def separate_sent_emails():
return result
"""
Reads the file that gathers all sent emails to find, for each voter provided in array voters_email_addresses, their credential and their latest sent password. Returns an array, where each element is a dictionary with fields "email_address", "credential", "election_page_url", "username", and "password".
:return: array
"""
def populate_credential_and_password_for_voters_from_sent_emails(voters_email_addresses, election_title):
"""
Reads the file that gathers all sent emails to find, for each voter provided in array voters_email_addresses, their credential and their latest sent password. Returns an array, where each element is a dictionary with fields "email_address", "credential", "election_page_url", "username", and "password".
:return: array
"""
result = []
sent_emails = separate_sent_emails()
for voter_email_address in voters_email_addresses:
......@@ -246,6 +248,7 @@ def repopulate_vote_confirmations_for_voters_from_sent_emails(voters_with_creden
voter["smart_ballot_tracker_in_vote_confirmation_email"] = voter_smart_ballot_confirmation
return voters_with_credentials
def remove_database_folder():
shutil.rmtree(os.path.join(GIT_REPOSITORY_ABSOLUTE_PATH, DATABASE_FOLDER_PATH_RELATIVE_TO_GIT_REPOSITORY), ignore_errors=True)
......@@ -344,11 +347,11 @@ def verify_election_consistency(election_id, snapshot_folder=None):
print("Verification of election consistency has been correctly processed")
assert match
else:
raise Exception ("Error: Verification of election consistency is wrong. STDOUT was: " + outs + " STDERR was:" + errs)
raise Exception("Error: Verification of election consistency is wrong. STDOUT was: " + outs + " STDERR was:" + errs)
except subprocess.TimeoutExpired:
running_process.kill()
outs, errs = proc.communicate()
raise Exception ("Error: Verification took longer than " + process_timeout + " seconds. STDOUT was: " + outs + " STDERR was:" + errs)
outs, errs = running_process.communicate()
raise Exception("Error: Verification took longer than " + process_timeout + " seconds. STDOUT was: " + outs + " STDERR was:" + errs)
def create_election_data_snapshot(election_id):
......@@ -437,11 +440,11 @@ def wait_for_element_exists_and_contains_expected_text(browser, css_selector, ex
:return: The WebElement once it matches expected conditions
"""
try:
ignored_exceptions=(NoSuchElementException,StaleElementReferenceException,)
ignored_exceptions = (NoSuchElementException, StaleElementReferenceException,)
custom_wait = WebDriverWait(browser, wait_duration, ignored_exceptions=ignored_exceptions)
page_title_element = custom_wait.until(element_exists_and_contains_expected_text((By.CSS_SELECTOR, css_selector), expected_text))
return page_title_element
except:
except Exception:
raise Exception("Could not find expected DOM element '" + css_selector + "' with text content '" + expected_text + "' until timeout of " + str(wait_duration) + " seconds")
......@@ -557,7 +560,7 @@ class BeleniosTestElectionScenario1(unittest.TestCase):
# She arrives back on the logged out home page. She checks that a login link is present
login_link_id = "login_local"
login_element = browser.find_element_by_id(login_link_id)
browser.find_element_by_id(login_link_id)
def administrator_creates_election(self):
......@@ -622,7 +625,7 @@ class BeleniosTestElectionScenario1(unittest.TestCase):
# She removes answer 3
question_to_remove = 3
remove_button_css_selector = ".question_answers > div:nth-child("+str(question_to_remove)+") button:nth-child(2)"
remove_button_css_selector = ".question_answers > div:nth-child(" + str(question_to_remove) + ") button:nth-child(2)"
remove_button_element = browser.find_element_by_css_selector(remove_button_css_selector)
remove_button_element.click()
......@@ -691,7 +694,7 @@ class BeleniosTestElectionScenario1(unittest.TestCase):
"""
An email sent by Belenios (using sendmail or using the fake sendmail) to a voter looks like this:
Content-type: text/plain; charset="UTF-8"
Content-type: text/plain; charset="UTF-8"
Content-transfer-encoding: quoted-printable
From: Belenios public server <noreply@example.org>
To: "820E7G83JBY0F4Z3DY2Y@mailinator.com"
......@@ -811,7 +814,7 @@ pris en compte.
# She checks that a "Close election" button is present (but she does not click on it)
close_election_button_label = "Close election"
close_election_button_element = find_button_in_page_content_by_value(browser, close_election_button_label)
find_button_in_page_content_by_value(browser, close_election_button_label)
self.log_out()
......@@ -895,14 +898,15 @@ pris en compte.
self.log_out()
def some_voters_cast_their_vote(self, voters):
"""
:param voters: list of dict. Each element contains information about a voter (their e-mail address, the planned answers to each question they will cast)
"""
def some_voters_cast_their_vote(self, voters):
browser = self.browser
voters_count = len(voters)
for index, voter in enumerate(voters):
print("#### Current voter casting their vote in current batch: " + str(index+1) + "/" + str(voters_count))
print("#### Current voter casting their vote in current batch: " + str(index + 1) + "/" + str(voters_count))
# Bob has received 2 emails containing an invitation to vote and all necessary credentials (election page URL, username, password). He goes to the election page URL.
browser.get(voter["election_page_url"])
......@@ -926,7 +930,7 @@ pris en compte.
)
verify_element_label(here_button_element, here_button_expected_label)
here_button_element.click()
except:
except Exception:
raise Exception("Could not find expected DOM element until timeout")
wait_a_bit()
......@@ -1078,7 +1082,10 @@ pris en compte.
self.some_voters_cast_their_vote(voters_who_will_vote_now_data)
def all_voters_vote_in_sequences(self, verify_every_x_votes=5): # This function is an alias of some_voters_vote_in_sequences() using some default parameters, for readability
def all_voters_vote_in_sequences(self, verify_every_x_votes=5):
"""
This function is an alias of some_voters_vote_in_sequences() using some default parameters, for readability
"""
self.some_voters_vote_in_sequences(start_index=0, end_index=NUMBER_OF_VOTING_VOTERS, verify_every_x_votes=verify_every_x_votes)
def some_voters_vote_in_sequences(self, start_index=0, end_index=NUMBER_OF_VOTING_VOTERS, verify_every_x_votes=5):
......@@ -1105,9 +1112,9 @@ pris en compte.
print("#### Substep complete: create_election_data_snapshot")
try:
print("#### A batch of " + str(current_end_index - current_start_index) + " voters, indexed " + str(current_start_index) + " to " + str(current_end_index-1) + " are now going to vote")
print("#### A batch of " + str(current_end_index - current_start_index) + " voters, indexed " + str(current_start_index) + " to " + str(current_end_index - 1) + " are now going to vote")
self.some_voters_cast_their_vote(voters_who_will_vote_now_data[current_start_index:current_end_index])
print("#### A batch of " + str(current_end_index - current_start_index) + " voters, indexed " + str(current_start_index) + " to " + str(current_end_index-1) + " have now voted")
print("#### A batch of " + str(current_end_index - current_start_index) + " voters, indexed " + str(current_start_index) + " to " + str(current_end_index - 1) + " have now voted")
if current_start_index > 0:
print("#### Starting substep: verify_election_consistency using `belenios_tool verify-diff` (for a batch of votes)")
......@@ -1134,7 +1141,7 @@ pris en compte.
browser = self.browser
# Alice goes to the election page
election_url = self.election_page_url #self.voters_data[self.voters_email_addresses[0]]["election_page_url"]
election_url = self.election_page_url # Could also be obtained with self.voters_data[self.voters_email_addresses[0]]["election_page_url"]
browser.get(election_url)
wait_a_bit()
......
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