import pytest from bs4 import BeautifulSoup from flask import render_template from atlas_um.dna_accounts.forms import DNAAccountForm from tests.atlas_um.factories import DNAAccountFactory from tests.atlas_um.pytest_helpers import UrlForThisMixin from . import helpers class TestEditDNAAccount(UrlForThisMixin): ENDPOINT = "dna_accounts.create" FAKE_HOST = "atlas_um.test" @pytest.fixture def app_config(self): def inner(app): app.config["SERVER_NAME"] = self.FAKE_HOST app.config["NO_MFA_ENABLED"] = True return inner def test_title(self, app, pgdb_session): account = DNAAccountFactory.build() with app.test_request_context(self.url_for_this(app)): form = DNAAccountForm(obj=account) page = self.render_soup(account=account, form=form) expected_title = "Create New User" 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_fields(self, app, pgdb_session): with app.test_request_context(self.url_for_this(app)): form = DNAAccountForm() page = self.render_soup(form=form) for field in list(form): if field.name == "action": continue assert ( page.find(id=field.id) is not None ), f"Field not found: {field}" def test_frontend_libs_are_added(self, app, pgdb_session): with app.test_request_context(self.url_for_this(app)): form = DNAAccountForm() page = self.render_soup(form=form) assert all(helpers.added_frontend_libs(page)) # Helpers def render_soup(self, *args, **kwargs): rt = render_template( "dna_accounts/create_dna_account.html", *args, **kwargs ) return BeautifulSoup(rt, "html.parser")