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 b50f73d
Show file tree
Hide file tree
Showing 19 changed files with 26 additions and 23 deletions.
10 changes: 5 additions & 5 deletions paikkala/management/commands/paikkala_load_demo_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from paikkala.excs import NoCapacity
from paikkala.models import Zone
from paikkala.tests.demo_data import (
from paikkala_tests.demo_data import (
SIBELIUSTALO_DEFAULT_ROOM_NAME,
create_jussi_program,
import_sibeliustalo_zones,
Expand All @@ -18,25 +18,25 @@

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:
if not yes:
self.stderr.write('this command requires the --yes parameter, as it will mess up your database')
self.stderr.write("this command requires the --yes parameter, as it will mess up your database")

Check warning on line 26 in paikkala/management/commands/paikkala_load_demo_data.py

View check run for this annotation

Codecov / codecov/patch

paikkala/management/commands/paikkala_load_demo_data.py#L26

Added line #L26 was not covered by tests
return
sibeliustalo_zones = list(Zone.objects.filter(room__name=SIBELIUSTALO_DEFAULT_ROOM_NAME))
if not sibeliustalo_zones:
sibeliustalo_zones = import_sibeliustalo_zones()
room = sibeliustalo_zones[0].room
program = room.program_set.first() or create_jussi_program(sibeliustalo_zones, room=room)
user = User.objects.create_user(f'random-demo-{get_random_string(12)}')
user = User.objects.create_user(f"random-demo-{get_random_string(12)}")
prog_zones = list(program.zones)
for _ in range(10):
zone = random.choice(prog_zones)
count = random.randint(1, 5)
try:
tickets = list(program.reserve(zone=zone, count=count, user=user))
self.stdout.write(f'{user}: Reserved {len(tickets):d} tickets in {zone.name}')
self.stdout.write(f"{user}: Reserved {len(tickets):d} tickets in {zone.name}")
except NoCapacity:
break
File renamed without changes.
10 changes: 5 additions & 5 deletions paikkala/tests/conftest.py → paikkala_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.utils.timezone import now

from paikkala.models import Program, Room, Row, Zone
from paikkala.tests.demo_data import (
from paikkala_tests.demo_data import (
create_jussi_program,
create_scatter_program,
create_workshop_program,
Expand Down Expand Up @@ -54,14 +54,14 @@ def workshop_program(workshop_room, workshop_row):

@pytest.fixture
def lattia_program():
room = Room.objects.create(name='huone')
zone = Zone.objects.create(name='lattia', room=room)
row = Row.objects.create(zone=zone, start_number=1, end_number=10, excluded_numbers='3,4,5')
room = Room.objects.create(name="huone")
zone = Zone.objects.create(name="lattia", room=room)
row = Row.objects.create(zone=zone, start_number=1, end_number=10, excluded_numbers="3,4,5")
assert row.capacity == 7
t = now()
program = Program.objects.create(
room=zone.room,
name='program',
name="program",
max_tickets=100,
reservation_start=t,
reservation_end=t + timedelta(days=1),
Expand Down
22 changes: 12 additions & 10 deletions paikkala/tests/demo_data.py → paikkala_tests/demo_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,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
File renamed without changes.
File renamed without changes.
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])
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,6 @@ max-complexity = 10
"ANN",
"E501",
]

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

0 comments on commit b50f73d

Please sign in to comment.