示例#1
0
    def test_should_start_after(self):
        tender_period = PeriodEndRequired({
            'startDate':
            datetime.now(TZ).isoformat(),
            'endDate': (datetime.now(TZ) + timedelta(minutes=10)).isoformat()
        })
        tender_enquiry_period = PeriodEndRequired({
            'startDate':
            datetime.now(TZ).isoformat(),
            'endDate': (datetime.now(TZ) + timedelta(minutes=10)).isoformat()
        })
        tender = Tender({'status': 'active.enquiries'})
        tender.lots = []
        tender.numberOfBids = 2
        tender.tenderPeriod = tender_period
        tender.enquiryPeriod = tender_enquiry_period
        start_date = datetime.now(TZ)
        end_date = datetime.now(TZ) + timedelta(minutes=5)
        tender_auction_period = TenderAuctionPeriod({
            'startDate':
            start_date.isoformat(),
            'endDate':
            end_date.isoformat()
        })

        # Test with endDate exist
        serialized = tender_auction_period.serialize()
        self.assertEqual(serialized, {
            'startDate': start_date.isoformat(),
            'endDate': end_date.isoformat()
        })

        # Test with wrong status
        tender_auction_period = TenderAuctionPeriod(
            {'startDate': start_date.isoformat()})
        tender_auction_period.__parent__ = tender

        serialized = tender_auction_period.serialize()
        self.assertEqual(serialized, {'startDate': start_date.isoformat()})

        # Test with get_now() less than calc_auction_end_time()
        tender_auction_period = TenderAuctionPeriod(
            {'startDate': start_date.isoformat()})
        tender.status = 'active.tendering'
        tender_auction_period.__parent__ = tender
        serialized = tender_auction_period.serialize()
        should_start_after = datetime.combine(
            (tender.tenderPeriod.endDate.date() + timedelta(days=1)),
            time(0, tzinfo=tender.tenderPeriod.endDate.tzinfo))
        self.assertEqual(
            serialized, {
                'startDate': start_date.isoformat(),
                'shouldStartAfter': should_start_after.isoformat()
            })

        # Test with get_now() greater then calc_auction
        tender_auction_period.startDate -= timedelta(days=1)
        serialized = tender_auction_period.serialize()
        should_start_after = datetime.combine(
            (tender_auction_period.startDate.date() + timedelta(days=1)),
            time(0, tzinfo=tender_auction_period.startDate.tzinfo))
        self.assertEqual(
            serialized, {
                'startDate': tender_auction_period.startDate.isoformat(),
                'shouldStartAfter': should_start_after.isoformat()
            })
示例#2
0
    def test_should_start_after(self):
        tender_period = PeriodEndRequired({
            "startDate":
            datetime.now(TZ).isoformat(),
            "endDate": (datetime.now(TZ) + timedelta(minutes=10)).isoformat(),
        })
        tender_enquiry_period = PeriodEndRequired({
            "startDate":
            datetime.now(TZ).isoformat(),
            "endDate": (datetime.now(TZ) + timedelta(minutes=10)).isoformat(),
        })
        tender = Tender({"status": "active.enquiries"})
        tender.lots = []
        tender.numberOfBids = 2
        tender.tenderPeriod = tender_period
        tender.enquiryPeriod = tender_enquiry_period
        start_date = datetime.now(TZ)
        end_date = datetime.now(TZ) + timedelta(minutes=5)
        tender_auction_period = TenderAuctionPeriod({
            "startDate":
            start_date.isoformat(),
            "endDate":
            end_date.isoformat()
        })

        # Test with endDate exist
        serialized = tender_auction_period.serialize()
        self.assertEqual(serialized, {
            "startDate": start_date.isoformat(),
            "endDate": end_date.isoformat()
        })

        # Test with wrong status
        tender_auction_period = TenderAuctionPeriod(
            {"startDate": start_date.isoformat()})
        tender_auction_period.__parent__ = tender

        serialized = tender_auction_period.serialize()
        self.assertEqual(serialized, {"startDate": start_date.isoformat()})

        # Test with get_now() less than calc_auction_end_time()
        tender_auction_period = TenderAuctionPeriod(
            {"startDate": start_date.isoformat()})
        tender.status = "active.tendering"
        tender_auction_period.__parent__ = tender
        serialized = tender_auction_period.serialize()
        should_start_after = datetime.combine(
            (tender.tenderPeriod.endDate.date() + timedelta(days=1)),
            time(0, tzinfo=tender.tenderPeriod.endDate.tzinfo))
        self.assertEqual(
            serialized, {
                "startDate": start_date.isoformat(),
                "shouldStartAfter": should_start_after.isoformat()
            })

        # Test with get_now() greater then calc_auction
        tender_auction_period.startDate -= timedelta(days=1)
        serialized = tender_auction_period.serialize()
        should_start_after = datetime.combine(
            (tender_auction_period.startDate.date() + timedelta(days=1)),
            time(0, tzinfo=tender_auction_period.startDate.tzinfo),
        )
        # TODO: investigate fail starting at 23:24:00 to 24:00:00
        self.assertEqual(
            serialized,
            {
                "startDate": tender_auction_period.startDate.isoformat(),
                "shouldStartAfter": should_start_after.isoformat(),
            },
        )