From 16660dc50727a29e7938d645aa3154ed6b2c118e Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Sun, 16 Jun 2024 13:40:50 +0300 Subject: [PATCH] chore: Move tests outside main package --- .../Sibeliustalo_paasali_paikkanumerointi.pdf | Bin .../_generate_sibeliustalo_qualifiers.py | 0 paikkala/demo_data/__init__.py | 43 +++++++++++++ .../sibeliustalo-qualifiers.txt | 0 .../{tests => demo_data}/sibeliustalo.txt | 0 .../commands/paikkala_load_demo_data.py | 8 +-- .../tests => paikkala_tests}/__init__.py | 0 .../tests => paikkala_tests}/conftest.py | 8 ++- .../tests => paikkala_tests}/test_admin.py | 0 .../tests => paikkala_tests}/test_blocks.py | 0 .../test_demo_data.py | 0 .../tests => paikkala_tests}/test_paikkala.py | 4 +- .../tests => paikkala_tests}/test_printing.py | 1 + .../test_qualifiers.py | 0 .../tests => paikkala_tests}/test_ranges.py | 0 .../tests => paikkala_tests}/test_runs.py | 0 .../tests => paikkala_tests}/test_views.py | 0 .../tests => paikkala_tests}/test_workshop.py | 0 .../demo_data.py => paikkala_tests/utils.py | 59 ++++-------------- pyproject.toml | 5 +- 20 files changed, 71 insertions(+), 57 deletions(-) rename {paikkala/tests => misc}/Sibeliustalo_paasali_paikkanumerointi.pdf (100%) rename {paikkala/tests => misc}/_generate_sibeliustalo_qualifiers.py (100%) create mode 100644 paikkala/demo_data/__init__.py rename paikkala/{tests => demo_data}/sibeliustalo-qualifiers.txt (100%) rename paikkala/{tests => demo_data}/sibeliustalo.txt (100%) rename {paikkala/tests => paikkala_tests}/__init__.py (100%) rename {paikkala/tests => paikkala_tests}/conftest.py (96%) rename {paikkala/tests => paikkala_tests}/test_admin.py (100%) rename {paikkala/tests => paikkala_tests}/test_blocks.py (100%) rename {paikkala/tests => paikkala_tests}/test_demo_data.py (100%) rename {paikkala/tests => paikkala_tests}/test_paikkala.py (98%) rename {paikkala/tests => paikkala_tests}/test_printing.py (91%) rename {paikkala/tests => paikkala_tests}/test_qualifiers.py (100%) rename {paikkala/tests => paikkala_tests}/test_ranges.py (100%) rename {paikkala/tests => paikkala_tests}/test_runs.py (100%) rename {paikkala/tests => paikkala_tests}/test_views.py (100%) rename {paikkala/tests => paikkala_tests}/test_workshop.py (100%) rename paikkala/tests/demo_data.py => paikkala_tests/utils.py (52%) diff --git a/paikkala/tests/Sibeliustalo_paasali_paikkanumerointi.pdf b/misc/Sibeliustalo_paasali_paikkanumerointi.pdf similarity index 100% rename from paikkala/tests/Sibeliustalo_paasali_paikkanumerointi.pdf rename to misc/Sibeliustalo_paasali_paikkanumerointi.pdf diff --git a/paikkala/tests/_generate_sibeliustalo_qualifiers.py b/misc/_generate_sibeliustalo_qualifiers.py similarity index 100% rename from paikkala/tests/_generate_sibeliustalo_qualifiers.py rename to misc/_generate_sibeliustalo_qualifiers.py diff --git a/paikkala/demo_data/__init__.py b/paikkala/demo_data/__init__.py new file mode 100644 index 0000000..4fd0c7a --- /dev/null +++ b/paikkala/demo_data/__init__.py @@ -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 diff --git a/paikkala/tests/sibeliustalo-qualifiers.txt b/paikkala/demo_data/sibeliustalo-qualifiers.txt similarity index 100% rename from paikkala/tests/sibeliustalo-qualifiers.txt rename to paikkala/demo_data/sibeliustalo-qualifiers.txt diff --git a/paikkala/tests/sibeliustalo.txt b/paikkala/demo_data/sibeliustalo.txt similarity index 100% rename from paikkala/tests/sibeliustalo.txt rename to paikkala/demo_data/sibeliustalo.txt diff --git a/paikkala/management/commands/paikkala_load_demo_data.py b/paikkala/management/commands/paikkala_load_demo_data.py index 9900355..6d4dd98 100644 --- a/paikkala/management/commands/paikkala_load_demo_data.py +++ b/paikkala/management/commands/paikkala_load_demo_data.py @@ -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: diff --git a/paikkala/tests/__init__.py b/paikkala_tests/__init__.py similarity index 100% rename from paikkala/tests/__init__.py rename to paikkala_tests/__init__.py diff --git a/paikkala/tests/conftest.py b/paikkala_tests/conftest.py similarity index 96% rename from paikkala/tests/conftest.py rename to paikkala_tests/conftest.py index ca79448..a1c1b5e 100644 --- a/paikkala/tests/conftest.py +++ b/paikkala_tests/conftest.py @@ -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, ) diff --git a/paikkala/tests/test_admin.py b/paikkala_tests/test_admin.py similarity index 100% rename from paikkala/tests/test_admin.py rename to paikkala_tests/test_admin.py diff --git a/paikkala/tests/test_blocks.py b/paikkala_tests/test_blocks.py similarity index 100% rename from paikkala/tests/test_blocks.py rename to paikkala_tests/test_blocks.py diff --git a/paikkala/tests/test_demo_data.py b/paikkala_tests/test_demo_data.py similarity index 100% rename from paikkala/tests/test_demo_data.py rename to paikkala_tests/test_demo_data.py diff --git a/paikkala/tests/test_paikkala.py b/paikkala_tests/test_paikkala.py similarity index 98% rename from paikkala/tests/test_paikkala.py rename to paikkala_tests/test_paikkala.py index 317b5a5..3add148 100644 --- a/paikkala/tests/test_paikkala.py +++ b/paikkala_tests/test_paikkala.py @@ -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]) diff --git a/paikkala/tests/test_printing.py b/paikkala_tests/test_printing.py similarity index 91% rename from paikkala/tests/test_printing.py rename to paikkala_tests/test_printing.py index cdf1fc2..484e799 100644 --- a/paikkala/tests/test_printing.py +++ b/paikkala_tests/test_printing.py @@ -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 diff --git a/paikkala/tests/test_qualifiers.py b/paikkala_tests/test_qualifiers.py similarity index 100% rename from paikkala/tests/test_qualifiers.py rename to paikkala_tests/test_qualifiers.py diff --git a/paikkala/tests/test_ranges.py b/paikkala_tests/test_ranges.py similarity index 100% rename from paikkala/tests/test_ranges.py rename to paikkala_tests/test_ranges.py diff --git a/paikkala/tests/test_runs.py b/paikkala_tests/test_runs.py similarity index 100% rename from paikkala/tests/test_runs.py rename to paikkala_tests/test_runs.py diff --git a/paikkala/tests/test_views.py b/paikkala_tests/test_views.py similarity index 100% rename from paikkala/tests/test_views.py rename to paikkala_tests/test_views.py diff --git a/paikkala/tests/test_workshop.py b/paikkala_tests/test_workshop.py similarity index 100% rename from paikkala/tests/test_workshop.py rename to paikkala_tests/test_workshop.py diff --git a/paikkala/tests/demo_data.py b/paikkala_tests/utils.py similarity index 52% rename from paikkala/tests/demo_data.py rename to paikkala_tests/utils.py index dae4537..654987f 100644 --- a/paikkala/tests/demo_data.py +++ b/paikkala_tests/utils.py @@ -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( @@ -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() diff --git a/pyproject.toml b/pyproject.toml index ada3233..e3aa12d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"