-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d5821e9
commit 76a9dea
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import os | ||
import unittest | ||
|
||
from playwright.sync_api import expect, sync_playwright # 1.37.0 | ||
|
||
|
||
class TestLeaflet(unittest.TestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
cls.p = sync_playwright().start() | ||
cls.browser = cls.p.chromium.launch() | ||
cls.context = cls.browser.new_context() | ||
cls.context.set_default_timeout(500_000) | ||
|
||
def setUp(self): | ||
self.page = TestLeaflet.context.new_page() | ||
|
||
def tearDown(self): | ||
self.page.close() | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
cls.context.close() | ||
cls.browser.close() | ||
cls.p.stop() | ||
|
||
def navigate_to_upload_page(self, page): | ||
base_url = 'http://localhost:8000/' | ||
page.goto(base_url) | ||
page.get_by_role('link', name='Upload a leaflet').click() | ||
page.get_by_text('Take a photo of a leaflet').click() | ||
|
||
def fill_postcode_and_submit(self, page, postcode='SW1A AA'): | ||
page.get_by_label('What postcode was this').click() | ||
page.get_by_label('What postcode was this').fill(postcode) | ||
page.get_by_role('button', name='Submit').click() | ||
page.get_by_text('Green Party').click() | ||
page.get_by_role('button', name='Submit').click() | ||
page.get_by_text('Thank you so much!') | ||
|
||
def test_basic_upload(self): | ||
self.navigate_to_upload_page(self.page) | ||
self.page.get_by_label('Take a photo of a leaflet').set_input_files('../test_media/test_images/test_leaflet.jpeg') | ||
self.page.get_by_role('button', name='Continue').click() | ||
self.fill_postcode_and_submit(self.page) | ||
|
||
def test_uploading_multiple_leaflet_images(self): | ||
self.navigate_to_upload_page(self.page) | ||
image_dir = 'electionleaflets/test_media/test_images' | ||
image_files = [f'{image_dir}/{file}' for file in os.listdir(image_dir)] | ||
self.page.get_by_label('Take a photo of a leaflet').set_input_files(image_files) | ||
self.page.get_by_role('button', name='Continue').click() | ||
self.fill_postcode_and_submit(self.page) | ||
|
||
def test_uploading_non_image_leaflet_file(self): | ||
self.navigate_to_upload_page(self.page) | ||
self.page.get_by_label('Take a photo of a leaflet').set_input_files('../test_media/test_images/test_leaflet.docx') | ||
self.page.get_by_role('button', name='Continue').click() | ||
self.page.get_by_text('Error during upload tap to retry') | ||
|
||
def test_read_leaflet_from_latest_leaflets(self): | ||
base_url = 'http://localhost:8000/' | ||
self.page.goto(base_url) | ||
self.page.get_by_role('link', name='Latest leaflets').click() | ||
self.page.locator('.ds-card-link').first().click() | ||
self.page.get_by_text('Leaflet details') | ||
|
||
if __name__ == "__main__": | ||
unittest.main(verbosity=2) |