Skip to content

Commit

Permalink
chore: Move tests outside main package
Browse files Browse the repository at this point in the history
  • Loading branch information
akx committed Jun 16, 2024
1 parent 57da19a commit 16660dc
Show file tree
Hide file tree
Showing 20 changed files with 71 additions and 57 deletions.
File renamed without changes.
43 changes: 43 additions & 0 deletions paikkala/demo_data/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from __future__ import annotations

import os
from datetime import timedelta
from typing import Dict, List, Optional

from django.utils.timezone import now

from paikkala.models import Program, Room, Row, Zone
from paikkala.utils.importer import import_zones, read_csv_file

SIBELIUSTALO_DEFAULT_ROOM_NAME = 'Pääsali'


def get_sibeliustalo_rows() -> List[Dict[str, str]]:
return list(read_csv_file(os.path.join(os.path.dirname(__file__), 'sibeliustalo.txt')))


def get_sibeliustalo_qualifiers() -> List[Dict[str, str]]:
return list(read_csv_file(os.path.join(os.path.dirname(__file__), 'sibeliustalo-qualifiers.txt')))


def import_sibeliustalo_zones() -> List[Zone]:
return import_zones(
row_csv_list=get_sibeliustalo_rows(),
qualifier_csv_list=get_sibeliustalo_qualifiers(),
default_room_name=SIBELIUSTALO_DEFAULT_ROOM_NAME,
)


def create_jussi_program(zones: List[Zone], room: Optional[Room] = None) -> Program:
if not room:
room = zones[0].room
program = Program.objects.create(
room=room,
name='Jussi laskeutuu katosta enkelikuoron saattelemana',
reservation_start=now() - timedelta(hours=1),
reservation_end=now() + timedelta(hours=1),
max_tickets=100,
max_tickets_per_batch=1000,
)
program.rows.set(Row.objects.filter(zone__in=zones))
return program
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions paikkala/management/commands/paikkala_load_demo_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
from django.db.transaction import atomic
from django.utils.crypto import get_random_string

from paikkala.excs import NoCapacity
from paikkala.models import Zone
from paikkala.tests.demo_data import (
from paikkala.demo_data import (
SIBELIUSTALO_DEFAULT_ROOM_NAME,
create_jussi_program,
import_sibeliustalo_zones,
)
from paikkala.excs import NoCapacity
from paikkala.models import Zone


class Command(BaseCommand):
def add_arguments(self, parser: ArgumentParser) -> None:
parser.add_argument('--yes', '-y', default=False, action='store_true')
parser.add_argument("--yes", "-y", default=False, action="store_true")

@atomic
def handle(self, yes: bool, **options: Any) -> None:
Expand Down
File renamed without changes.
8 changes: 5 additions & 3 deletions paikkala/tests/conftest.py → paikkala_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
from django.utils.crypto import get_random_string
from django.utils.timezone import now

from paikkala.models import Program, Room, Row, Zone
from paikkala.tests.demo_data import (
from paikkala.demo_data import (
create_jussi_program,
import_sibeliustalo_zones,
)
from paikkala.models import Program, Room, Row, Zone
from paikkala_tests.utils import (
create_scatter_program,
create_workshop_program,
create_workshop_room,
create_workshop_row,
create_workshop_zone,
import_sibeliustalo_zones,
)


Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,4 @@ def test_automatic_max_tickets(jussi_program):
def test_attempt_sequential(lattia_program, attempt_sequential):
zone = lattia_program.zones[0]
tickets = list(lattia_program.reserve(zone=zone, count=3, attempt_sequential=attempt_sequential))
assert [t.number for t in tickets] == (
[1, 2, 6] if not attempt_sequential else [6, 7, 8]
)
assert [t.number for t in tickets] == ([1, 2, 6] if not attempt_sequential else [6, 7, 8])
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

@pytest.mark.django_db
def test_smoke_printing(jussi_program):
pytest.importorskip('reportlab')
from paikkala.printing import generate_ticket_pdf
from paikkala.printing.configuration import PrintingConfiguration
from paikkala.printing.drawing import TicketDrawer
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
59 changes: 13 additions & 46 deletions paikkala/tests/demo_data.py → paikkala_tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,13 @@
from __future__ import annotations

import os
from datetime import timedelta

from django.utils.timezone import now

from paikkala.models import Program, Room, Row, Zone
from paikkala.utils.importer import import_zones, read_csv_file

SIBELIUSTALO_DEFAULT_ROOM_NAME = 'Pääsali'


def get_sibeliustalo_rows():
return list(read_csv_file(os.path.join(os.path.dirname(__file__), 'sibeliustalo.txt')))


def get_sibeliustalo_qualifiers():
return list(read_csv_file(os.path.join(os.path.dirname(__file__), 'sibeliustalo-qualifiers.txt')))


def import_sibeliustalo_zones():
return import_zones(
row_csv_list=get_sibeliustalo_rows(),
qualifier_csv_list=get_sibeliustalo_qualifiers(),
default_room_name=SIBELIUSTALO_DEFAULT_ROOM_NAME,
)


def create_jussi_program(zones, room=None):
if not room:
room = zones[0].room
program = Program.objects.create(
room=room,
name='Jussi laskeutuu katosta enkelikuoron saattelemana',
reservation_start=now() - timedelta(hours=1),
reservation_end=now() + timedelta(hours=1),
max_tickets=100,
max_tickets_per_batch=1000,
)
program.rows.set(Row.objects.filter(zone__in=zones))
return program


def create_scatter_program(zones: list[Zone], room=None):
def create_scatter_program(zones: list[Zone], room=None) -> Program:
if not room:
room = zones[0].room
program = Program.objects.create(
Expand All @@ -59,16 +24,18 @@ def create_scatter_program(zones: list[Zone], room=None):
row: Row
for row in zone.rows.all():
# Leave one seat per row
_ = list(row.reserve(
program=program,
count=row.capacity - 1,
user=None,
name='Señor Developer',
email='test@localhost',
phone=None,
attempt_sequential=False,
excluded_numbers=None,
))
_ = list(
row.reserve(
program=program,
count=row.capacity - 1,
user=None,
name='Señor Developer',
email='test@localhost',
phone=None,
attempt_sequential=False,
excluded_numbers=None,
)
)

status = zone.get_reservation_status(program)
assert status.total_remaining == zone.rows.count()
Expand Down
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,13 @@ max-complexity = 10
"ANN003",
"ANN201",
]
"*/tests/*.py" = [
"paikkala_tests/*.py" = [
"ANN",
]
"*/migrations/*.py" = [
"ANN",
"E501",
]

[tool.ruff.format]
quote-style = "preserve"

0 comments on commit 16660dc

Please sign in to comment.