What should I test if I have created a scenario with Python (bottle + mako) and web front-end to download a PDF file for registered users? I can use selenium to start Firefox, login and trigger the PDF file download, and then (theoretically, I didn't try it) I can use a tool like textract to extract to text from the PDF file and inspect that it has the expected text and not an error message.
However the nature of my use case is that the file won't download at all if something is wrong and I'm rendering HTML onto a PDF using the python tool pdfkit:
import pdfkit to_pdf_file = '/tmp/output.pdf' from bottle import static_file css = '/srv/http/python.dev/python-common/assets/static_files/css/styles.css' pdfkit.from_string(render_template("oncall/dayview_reload", values), to_pdf_file, css=css) return static_file('output.pdf', root='/tmp', download='output.pdf')
So it feels rather pointless to test the PDF instead of testing the HTML because in practice I would only test that the third-party library pdfkit is working on, not testing my code.
I feel that I might as well test only the HTML that it renders and prints the correct result, or would it be important to actually test that the PDF is generated and prints the correct data?
Or should I use some other approach to make my test "right" ?
My test code looks like the following right now, it starts selenium and makes the download, but I feel that I might as well test only the HTML instead of the PDF.
class ViewTest(unittest.TestCase): @classmethod def setUp(cls): cls.driver = webdriver.Firefox() cls.driver.implicitly_wait(20) cls.driver.maximize_window() cls.driver.get("http://python.dev/oncall/daily_reload?oncall_customer_ids=417&oncall_customer_id=417") def test_1(self): username_input = self.driver.find_element_by_name("email") username_input.send_keys('email@example.com') password_input = self.driver.find_element_by_name("password") password_input.send_keys('ex4mple1') self.driver.find_element_by_css_selector('.btn.btn-primary.btn-block.btn-lg').click() print("done")