Пример #1
0
class CancellationTestCase(TestCase):
    """
    TODO
    """
    def setUp(self):
        """
        TODO
        """
        stadium = Stadium(name="test stadium")
        stadium.save()

        self.sector = Sector(stadium=stadium, letter="A", color="#00ff00",
                             rows=10, sits=10, price=Decimal("10.00"))
        self.sector.save()

        self.festival = Festival(stadium=stadium, name="test festival",
                                 base_price=Decimal("10.00"))
        self.festival.save()

        start_night = datetime.now() + timedelta(days=50)

        self.night = Night(festival=self.festival, datetime=start_night)
        self.night.save()

        for i in range(2):
            band = Band(name="Test band %d" % i)
            band.save()

            self.bbn = BandByNight(band=band, night=self.night,
                                   price=Decimal("5.00"))
            self.bbn.save()

        self.pt = PublicType(name="maxor", price=Decimal("10.00"))
        self.pt.save()

        self.discount = Discount(festival=self.festival, limit_days=30,
                                 porcent=Decimal("10.00"))
        self.discount.save()

        self.ticket1 = Ticket(night=self.night, sector=self.sector, row=1,
                              sit=1, public_type=self.pt)
        self.ticket1.save()

        self.ticket2 = Ticket(night=self.night, sector=self.sector, row=1,
                              sit=2, public_type=self.pt)
        self.ticket2.save()

        self.sell_center = SellCenter(name="Test sell center")
        self.sell_center.save()

        self.sell_point = SellPoint(sell_center=self.sell_center)
        self.sell_point.save()

        self.sell = Sell(sell_point=self.sell_point)
        self.sell.save()

        ticket_sell = TicketSell(sell=self.sell, ticket=self.ticket1)
        ticket_sell.save()

        ticket_sell = TicketSell(sell=self.sell, ticket=self.ticket2)
        ticket_sell.save()

    def testMarkWasNotSelled(self):
        """
        TODO
        """
        self.assertEquals(True, self.ticket1.was_selled)

        cancellation = Cancellation(ticket=self.ticket1)
        cancellation.save()

        self.assertEquals(False, self.ticket1.was_selled)

    def testReSellCancelledTicket(self):
        """
        TODO
        """
        ticket = Ticket(night=self.night, sector=self.sector, row=1,
                        sit=5, public_type=self.pt)
        ticket.save()

        sell = Sell(sell_point=self.sell_point)
        sell.save()

        ticket_sell = TicketSell(sell=sell, ticket=ticket)
        ticket_sell.save()

        self.assertEquals(True, ticket.was_selled)

        cancellation = Cancellation(ticket=ticket)
        cancellation.save()

        self.assertEquals(False, ticket.was_selled)

        sell = Sell(sell_point=self.sell_point)
        sell.save()

        ticket_sell = TicketSell(sell=sell, ticket=ticket)
        ticket_sell.save()

        self.assertEquals(True, ticket.was_selled)

    def testReturnValue(self):
        """
        TODO
        """
        cancellation = Cancellation(ticket=self.ticket1)
        cancellation.save()

        return_value = self.ticket1.price() - self.ticket1.price() * \
            (Cancellation.RETURN_PORCENT / Decimal("100.00"))

        self.assertEquals(return_value, cancellation.return_value())

    def testReSellSelledTicket(self):
        """
        TODO
        """
        ticket = Ticket(night=self.night, sector=self.sector, row=1,
                        sit=5, public_type=self.pt)
        ticket.save()

        sell = Sell(sell_point=self.sell_point)
        sell.save()

        ticket_sell = TicketSell(sell=sell, ticket=ticket)
        ticket_sell.save()

        self.assertEquals(True, ticket.was_selled)

        sell = Sell(sell_point=self.sell_point)
        sell.save()

        with self.assertRaises(ValidationError):
            ticket_sell = TicketSell(sell=sell, ticket=ticket)
            ticket_sell.save()
