ci: add dedicated test stage

This commit is contained in:
nyan404 committed 2026-08-21 13:27:42 +03:00
1 parent 532b4c7710
commit 9022d3b06a
5 files changed
+35 -21

No files matched your search

+10
View File
@@ -1,4 +1,5 @@
stages:
- test
- build
- deploy
@@ -11,6 +12,15 @@ variables:
DOCKER_TLS_CERTDIR: ""
DOCKER_DRIVER: overlay2
test:
stage: test
image: python:3.12-slim
before_script:
- pip install --no-cache-dir -r requirements.txt
script:
- python -m compileall -q app tests
- python -m unittest discover -s tests -q
build:
stage: build
tags:
+1 -1
View File
@@ -18,7 +18,7 @@
- The job targets GitLab runner tag `fast` and builds through a privileged `docker:29.6.1-dind` service at `DOCKER_HOST=tcp://docker:2375`, with an explicit `alias: docker` and `DOCKER_TLS_CERTDIR=""`.
- The job waits for the DinD daemon and runs `docker info` before starting the build.
- The local image is currently `belki-calculator:test`; the CI target is now `$DOCKER_REGISTRY/belki:latest`.
- Local validation was performed with `python3 -m unittest discover -s tests -v` (28 tests), `compileall`, JavaScript syntax check, a local browser/API smoke test, and container health/API smoke.
- GitLab CI runs `python -m compileall -q app tests` and `python -m unittest discover -s tests -q` in a dedicated `test` stage before build/deploy. Local validation was performed with the same tests, JavaScript syntax check, a local browser/API smoke test, and container health/API smoke.
- The VK dialog layer is covered by tests for step-by-step entry, bulk detection, clarification, confirmation, and cancellation.
- Bulk input accepts a natural one-line format without pipes, e.g. `15.08 11:00 11:20 Дикая Вишня 1604614 Серолап 1617140`; the web form calls `/api/inspect-bulk` and fills recognized fields.
- Training and inspection have the same stepwise/bulk flow. Character identity can be resolved through `/api/resolve-identity` and the persistent SQLite directory; missing pairs produce an explicit prompt instead of guessed data.
+6 -8
View File
@@ -47,7 +47,7 @@ class CalculationTests(unittest.TestCase):
self.assertEqual(result.kitten_points, 12)
def test_non_self_kitten_and_extra_companion(self):
with self.assertRaisesRegex(ValueError, "одинаковый статус"):
with self.assertRaisesRegex(ValueError, "Для ЗУ все котята должны быть самостоятельными"):
CoachingSession(
date="15.08",
skill="ЗУ",
@@ -64,8 +64,8 @@ class CalculationTests(unittest.TestCase):
),
)
def test_non_self_30_minutes_matches_calculator(self):
result = calculate_coaching(
def test_zu_rejects_non_self_kitten(self):
with self.assertRaisesRegex(ValueError, "Для ЗУ все котята должны быть самостоятельными"):
CoachingSession(
date="16.08",
skill="ЗУ",
@@ -77,9 +77,6 @@ class CalculationTests(unittest.TestCase):
kitten_id=134437,
kitten_independence="несамостоятельно",
)
)
self.assertEqual(result.escort_points, 9)
self.assertEqual(result.kitten_points, 6)
def test_non_self_60_minutes_gives_adult_18_and_kitten_12(self):
result = calculate_coaching(
@@ -135,9 +132,10 @@ class CalculationTests(unittest.TestCase):
).escort_points
self.assertEqual(points("самостоятельно", "самостоятельно"), 18)
with self.assertRaisesRegex(ValueError, "одинаковый статус"):
with self.assertRaisesRegex(ValueError, "Для ЗУ все котята должны быть самостоятельными"):
points("самостоятельно", "несамостоятельно")
self.assertEqual(points("несамостоятельно", "несамостоятельно"), 30)
with self.assertRaisesRegex(ValueError, "Для ЗУ все котята должны быть самостоятельными"):
points("несамостоятельно", "несамостоятельно")
def test_training_is_fixed(self):
self.assertEqual(calculate_training(TrainingSession("Белка", 1, "Котёнок", 2)).points, 25)
+5 -6
View File
@@ -26,12 +26,11 @@ class VkBotTests(unittest.TestCase):
)
self.assertEqual(command["extra_kittens"], (("Второй", 3, "самостоятельно"), ("Третий", 4, "самостоятельно")))
def test_parse_one_line_command_with_multiple_kittens_and_shared_status(self):
command = parse_text_command(
"/зу 15.08 11:00 11:20 | Белка [1] | Первый [2], Второй [3] | несам"
)
self.assertEqual(command["kitten_independence"], "несамостоятельно")
self.assertEqual(command["extra_kittens"], (("Второй", 3, "несамостоятельно"),))
def test_zu_command_rejects_non_self_kittens(self):
with self.assertRaisesRegex(ValueError, "Для ЗУ все котята должны быть самостоятельными"):
parse_text_command(
"/зу 15.08 11:00 11:20 | Белка [1] | Первый [2], Второй [3] | несам"
)
def test_parse_help(self):
self.assertEqual(parse_text_command("/help"), {"mode": "help"})
+13 -6
View File
@@ -263,19 +263,26 @@ class VkConversationTests(unittest.TestCase):
dialog.handle(502, answer)
self.assertIn("скриншот", dialog.handle(502, "несам").lower())
def test_compact_command_accepts_all_independence_variants(self):
for value, expected in (
def test_compact_zu_command_rejects_non_self_variants(self):
for value in (
("сам", "самостоятельно"),
("самостоятельный", "самостоятельно"),
("самостоятельно", "самостоятельно"),
):
parsed = parse_text_command(
f"/зу 16.08 10:00 10:10 | Белка [1] | Малыш [2] | {value[0]}"
)
self.assertEqual(parsed["kitten_independence"], value[1])
for value in (
("несам", "несамостоятельно"),
("несамостоятельный", "несамостоятельно"),
("несамостоятельно", "несамостоятельно"),
):
parsed = parse_text_command(
f"/зу 16.08 10:00 10:10 | Белка [1] | Малыш [2] | {value}"
)
self.assertEqual(parsed["kitten_independence"], expected)
with self.assertRaisesRegex(ValueError, "Для ЗУ все котята должны быть самостоятельными"):
parse_text_command(
f"/зу 16.08 10:00 10:10 | Белка [1] | Малыш [2] | {value[0]}"
)
def test_keyboard_changes_with_dialog_state(self):
dialog = BelkiDialog()