Add index settings page unit test
This commit is contained in:
parent
cdea172bb5
commit
4494287e3e
|
@ -15,7 +15,6 @@ def test_character_view(db: DbContext, app: Flask, make: ObjectFactory):
|
||||||
username: str = f"user_{os.urandom(8).hex()}"
|
username: str = f"user_{os.urandom(8).hex()}"
|
||||||
charname: str = f"char_{os.urandom(8).hex()}"
|
charname: str = f"char_{os.urandom(8).hex()}"
|
||||||
char_sig: str = f"signature_{os.urandom(8).hex()}"
|
char_sig: str = f"signature_{os.urandom(8).hex()}"
|
||||||
# ub: bytes = username.encode("utf8")
|
|
||||||
|
|
||||||
with app.test_client() as client:
|
with app.test_client() as client:
|
||||||
# Create the user and log in
|
# Create the user and log in
|
||||||
|
@ -63,7 +62,6 @@ def test_character_view(db: DbContext, app: Flask, make: ObjectFactory):
|
||||||
created_redirect,
|
created_redirect,
|
||||||
data={"name": charname, "signature": char_sig, "csrf_token": csrf_token},
|
data={"name": charname, "signature": char_sig, "csrf_token": csrf_token},
|
||||||
)
|
)
|
||||||
print(response.data.decode("utf8"))
|
|
||||||
assert 300 <= response.status_code <= 399
|
assert 300 <= response.status_code <= 399
|
||||||
|
|
||||||
# The character is updated
|
# The character is updated
|
||||||
|
|
|
@ -0,0 +1,91 @@
|
||||||
|
from amanuensis.db.models import IndexType
|
||||||
|
import os
|
||||||
|
from urllib.parse import urlsplit
|
||||||
|
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
from flask import Flask, url_for
|
||||||
|
|
||||||
|
from amanuensis.backend import memq, charq, indq
|
||||||
|
from amanuensis.db import DbContext
|
||||||
|
|
||||||
|
from tests.conftest import ObjectFactory
|
||||||
|
|
||||||
|
|
||||||
|
def test_index_view(db: DbContext, app: Flask, make: ObjectFactory):
|
||||||
|
"""Test the lexicon index page"""
|
||||||
|
|
||||||
|
with app.test_client() as client:
|
||||||
|
# Create the user and log in
|
||||||
|
user = make.user()
|
||||||
|
assert user
|
||||||
|
user_client = make.client(user.id)
|
||||||
|
assert client
|
||||||
|
user_client.login(client)
|
||||||
|
|
||||||
|
# Create a lexicon and join as the editor
|
||||||
|
lexicon = make.lexicon()
|
||||||
|
assert lexicon
|
||||||
|
mem = memq.create(db, user.id, lexicon.id, is_editor=True)
|
||||||
|
assert mem
|
||||||
|
|
||||||
|
# The index settings page exists
|
||||||
|
index_settings = url_for("lexicon.settings.index", lexicon_name=lexicon.name)
|
||||||
|
response = client.get(index_settings)
|
||||||
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
# Add some indices
|
||||||
|
i1 = indq.create(db, lexicon.id, IndexType.CHAR, "ABCDE", 0, 0, 0)
|
||||||
|
assert i1
|
||||||
|
p1 = i1.pattern
|
||||||
|
assert p1
|
||||||
|
i2 = indq.create(db, lexicon.id, IndexType.RANGE, "F-M", 0, 0, 0)
|
||||||
|
assert i2
|
||||||
|
p2 = i2.pattern
|
||||||
|
assert p2
|
||||||
|
i3 = indq.create(db, lexicon.id, IndexType.CHAR, "NOPQ", 0, 0, 0)
|
||||||
|
assert i3
|
||||||
|
p3 = i3.pattern
|
||||||
|
assert p3
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
# The index settings page shows the indices
|
||||||
|
response = client.get(index_settings)
|
||||||
|
assert response.status_code == 200
|
||||||
|
# for i in indq.get_for_lexicon(db, lexicon.id):
|
||||||
|
assert p1.encode("utf8") in response.data
|
||||||
|
assert p2.encode("utf8") in response.data
|
||||||
|
assert p3.encode("utf8") in response.data
|
||||||
|
|
||||||
|
# Indices can be modified
|
||||||
|
soup = BeautifulSoup(response.data, features="html.parser")
|
||||||
|
csrf_token = soup.find(id="csrf_token")["value"]
|
||||||
|
assert csrf_token
|
||||||
|
response = client.post(
|
||||||
|
index_settings,
|
||||||
|
data={
|
||||||
|
"csrf_token": csrf_token,
|
||||||
|
"indices-0-index_type": "CHAR",
|
||||||
|
"indices-0-pattern": "ABCDEF",
|
||||||
|
"indices-0-logical_order": 0,
|
||||||
|
"indices-0-display_order": 0,
|
||||||
|
"indices-0-capacity": "",
|
||||||
|
"indices-1-index_type": "PREFIX",
|
||||||
|
"indices-1-pattern": "F-M",
|
||||||
|
"indices-1-logical_order": 1,
|
||||||
|
"indices-1-display_order": -1,
|
||||||
|
"indices-1-capacity": "",
|
||||||
|
"indices-2-index_type": "",
|
||||||
|
"indices-2-pattern": "NOPQ",
|
||||||
|
"indices-2-logical_order": 0,
|
||||||
|
"indices-2-display_order": 0,
|
||||||
|
"indices-2-capacity": "",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
assert 300 <= response.status_code <= 399
|
||||||
|
|
||||||
|
updated_indices = list(indq.get_for_lexicon(db, lexicon.id))
|
||||||
|
assert len(updated_indices) == 2
|
||||||
|
assert updated_indices[0].index_type == IndexType.CHAR
|
||||||
|
assert updated_indices[0].pattern == "ABCDEF"
|
||||||
|
assert updated_indices[1].index_type == IndexType.PREFIX
|
||||||
|
assert updated_indices[1].pattern == "F-M"
|
Loading…
Reference in New Issue