<commit_before>from dateutil.relativedelta import relativedelta
from django.test import TestCase
from django.utils import timezone

from factories import factories as f

from karspexet.ticket.models import Reservation, PricingModel

class TestReservation(TestCase):
    def setUp(self):
        venue = f.CreateVenue()
        group = f.CreateSeatingGroup(venue=venue)
        pricing = f.CreatePricingModel(
            seating_group=group,
            prices={'student': 200, 'normal': 250},
            valid_from=timezone.now()
        )
        self.seat1 = f.CreateSeat(group=group)
        self.seat2 = f.CreateSeat(group=group)

        production = f.CreateProduction()
        self.show = f.CreateShow(production=production, venue=venue, date=timezone.now())

    def test_reservation_is_active_if_session_timer_has_not_passed(self):
        timestamp = timezone.now() + relativedelta(minutes=10)
        reservation = Reservation.objects.create(
            show=self.show,
            session_timeout=timestamp,
            tickets={},
            total=200,
        )

        assert reservation in Reservation.active.all()

    def test_finalized_reservation_is_active(self):
        timestamp = timezone.now() - relativedelta(days=1)
        reservation = Reservation.objects.create(
            show=self.show,
            finalized=True,
            session_timeout=timestamp,
            tickets={},
            total=200,
        )

        assert reservation in Reservation.active.all()

    def test_timed_out_reservation_is_not_active(self):
        timestamp = timezone.now() - relativedelta(days=1)
        reservation = Reservation.objects.create(
            show=self.show,
            session_timeout=timestamp,
            tickets={},
            total=200,
        )

        assert reservation in Reservation.objects.all()
        assert reservation not in Reservation.active.all()


    def test_total_price(self):
        timestamp = timezone.now() - relativedelta(days=1)
        reservation = Reservation.objects.create(
            show=self.show,
            total=0,
            session_timeout=timestamp,
            tickets={
                self.seat1.id: 'student',
                self.seat2.id: 'normal',
            },
        )

        assert reservation.total_price() == 450

class TestPricingModel(TestCase):
    def setUp(self):
        venue = f.CreateVenue()
        self.group = f.CreateSeatingGroup(venue=venue)
<commit_msg>Refresh reservation object from database in tests<commit_after>from dateutil.relativedelta import relativedelta
from django.test import TestCase
from django.utils import timezone

from factories import factories as f

from karspexet.ticket.models import Reservation, PricingModel

class TestReservation(TestCase):
    def setUp(self):
        venue = f.CreateVenue()
        group = f.CreateSeatingGroup(venue=venue)
        pricing = f.CreatePricingModel(
            seating_group=group,
            prices={'student': 200, 'normal': 250},
            valid_from=timezone.now()
        )
        self.seat1 = f.CreateSeat(group=group)
        self.seat2 = f.CreateSeat(group=group)

        production = f.CreateProduction()
        self.show = f.CreateShow(production=production, venue=venue, date=timezone.now())

    def test_reservation_is_active_if_session_timer_has_not_passed(self):
        timestamp = timezone.now() + relativedelta(minutes=10)
        reservation = Reservation.objects.create(
            show=self.show,
            session_timeout=timestamp,
            tickets={},
            total=200,
        )

        assert reservation in Reservation.active.all()

    def test_finalized_reservation_is_active(self):
        timestamp = timezone.now() - relativedelta(days=1)
        reservation = Reservation.objects.create(
            show=self.show,
            finalized=True,
            session_timeout=timestamp,
            tickets={},
            total=200,
        )

        assert reservation in Reservation.active.all()

    def test_timed_out_reservation_is_not_active(self):
        timestamp = timezone.now() - relativedelta(days=1)
        reservation = Reservation.objects.create(
            show=self.show,
            session_timeout=timestamp,
            tickets={},
            total=200,
        )

        assert reservation in Reservation.objects.all()
        assert reservation not in Reservation.active.all()


    def test_total_price(self):
        timestamp = timezone.now() - relativedelta(days=1)
        reservation = Reservation.objects.create(
            show=self.show,
            total=0,
            session_timeout=timestamp,
            tickets={
                self.seat1.id: 'student',
                self.seat2.id: 'normal',
            },
        )
        reservation = Reservation.objects.get(pk=reservation.id)

        assert reservation.total_price() == 450

class TestPricingModel(TestCase):
    def setUp(self):
        venue = f.CreateVenue()
        self.group = f.CreateSeatingGroup(venue=venue)

{'fraction_non_alphanumeric': 0.09353371564168479, 'fraction_numerical': 0.01107375914573858, 'mean_word_length': 2.3518886679920477, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3853064', 'n_tokens_mistral': 1479, 'n_tokens_neox': 1403, 'n_words': 260}