66 lines
2.7 KiB
Python
66 lines
2.7 KiB
Python
import io
|
|
|
|
from pdfminer.high_level import extract_text
|
|
from selenium.webdriver.common.keys import Keys
|
|
|
|
from .base import SearchExportTester
|
|
|
|
|
|
class TestSteeringCommitteePrintLabels(SearchExportTester):
|
|
"""Tests the pdf labels for the SteeringCommitee show all contacts names"""
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
self.title("Steering Committee Print Labels")
|
|
self.desc(
|
|
"Testing the pdf labels for the SteeringCommittee show all contacts names"
|
|
)
|
|
self.group_dropdown = "s2id_autogen2"
|
|
self.search_button = "_qf_Basic_refresh"
|
|
# FIXME: THIS FUCKING CHANGES!!!!!!
|
|
# If you are having issues with the tests, go back and try and find the id for the item in the drop down. its all stupid js so we have to hack it like this and press it instead of post request
|
|
# Even in the post requests, actions are given IDs instead. Which change apparently!!!!! WTFFF!!!
|
|
self.mail_label_option = "select2-result-label-17"
|
|
# Using this to count amount of people in the exported pdf
|
|
# This will fail if someone is added that doesn't have a UK adddress
|
|
self.pdf_search_string = "UNITED KINGDOM"
|
|
|
|
def _test(self):
|
|
self.browser.get(self.search_url)
|
|
group_dropdown = self.find_element_by_id(self.group_dropdown)
|
|
group_dropdown.click()
|
|
group_dropdown.send_keys("Steering Committee" + Keys.ENTER)
|
|
self.find_element_by_id(self.search_button).click()
|
|
self._wait_for_search_to_load()
|
|
result_no = self._get_contact_search_number()
|
|
self.debug("exporting results using the magic dropdown")
|
|
self._select_option_from_magic_dropdown(self.mail_label_option)
|
|
# By omitting the field, we are effectively disabling the do not mail filter
|
|
data = {
|
|
"_qf_default": "Label:submit",
|
|
# Smallest labels, will show 24 contacts on one page
|
|
"label_name": "3475",
|
|
"location_type_id": "",
|
|
"_qf_Label_submit": "Make+Mailing+Labels"
|
|
}
|
|
res = self.download_export(data)
|
|
pdf_text = extract_text(io.BytesIO(res.content))
|
|
label_count = pdf_text.count(self.pdf_search_string)
|
|
if result_no == label_count:
|
|
self.passed(
|
|
"no missing mailing labels from pdf export. Expected: %d, Actual %d"
|
|
% (result_no, label_count)
|
|
)
|
|
else:
|
|
self.failed(
|
|
"missing mailing labels from the pdf export. Expected: %d, Actual %d"
|
|
% (result_no, label_count)
|
|
)
|
|
|
|
def test(self):
|
|
try:
|
|
self.login()
|
|
self._test()
|
|
finally:
|
|
self.logout()
|
|
self.browser.close()
|