2021-01-25 20:48:43 +00:00
import io
from pdfminer . high_level import extract_text
from selenium . webdriver . common . keys import Keys
from . base import SearchExportTester
2021-10-24 19:19:30 +00:00
class TestSteeringCommitteePrintLabels ( SearchExportTester ) :
2021-01-25 20:48:43 +00:00
""" 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 "
2021-10-20 12:57:23 +00:00
# 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 "
2021-01-25 20:48:43 +00:00
# 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 ( )
2021-01-25 21:21:14 +00:00
self . _wait_for_search_to_load ( )
result_no = self . _get_contact_search_number ( )
2021-01-25 20:48:43 +00:00
self . debug ( " exporting results using the magic dropdown " )
2021-01-25 21:21:14 +00:00
self . _select_option_from_magic_dropdown ( self . mail_label_option )
2021-01-25 20:48:43 +00:00
# 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 "
}
2021-01-25 21:21:14 +00:00
res = self . download_export ( data )
2021-01-25 20:48:43 +00:00
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 ( )