diff --git a/test/e2e/conftest.py b/test/e2e/conftest.py index af56251..bc193ef 100644 --- a/test/e2e/conftest.py +++ b/test/e2e/conftest.py @@ -4,7 +4,6 @@ from test.e2e.env_config import PORT from test.e2e.pageobjects.create_paste_page import CreatePastePage from typing import Generator - import pytest from playwright.sync_api import Page @@ -16,7 +15,16 @@ def application() -> Generator[None, None, None]: # Before All log.info(f"Starting Pinnwand application on port {PORT}") proc = subprocess.Popen( - [sys.executable, "-m", "pinnwand", "http", "--port", str(PORT)] + [ + sys.executable, + "-m", + "pinnwand", + "--configuration-path", + "test/e2e/pinnwand.toml", + "http", + "--port", + str(PORT), + ] ) yield # After All diff --git a/test/e2e/pageobjects/create_paste_page.py b/test/e2e/pageobjects/create_paste_page.py index a104600..7804b7b 100644 --- a/test/e2e/pageobjects/create_paste_page.py +++ b/test/e2e/pageobjects/create_paste_page.py @@ -18,6 +18,7 @@ def __init__(self, page: Page) -> None: self.paste_input = page.locator(".file-part textarea") self.submit_button = page.locator(".paste-submit button[type=submit]") self.add_another_paste_button = page.locator("button.add") + self.file_input = page.locator("#file-input") def open(self): log.info(f"Opening Pinnwand at {self.url}") @@ -35,6 +36,10 @@ def click_add_another_file_button(self): log.info("Clicking Add Another Paste Button") self.add_another_paste_button.click() + def add_file_to_file_input(self, file_paths): + log.info("Adding file for uploading") + self.file_input.set_input_files(file_paths) + # Step sequences def paste_random_text(self, paste_number=0): paste_text = string.ascii_letters + string.digits diff --git a/test/e2e/pinnwand.toml b/test/e2e/pinnwand.toml new file mode 100644 index 0000000..12b33f8 --- /dev/null +++ b/test/e2e/pinnwand.toml @@ -0,0 +1,11 @@ +ratelimit.read.capacity = 200 +ratelimit.read.consume = 1 +ratelimit.read.refill = 10 + +ratelimit.create.capacity = 200 +ratelimit.create.consume = 1 +ratelimit.create.refill = 10 + +ratelimit.delete.capacity = 200 +ratelimit.delete.consume = 1 +ratelimit.delete.refill = 10 \ No newline at end of file diff --git a/test/e2e/testscenarios/test_delete_paste.py b/test/e2e/testscenarios/test_delete_paste.py index d861538..01a1e13 100644 --- a/test/e2e/testscenarios/test_delete_paste.py +++ b/test/e2e/testscenarios/test_delete_paste.py @@ -1,4 +1,3 @@ -from test.e2e.conftest import create_paste_page from test.e2e.pageobjects.create_paste_page import CreatePastePage from test.e2e.pageobjects.error_page import ErrorPage from test.e2e.pageobjects.view_paste_page import ViewPastePage diff --git a/test/e2e/testscenarios/test_upload_files.py b/test/e2e/testscenarios/test_upload_files.py new file mode 100644 index 0000000..6e417fe --- /dev/null +++ b/test/e2e/testscenarios/test_upload_files.py @@ -0,0 +1,40 @@ +from test.e2e.pageobjects.create_paste_page import CreatePastePage +from test.e2e.pageobjects.view_paste_page import ViewPastePage +from test.e2e.utils.file_utils import create_random_file +import pytest +from playwright.sync_api import Page + + +@pytest.mark.e2e +def test_upload_single_file(page: Page, create_paste_page: CreatePastePage): + with create_random_file() as temp: + file_content = temp.read().decode() + create_paste_page.add_file_to_file_input(temp.name) + create_paste_page.should_have_value_in_paste_input(file_content) + create_paste_page.click_submit() + + view_paste_page = ViewPastePage(page) + view_paste_page.should_be_opened() + view_paste_page.should_have_pasted_text(file_content) + + +@pytest.mark.e2e +def test_upload_multiple_files(page: Page, create_paste_page: CreatePastePage): + with create_random_file() as first_temp, create_random_file() as second_temp: + first_file_content = first_temp.read().decode() + second_file_content = second_temp.read().decode() + create_paste_page.add_file_to_file_input( + [first_temp.name, second_temp.name] + ) + create_paste_page.should_have_value_in_paste_input( + first_file_content, paste_number=0 + ) + create_paste_page.should_have_value_in_paste_input( + second_file_content, paste_number=1 + ) + create_paste_page.click_submit() + + view_paste_page = ViewPastePage(page) + view_paste_page.should_be_opened() + view_paste_page.should_have_pasted_text(first_file_content, paste_number=0) + view_paste_page.should_have_pasted_text(second_file_content, paste_number=1) diff --git a/test/e2e/utils/file_utils.py b/test/e2e/utils/file_utils.py new file mode 100644 index 0000000..dd0a152 --- /dev/null +++ b/test/e2e/utils/file_utils.py @@ -0,0 +1,16 @@ +from test.e2e.utils.string_utils import random_string +import tempfile +import os +from contextlib import contextmanager + + +@contextmanager +def create_random_file(): + temp = tempfile.NamedTemporaryFile(suffix=".txt", delete=False) + temp.write(random_string().encode()) + temp.seek(0) + try: + yield temp + finally: + temp.close() + os.remove(temp.name) diff --git a/test/e2e/utils/string_utils.py b/test/e2e/utils/string_utils.py new file mode 100644 index 0000000..0a8861f --- /dev/null +++ b/test/e2e/utils/string_utils.py @@ -0,0 +1,11 @@ +import random +import string + + +def random_string(size=1000) -> str: + return "".join( + [ + random.choice(string.ascii_letters + string.digits) + for i in range(size) + ] + )