Пример #2
0
class TicketTestCase(TestCase):
    """
    TODO
    """
    def setUp(self):
        """
        TODO
        """
        stadium = Stadium(name="test stadium")
        stadium.save()

        self.sector = Sector(stadium=stadium, letter="A", color="#00ff00",
                             rows=10, sits=10, price=Decimal("10.00"))
        self.sector.save()

        self.festival = Festival(stadium=stadium, name="test festival",
                                 base_price=Decimal("10.00"))
        self.festival.save()

        start_night = datetime.now() + timedelta(days=50)

        self.night = Night(festival=self.festival, datetime=start_night)
        self.night.save()

        for i in range(2):
            band = Band(name="Test band %d" % i)
            band.save()

            self.bbn = BandByNight(band=band, night=self.night,
                                   price=Decimal("5.00"))
            self.bbn.save()

        self.pt = PublicType(name="maxor", price=Decimal("10.00"))
        self.pt.save()

        self.discount = Discount(festival=self.festival, limit_days=30,
                                 porcent=Decimal("10.00"))
        self.discount.save()

        self.ticket = Ticket(night=self.night, sector=self.sector, row=1,
                             sit=1, public_type=self.pt)
        self.ticket.save()

    def testPriceWithDiscount(self):
        """
        TODO
        """
        price = self.sector.price + self.night.price() + self.pt.price
        price -= price * (self.discount.porcent / Decimal("100.00"))
        self.assertEquals(price, self.ticket.price())

    def testPriceWithoutDiscount(self):
        """
        TODO
        """
        self.night.datetime = datetime.now() + timedelta(days=1)
        self.night.save()

        price = self.sector.price + self.night.price() + self.pt.price
        self.assertEquals(price, self.ticket.price())

    def testInvalidPosition(self):
        """
        TODO
        """
        with self.assertRaises(ValidationError):
            ticket = Ticket(night=self.night, sector=self.sector, row=100,
                            sit=1, public_type=self.pt)
            ticket.clean()

        with self.assertRaises(ValidationError):
            ticket = Ticket(night=self.night, sector=self.sector, row=1,
                            sit=100, public_type=self.pt)
            ticket.clean()

    def testUniqueTicket(self):
        """
        TODO
        """
        with self.assertRaises(IntegrityError):
            self.ticket = Ticket(night=self.night, sector=self.sector, row=1,
                                 sit=1, public_type=self.pt)
            self.ticket.save()
Пример #3
0
class SellTestCase(TestCase):
    """
    TODO
    """
    def setUp(self):
        """
        TODO
        """
        stadium = Stadium(name="test stadium")
        stadium.save()

        self.sector = Sector(stadium=stadium, letter="A", color="#00ff00",
                             rows=10, sits=10, price=Decimal("10.00"))
        self.sector.save()

        self.festival = Festival(stadium=stadium, name="test festival",
                                 base_price=Decimal("10.00"))
        self.festival.save()

        start_night = datetime.now() + timedelta(days=50)

        self.night = Night(festival=self.festival, datetime=start_night)
        self.night.save()

        for i in range(2):
            band = Band(name="Test band %d" % i)
            band.save()

            self.bbn = BandByNight(band=band, night=self.night,
                                   price=Decimal("5.00"))
            self.bbn.save()

        self.pt = PublicType(name="maxor", price=Decimal("10.00"))
        self.pt.save()

        self.discount = Discount(festival=self.festival, limit_days=30,
                                 porcent=Decimal("10.00"))
        self.discount.save()

        ticket1 = Ticket(night=self.night, sector=self.sector, row=1,
                        sit=1, public_type=self.pt)
        ticket1.save()

        ticket2 = Ticket(night=self.night, sector=self.sector, row=1,
                        sit=2, public_type=self.pt)
        ticket2.save()

        self.sell_center = SellCenter(name="Test sell center")
        self.sell_center.save()

        self.sell_point = SellPoint(sell_center=self.sell_center)
        self.sell_point.save()

        self.sell = Sell(sell_point=self.sell_point)
        self.sell.save()

        ticket_sell = TicketSell(sell=self.sell, ticket=ticket1)
        ticket_sell.save()

        ticket_sell = TicketSell(sell=self.sell, ticket=ticket2)
        ticket_sell.save()

    def testPrice(self):
        """
        TODO
        """
        price = sum([ts.ticket.price() for ts in
                    TicketSell.objects.filter(sell=self.sell)])
        self.assertEquals(price, self.sell.price())

    def testChangeWasSelled(self):
        """
        TODO
        """
        ticket = Ticket(night=self.night, sector=self.sector, row=1,
                        sit=3, public_type=self.pt)
        ticket.save()

        self.assertEquals(False, ticket.was_selled)

        self.sell = Sell(sell_point=self.sell_point)
        self.sell.save()

        ticket_sell = TicketSell(sell=self.sell, ticket=ticket)
        ticket_sell.save()

        self.assertEquals(True, ticket.was_selled)