Files
enviPy-bayer/tests/frontend/test_packagepage.py
jebus d6440f416c [Fix] Frontend Testing Fixtures (#249)
Co-authored-by: Tim Lorsbach <tim@lorsba.ch>
Co-authored-by: Liam Brydon <lbry121@aucklanduni.ac.nz>
Reviewed-on: enviPath/enviPy#249
2025-12-03 10:49:23 +13:00

70 lines
3.4 KiB
Python

import re
from django.test import tag
from playwright.sync_api import expect
from .frontend_base import EnviPyStaticLiveServerTestCase
class TestPackagePage(EnviPyStaticLiveServerTestCase):
@tag("frontend")
def test_create_package(self):
page = self.login()
page = self.create_package(page)
# Check the package name is correct
expect(page.locator("h2")).to_contain_text("test package")
@tag("frontend")
def test_package_permissions(self):
page = self.login()
page = self.create_package(page)
page.get_by_role("button", name="Actions").click()
page.get_by_role("button", name="Edit Permissions").click()
# Add read and write permission to enviPath Users group
page.locator("#select_grantee").select_option(label="enviPath Users")
page.locator("#read_new").check()
page.locator("#write_new").check()
page.get_by_role("button", name="+", exact=True).click()
page.get_by_role("button", name="Actions").click()
page.get_by_role("button", name="Edit Permissions").click()
# Check the permissions saved when re-opening the permissions box
expect(page.get_by_text("enviPath Users")).to_be_visible()
@tag("frontend")
def test_predict_in_package(self):
page = self.login()
page = self.create_package(page)
pathway_button = page.get_by_role("link", name="Pathways")
# Find number of current pathways by extracting it from pathway button
num_pathways = int(re.search(r"Pathways \((\d+)\)", pathway_button.inner_text()).group(1))
pathway_button.click()
page.get_by_role("button", name="Actions").click()
page.get_by_role("link", name="New Pathway").click()
# Check that the predict page 'in [package_name]' text shows the current package
expect(page.get_by_role("strong").get_by_text("test package")).to_be_visible()
page.get_by_role("textbox", name="Name").click()
page.get_by_role("textbox", name="Name").fill("Test Pathway")
page.get_by_role("textbox", name="Description").click()
page.get_by_role("textbox", name="Description").fill("Test description")
page.get_by_role("textbox", name="SMILES").click()
page.get_by_role("textbox", name="SMILES").fill("OCCCN")
page.locator("#predict-submit-button").click()
# Check a pathway is visible
expect(page.locator("rect")).to_be_visible()
page.get_by_role("link", name="test package").click()
# Check that the package now has one more pathway than initially
expect(page.locator("#docContent")).to_contain_text(f"Pathways ({num_pathways + 1})")
@staticmethod
def create_package(page):
"""Make a new empty package with name 'test package'"""
page.get_by_role("button", name="Browse").click()
page.get_by_role("link", name="Package", exact=True).click()
page.get_by_role("button", name="Actions").click()
page.get_by_role("button", name="New Package").click()
page.get_by_role("textbox", name="Name").click()
page.get_by_role("textbox", name="Name").fill("test package")
page.get_by_role("textbox", name="Description").click()
page.get_by_role("textbox", name="Description").fill("test description")
page.get_by_role("button", name="Submit").click()
return page