okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
3cabb9e3f
main
1"""serve/test_web_badges.py - the Recent requests table has a badge for every way a request can end (#3991). 2 3A request that waits past the queue limit ends with finish "timeout"; the Status cell showed the raw word. Reads the page source. 4""" 5from __future__import annotations 6 7import re 8import unittest 9from pathlib import Path 10 11APP = Path (__file__ ).resolve ().parent / "web" / "app.js" 12SERVER = Path (__file__ ).resolve ().parent / "server.py" 13 14 15class FinishBadges (unittest .TestCase ): 16def test_a_timed_out_request_has_a_badge (self ): 17src = APP .read_text (encoding = "utf-8" ) 18table = src [src .index ("const badge = {stop:" ):] 19table = table [:table .index ("};" )] 20self .assertRegex (table ,r'timeout: \["st-badge--queued", "Timeout"\]' ) 21 22def test_every_finish_the_server_stores_has_a_badge (self ): 23src = APP .read_text (encoding = "utf-8" ) 24table = src [src .index ("const badge = {stop:" ):] 25table = table [:table .index ("};" )] 26for finish in ("stop" ,"length" ,"cancel" ,"disconnect" ,"error" ,"timeout" ): 27self .assertRegex (table ,rf"\b { finish } :" ,finish ) 28self .assertIn ('"timeout"' ,SERVER .read_text (encoding = "utf-8" )) 29 30 31if __name__ == "__main__" : 32unittest .main ()