from bs4 import BeautifulSoup from flask import render_template from atlas_um.applications.forms import ApplicationForm from tests.atlas_um.pytest_helpers import UrlForThisMixin from . import helpers class TestCreateApplication(UrlForThisMixin): ENDPOINT = "applications.create" def test_title(self, app, pgdb_session, authorized_admin): with app.test_request_context(self.url_for_this(app)): form = ApplicationForm() page = self.render_soup(form=form) expected_title = "Create New Application" assert page.title.get_text(strip=True) == expected_title assert ( page.find(id="subnav-header") .find(string=True, recursive=False) .strip() == expected_title ) def test_form_fields(self, app, pgdb_session, authorized_admin): with app.test_request_context(self.url_for_this(app)): form = ApplicationForm() page = self.render_soup(form=form) assert page.find(id="application-editing-form") is not None for field in list(form): assert ( page.find(id=field.id) is not None ), f"Field not found: {field}" def test_frontend_libs_are_added( self, app, pgdb_session, authorized_admin ): with app.test_request_context(self.url_for_this(app)): form = ApplicationForm() page = self.render_soup(form=form) assert all(helpers.added_frontend_libs(page)) # Helpers def render_soup(self, *args, **kwargs): rt = render_template( "applications/create_application.html", *args, **kwargs ) return BeautifulSoup(rt, "html.parser")