コード例 #1
0
    def test_get_tender(self):
        period = PeriodEndRequired({
            'startDate': datetime.now(TZ).isoformat(),
            'endDate': datetime.now(TZ).isoformat()
        })
        second_period = PeriodEndRequired({
            'startDate':
            datetime.now(TZ).isoformat(),
            'endDate':
            datetime.now(TZ).isoformat()
        })
        tender = Tender()
        period._data['__parent__'] = tender
        second_period._data['__parent__'] = period

        parent_tender = get_tender(second_period)
        self.assertEqual(tender, parent_tender)
        self.assertIsInstance(parent_tender, Tender)
        self.assertIsInstance(tender, Tender)

        period._data['__parent__'] = None
        with self.assertRaises(AttributeError) as e:
            get_tender(second_period)
        self.assertEqual(e.exception.message,
                         "'NoneType' object has no attribute '__parent__'")
コード例 #2
0
 def test_validate_valid(self):
     tender = Tender(
         {"title": "whatever", "mainProcurementCategory": "goods", "milestones": [copy.deepcopy(self.milestones)]}
     )
     tender.validate()
     data = tender.serialize("embedded")
     self.assertIn("mainProcurementCategory", data)
     self.assertIn(data["mainProcurementCategory"], "goods")
コード例 #3
0
 def test_validate_not_valid(self):
     tender = Tender(
         {"title": "whatever", "mainProcurementCategory": "test", "milestones": [copy.deepcopy(self.milestones)]}
     )
     with self.assertRaises(ModelValidationError) as e:
         tender.validate()
     self.assertEqual(
         e.exception.messages, {"mainProcurementCategory": ["Value must be one of ['goods', 'services', 'works']."]}
     )
コード例 #4
0
 def test_validate_empty(self):
     with self.assertRaises(ModelValidationError) as e:
         tender = Tender({
             "title": "whatever",
             "milestones": [copy.deepcopy(self.milestones)]
         })
         tender.validate()
     self.assertEqual(
         e.exception.message,
         {"mainProcurementCategory": [u"This field is required."]})
コード例 #5
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()
            })
コード例 #6
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(),
            },
        )
コード例 #7
0
 def test_validate_empty(self):
     tender = Tender({"title": "whatever"})
     tender.validate()
     data = tender.serialize("embedded")
     self.assertNotIn("mainProcurementCategory", data)