Files
toiminnanohjaus-django/apps/catalog/tests/domain/test_domain.py
T
petriandClaude Opus 5.5 679bf57eb4 Vaihe 1/3: pohjatiedot (palveluyksiköt, palvelut ja työtehtävät)
- Uusi catalog-moduuli: palveluyksikkö → (palvelu) → työtehtävä ilman hintoja.
- Pohjatiedot-sivu /catalog/ pääkäyttäjälle ja johdolle (oikeus catalog.manage):
  lisäys ja muokkaus dialogissa, Siirrä ylös / Siirrä alas, käytöstä poisto ja
  käyttöön otto. Fokus ja aria-live-ilmoitus jokaisen muutoksen jälkeen.
- Rivejä ei poisteta. Käytöstä poistetun yläkohdan alla olevat rivit säilyttävät
  oman tilansa, mutta eivät ole valittavissa. Nimi on yksilöllinen samalla
  tasolla kirjainkoosta riippumatta.
- Työtehtävän voi siirtää saman yksikön toiseen palveluun tai suoraan yksikön alle.
- Luvun 11.1 lista data-migraationa (0002_seed), jos taulut ovat tyhjiä.
- CatalogQueries: work_type_options, active_service_units ja get_work_type
  tehtäviä ja tuntikirjausta varten.
- Import-linter-sopimukset, suomennokset, yksikkö-, integraatio- ja selaintestit.
- Päivitetty CLAUDE.md ja määrittelyn kohta 16.3.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-29 14:07:41 +02:00

63 lines
2.3 KiB
Python

import pytest
from apps.catalog.domain.entities import Service, ServiceUnit, WorkType
from apps.catalog.domain.exceptions import CannotMove, InvalidCatalogName, ServiceNotInUnit
from apps.catalog.domain.ordering import Direction, move
from apps.catalog.domain.value_objects import CatalogName
class TestCatalogName:
def test_spaces_are_normalized(self) -> None:
assert CatalogName(" Graafinen työ ").value == "Graafinen työ"
@pytest.mark.parametrize("value", ["", " ", "x" * 101])
def test_invalid(self, value: str) -> None:
with pytest.raises(InvalidCatalogName):
CatalogName(value)
def test_same_as_ignores_case_and_spaces(self) -> None:
assert CatalogName("Editointi").same_as(" EDITOINTI ")
assert not CatalogName("Editointi").same_as("Kuvaus")
class TestMove:
def test_up_and_down(self) -> None:
assert move([1, 2, 3], 2, Direction.UP) == [2, 1, 3]
assert move([1, 2, 3], 2, Direction.DOWN) == [1, 3, 2]
def test_edges(self) -> None:
with pytest.raises(CannotMove):
move([1, 2], 1, Direction.UP)
with pytest.raises(CannotMove):
move([1, 2], 2, Direction.DOWN)
def service(id: int, unit_id: int) -> Service:
return Service.reconstitute(
id=id, service_unit_id=unit_id, name=CatalogName("S"), is_active=True, sort_order=1
)
class TestWorkType:
def test_service_must_belong_to_the_same_unit(self) -> None:
with pytest.raises(ServiceNotInUnit):
WorkType.register(
service_unit_id=1, service=service(5, 2), name=CatalogName("X"), sort_order=1
)
def test_move_between_service_and_unit(self) -> None:
wt = WorkType.register(
service_unit_id=1, service=service(5, 1), name=CatalogName("X"), sort_order=1
)
assert wt.service_id == 5
moved = wt.move_to(None, sort_order=7)
assert (moved.service_id, moved.sort_order) == (None, 7)
with pytest.raises(ServiceNotInUnit):
moved.move_to(service(6, 3), sort_order=1)
def test_deactivate_and_activate(self) -> None:
unit = ServiceUnit.register(name=CatalogName("U"), sort_order=1)
assert unit.is_active
assert not unit.with_active(False).is_active
assert unit.with_active(False).with_active(True).is_active