mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
feat(FastAPI): add get_(errors|successes) testing HTML helpers
These functions will allow us to more easily check errors or success messages when testing routes. Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
34c96ed81b
commit
27fbda5e7b
2 changed files with 32 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
|||
from io import StringIO
|
||||
from typing import List
|
||||
|
||||
from lxml import etree
|
||||
|
||||
|
@ -12,3 +13,13 @@ def parse_root(html: str) -> etree.Element:
|
|||
:return: etree.Element
|
||||
"""
|
||||
return etree.parse(StringIO(html), parser)
|
||||
|
||||
|
||||
def get_errors(content: str) -> List[etree._Element]:
|
||||
root = parse_root(content)
|
||||
return root.xpath('//ul[@class="errorlist"]/li')
|
||||
|
||||
|
||||
def get_successes(content: str) -> List[etree._Element]:
|
||||
root = parse_root(content)
|
||||
return root.xpath('//ul[@class="success"]/li')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue