songs2slides

A tool that automatically finds song lyrics and creates lyric slideshows
git clone https://git.ashermorgan.net/songs2slides/
Log | Files | Refs | README

commit fbd828ff1d9b6b3ed5545fd9e6e0a16575b53f73
parent da9878331e596abd467f49dbcf77990a68ccc245
Author: Asher Morgan <59518073+ashermorgan@users.noreply.github.com>
Date:   Tue, 16 Apr 2024 16:55:52 -0700

Start server and API automatically for e2e tests

Diffstat:
Mrequirements.txt | 1+
Mtests/test_e2e.py | 109++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------
2 files changed, 78 insertions(+), 32 deletions(-)

diff --git a/requirements.txt b/requirements.txt @@ -5,3 +5,4 @@ requests pytest pytest-mock pytest-playwright +pytest-xprocess diff --git a/tests/test_e2e.py b/tests/test_e2e.py @@ -1,14 +1,59 @@ -# Requires songs2slides to be using mock_api.py and running on localhost:5000 - +import pytest from playwright.sync_api import Page, expect +from xprocess import ProcessStarter + +@pytest.fixture(autouse=True, scope="session") +def api(xprocess): + port = '5003' + + class Starter(ProcessStarter): + pattern = ".*Running.*" + timeout = 10 + args = ['python', '-m', 'flask', '--app', '../../../../mock_api.py', 'run'] + env = { + 'FLASK_RUN_PORT': port, + } + + # Start API + xprocess.ensure("api", Starter) + + yield f'http://localhost:{port}' + + # Stop API + xprocess.getinfo("api").terminate() + +@pytest.fixture(autouse=True, scope="session") +def server(xprocess, api): + port = '5002' + + class Starter(ProcessStarter): + pattern = ".*Running.*" + timeout = 10 + args = ['python', '-m', 'flask', '--app', '../../../../songs2slides', 'run'] + env = { + 'API_URL': api + '/{title}/{artist}/', + 'FLASK_RUN_PORT': port, + } + + # Start server + xprocess.ensure("server", Starter) + + yield f'http://localhost:{port}' + + # Stop server + xprocess.getinfo("server").terminate() + +@pytest.fixture(autouse=True, scope="session") +def base_url(server): + return server def test_basic(page: Page): # Start on homepage - page.goto("http://localhost:5000") + page.goto("/") # Click "Create a Slideshow" page.get_by_role("link", name="Create a Slideshow").click() - expect(page).to_have_url("http://localhost:5000/create/step-1/") + expect(page).to_have_url("http://localhost:5002/create/step-1/") # Fill in song information page.get_by_placeholder("Song title").last.fill("Song 1") @@ -19,7 +64,7 @@ def test_basic(page: Page): # Click Next page.get_by_role("button", name="Next").click() - expect(page).to_have_url("http://localhost:5000/create/step-2/") + expect(page).to_have_url("http://localhost:5002/create/step-2/") # Assert missing song message is correct expect(page.get_by_text("Lyrics must be entered manually for 1 song.")).to_be_visible() @@ -46,14 +91,14 @@ def test_basic(page: Page): # Click Next page.get_by_role("button", name="Next").click() - expect(page).to_have_url("http://localhost:5000/create/step-3/") + expect(page).to_have_url("http://localhost:5002/create/step-3/") # Fill in slideshow settings page.get_by_role("checkbox", name="Include a title slide before each song").uncheck() # Click create page.get_by_role("button", name="Create").click() - expect(page).to_have_url("http://localhost:5000/slides/") + expect(page).to_have_url("http://localhost:5002/slides/") # Assert slide content is correct expect(page.locator("css=section.present")).to_have_text('LYRICS TO SONG 1\nBY ARTIST A') @@ -66,11 +111,11 @@ def test_basic(page: Page): def test_pptx(page: Page): # Start on homepage - page.goto("http://localhost:5000") + page.goto("/") # Click "Create a Slideshow" page.get_by_role("link", name="Create a Slideshow").click() - expect(page).to_have_url("http://localhost:5000/create/step-1/") + expect(page).to_have_url("http://localhost:5002/create/step-1/") # Fill in song information page.get_by_placeholder("Song title").last.fill("Song 1") @@ -81,14 +126,14 @@ def test_pptx(page: Page): # Click Next page.get_by_role("button", name="Next").click() - expect(page).to_have_url("http://localhost:5000/create/step-2/") + expect(page).to_have_url("http://localhost:5002/create/step-2/") # Fill in missing lyrics page.get_by_role("textbox").last.fill('custom song 5 lyrics') # Click Next page.get_by_role("button", name="Next").click() - expect(page).to_have_url("http://localhost:5000/create/step-3/") + expect(page).to_have_url("http://localhost:5002/create/step-3/") # Fill in slideshow settings page.get_by_role("checkbox", name="Include a title slide before each song").uncheck() @@ -102,15 +147,15 @@ def test_pptx(page: Page): assert download.value.suggested_filename == 'slides.pptx' # Assert redirected to post download page - expect(page).to_have_url("http://localhost:5000/post-download/") + expect(page).to_have_url("http://localhost:5002/post-download/") def test_localStorage(page: Page): # Start on homepage - page.goto("http://localhost:5000") + page.goto("/") # Click "Create a Slideshow" page.get_by_role("link", name="Create a Slideshow").click() - expect(page).to_have_url("http://localhost:5000/create/step-1/") + expect(page).to_have_url("http://localhost:5002/create/step-1/") # Fill in song information page.get_by_placeholder("Song title").last.fill("Song 1") @@ -121,14 +166,14 @@ def test_localStorage(page: Page): # Click Next page.get_by_role("button", name="Next").click() - expect(page).to_have_url("http://localhost:5000/create/step-2/") + expect(page).to_have_url("http://localhost:5002/create/step-2/") # Fill in missing lyrics page.get_by_role("textbox").last.fill('custom song 5 lyrics') # Click Next page.get_by_role("button", name="Next").click() - expect(page).to_have_url("http://localhost:5000/create/step-3/") + expect(page).to_have_url("http://localhost:5002/create/step-3/") # Assert slideshow settings have default values expect(page.get_by_role("checkbox", name="Include a title slide before each song")).to_be_checked() @@ -141,14 +186,14 @@ def test_localStorage(page: Page): # Click create page.get_by_role("button", name="Create").click() - expect(page).to_have_url("http://localhost:5000/post-download/") + expect(page).to_have_url("http://localhost:5002/post-download/") # Return to homepage - page.goto("http://localhost:5000") + page.goto("/") # Click "Create a Slideshow" page.get_by_role("link", name="Create a Slideshow").click() - expect(page).to_have_url("http://localhost:5000/create/step-1/") + expect(page).to_have_url("http://localhost:5002/create/step-1/") # Fill in song information page.get_by_placeholder("Song title").last.fill("Song 1") @@ -159,14 +204,14 @@ def test_localStorage(page: Page): # Click Next page.get_by_role("button", name="Next").click() - expect(page).to_have_url("http://localhost:5000/create/step-2/") + expect(page).to_have_url("http://localhost:5002/create/step-2/") # Fill in missing lyrics page.get_by_role("textbox").last.fill('custom song 5 lyrics') # Click Next page.get_by_role("button", name="Next").click() - expect(page).to_have_url("http://localhost:5000/create/step-3/") + expect(page).to_have_url("http://localhost:5002/create/step-3/") # Assert slideshow settings have custom values expect(page.get_by_role("checkbox", name="Include a title slide before each song")).to_be_checked(checked = False) @@ -174,11 +219,11 @@ def test_localStorage(page: Page): def test_back(page: Page): # Start on homepage - page.goto("http://localhost:5000") + page.goto("/") # Click "Create a Slideshow" page.get_by_role("link", name="Create a Slideshow").click() - expect(page).to_have_url("http://localhost:5000/create/step-1/") + expect(page).to_have_url("http://localhost:5002/create/step-1/") # Fill in bad song information page.get_by_placeholder("Song title").last.fill("Song 11") @@ -186,7 +231,7 @@ def test_back(page: Page): # Click Next page.get_by_role("button", name="Next").click() - expect(page).to_have_url("http://localhost:5000/create/step-2/") + expect(page).to_have_url("http://localhost:5002/create/step-2/") # Assert songs are loaded expect(page.get_by_text("Song 11 (Artist Aa) lyrics not found")).to_be_visible() @@ -198,7 +243,7 @@ def test_back(page: Page): # Click Back page.get_by_role("button", name="Back").click() - expect(page).to_have_url("http://localhost:5000/create/step-1/") + expect(page).to_have_url("http://localhost:5002/create/step-1/") # Assert bad song information is still present expect(page.get_by_placeholder("Song title")).to_have_count(1) @@ -215,7 +260,7 @@ def test_back(page: Page): # Click Next page.get_by_role("button", name="Next").click() - expect(page).to_have_url("http://localhost:5000/create/step-2/") + expect(page).to_have_url("http://localhost:5002/create/step-2/") # Assert songs are loaded expect(page.get_by_text("Song 1 (Artist A)")).to_be_visible() @@ -235,11 +280,11 @@ def test_back(page: Page): # Click Next page.get_by_role("button", name="Next").click() - expect(page).to_have_url("http://localhost:5000/create/step-3/") + expect(page).to_have_url("http://localhost:5002/create/step-3/") # Click Back page.get_by_role("button", name="Back").click() - expect(page).to_have_url("http://localhost:5000/create/step-2/") + expect(page).to_have_url("http://localhost:5002/create/step-2/") # Uncollapse Song 1 page.get_by_text("Song 1 (Artist A)").click() @@ -254,14 +299,14 @@ def test_back(page: Page): # Click Next page.get_by_role("button", name="Next").click() - expect(page).to_have_url("http://localhost:5000/create/step-3/") + expect(page).to_have_url("http://localhost:5002/create/step-3/") # Fill in bad slideshow settings page.get_by_role("checkbox", name="Include a blank slide between each song").uncheck() # Click create page.get_by_role("button", name="Create").click() - expect(page).to_have_url("http://localhost:5000/slides/") + expect(page).to_have_url("http://localhost:5002/slides/") # Assert slide content is correct expect(page.locator("css=section.present")).to_have_text('SONG 1') @@ -276,7 +321,7 @@ def test_back(page: Page): # Click back page.go_back() - expect(page).to_have_url("http://localhost:5000/create/step-3/") + expect(page).to_have_url("http://localhost:5002/create/step-3/") # Assert bad slideshow settings still loaded expect(page.get_by_role("checkbox", name="Include a blank slide between each song")).to_be_checked(checked = False) @@ -287,7 +332,7 @@ def test_back(page: Page): # Click create page.get_by_role("button", name="Create").click() - expect(page).to_have_url("http://localhost:5000/slides/") + expect(page).to_have_url("http://localhost:5002/slides/") # Assert slide content is correct expect(page.locator("css=section.present")).to_have_text('LYRICS TO SONG 1\nBY ARTIST A')