feat: add conversational RollCalc assistant
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import base64
|
||||
import os
|
||||
import re
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
import app as rollcalc_app
|
||||
from core_presets import CORE_PRESETS, matching_core_presets
|
||||
|
||||
|
||||
class CorePresetTests(unittest.TestCase):
|
||||
def test_rendered_web_ui_preset_list_is_unchanged(self):
|
||||
expected = [
|
||||
("133", "steel", "133mm Stahl"),
|
||||
("150", "pvc", "150mm PVC"),
|
||||
("168", "pvc", "168mm PVC"),
|
||||
("194", "steel", "194mm Stahl"),
|
||||
]
|
||||
credentials = base64.b64encode(b"mtazl:rollcalc").decode("ascii")
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
log_file = os.path.join(temp_dir, "access.json")
|
||||
with patch.object(rollcalc_app, "LOG_FILE", log_file):
|
||||
response = rollcalc_app.app.test_client().get(
|
||||
"/",
|
||||
headers={"Authorization": f"Basic {credentials}"},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
rendered = re.findall(
|
||||
r'class="core-preset-btn" data-core="([^"]+)" '
|
||||
r'data-core-material="([^"]+)">([^<]+)</button>',
|
||||
response.get_data(as_text=True),
|
||||
)
|
||||
self.assertEqual(rendered, expected)
|
||||
self.assertEqual(
|
||||
[
|
||||
(preset.ui_diameter, preset.material, preset.label)
|
||||
for preset in CORE_PRESETS
|
||||
],
|
||||
expected,
|
||||
)
|
||||
|
||||
def test_explicit_finite_aliases_resolve_one_canonical_preset(self):
|
||||
german = matching_core_presets("194 mm Stahlkern")
|
||||
english = matching_core_presets("194 mm steel core")
|
||||
|
||||
self.assertEqual(german, english)
|
||||
self.assertEqual(len(german), 1)
|
||||
self.assertEqual(german[0].key, "steel_194")
|
||||
|
||||
def test_generic_existing_families_are_genuinely_ambiguous(self):
|
||||
self.assertEqual(
|
||||
[preset.key for preset in matching_core_presets("Stahlkern")],
|
||||
["steel_133", "steel_194"],
|
||||
)
|
||||
self.assertEqual(
|
||||
[preset.key for preset in matching_core_presets("plastic core")],
|
||||
["pvc_150", "pvc_168"],
|
||||
)
|
||||
|
||||
def test_unknown_core_label_does_not_match(self):
|
||||
self.assertEqual(matching_core_presets("cardboard core"), ())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user