Esempio n. 1
0
    def test_lease_verify_child_availability_lease_conflict(self):
        parent_lease = api.lease_create(self.parent_lease_data)
        api.lease_create(self.child_lease_data)

        start = (self.child_lease_data['start_time'] +
                 datetime.timedelta(days=-5))
        end = self.child_lease_data['start_time'] + datetime.timedelta(days=-1)
        api.lease_verify_child_availability(parent_lease, start, end)

        start = self.child_lease_data['end_time'] + datetime.timedelta(days=1)
        end = self.child_lease_data['end_time'] + datetime.timedelta(days=5)
        api.lease_verify_child_availability(parent_lease, start, end)

        start = (self.child_lease_data['start_time'] +
                 datetime.timedelta(days=1))
        end = self.child_lease_data['end_time'] + datetime.timedelta(days=5)
        self.assertRaises(
            e.LeaseNoTimeAvailabilities,
            api.lease_verify_child_availability,
            parent_lease,
            start,
            end,
        )

        start = (self.child_lease_data['start_time'] +
                 datetime.timedelta(days=-1))
        end = self.child_lease_data['end_time'] + datetime.timedelta(days=-1)
        self.assertRaises(
            e.LeaseNoTimeAvailabilities,
            api.lease_verify_child_availability,
            parent_lease,
            start,
            end,
        )
Esempio n. 2
0
    def test_lease_get_all(self):
        api.lease_create(test_lease_1)
        api.lease_create(test_lease_2)

        res = api.lease_get_all({})
        res_uuids = [res_lease.to_dict()['uuid'] for res_lease in res]

        self.assertEqual(2, res.count())
        self.assertIn(test_lease_1['uuid'], res_uuids)
        self.assertIn(test_lease_2['uuid'], res_uuids)
Esempio n. 3
0
 def test_offer_get_first_availability(self):
     o1 = api.offer_create(test_offer_1)
     self.assertEqual(
         api.offer_get_first_availability(
             o1.uuid,
             o1.start_time,
         ), None)
     test_lease_3['offer_uuid'] = o1.uuid
     api.lease_create(test_lease_3)
     self.assertEqual(
         api.offer_get_first_availability(o1.uuid, o1.start_time),
         (now + datetime.timedelta(days=50), ))
Esempio n. 4
0
    def test_lease_get_all_filter_by_project_or_owner_id(self):
        api.lease_create(test_lease_1)
        api.lease_create(test_lease_2)
        api.lease_create(test_lease_3)
        api.lease_create(test_lease_4)
        api.lease_create(test_lease_5)

        res = api.lease_get_all({'project_or_owner_id': '0wn3r'})
        res_uuids = [res_lease.to_dict()['uuid'] for res_lease in res]

        self.assertEqual(3, res.count())
        self.assertIn(test_lease_1['uuid'], res_uuids)
        self.assertIn(test_lease_2['uuid'], res_uuids)
        self.assertIn(test_lease_5['uuid'], res_uuids)
Esempio n. 5
0
    def test_lease_get_all_filter_by_status(self):
        api.lease_create(test_lease_1)
        api.lease_create(test_lease_2)
        api.lease_create(test_lease_3)
        api.lease_create(test_lease_4)
        api.lease_create(test_lease_5)

        res = api.lease_get_all(
            {'status': [statuses.CREATED, statuses.ACTIVE]})
        res_uuids = [res_lease.to_dict()['uuid'] for res_lease in res]

        self.assertEqual(3, res.count())
        self.assertIn(test_lease_1['uuid'], res_uuids)
        self.assertIn(test_lease_2['uuid'], res_uuids)
        self.assertIn(test_lease_3['uuid'], res_uuids)
Esempio n. 6
0
    def test_resource_verify_availability_lease_conflict(self):
        test_lease = api.lease_create(test_lease_1)
        r_type = test_lease.resource_type
        r_uuid = test_lease.resource_uuid

        start = test_lease_1['end_time'] + datetime.timedelta(days=1)
        end = test_lease_1['end_time'] + datetime.timedelta(days=5)
        api.resource_verify_availability(r_type, r_uuid, start, end)

        start = test_lease_1['start_time'] + datetime.timedelta(days=1)
        end = test_lease_1['end_time'] + datetime.timedelta(days=-1)
        self.assertRaises(e.ResourceTimeConflict,
                          api.resource_verify_availability, r_type, r_uuid,
                          start, end)

        start = test_lease_1['start_time'] + datetime.timedelta(days=-1)
        end = test_lease_1['end_time'] + datetime.timedelta(days=1)
        self.assertRaises(e.ResourceTimeConflict,
                          api.resource_verify_availability, r_type, r_uuid,
                          start, end)

        start = test_lease_1['start_time'] + datetime.timedelta(days=-1)
        end = test_lease_1['start_time'] + datetime.timedelta(days=1)
        self.assertRaises(e.ResourceTimeConflict,
                          api.resource_verify_availability, r_type, r_uuid,
                          start, end)

        start = test_lease_1['end_time'] + datetime.timedelta(days=-1)
        end = test_lease_1['end_time'] + datetime.timedelta(days=1)
        self.assertRaises(e.ResourceTimeConflict,
                          api.resource_verify_availability, r_type, r_uuid,
                          start, end)
Esempio n. 7
0
 def test_lease_create(self):
     o1 = api.offer_create(test_offer_2)
     test_lease_4['offer_uuid'] = o1.uuid
     l1 = api.lease_create(test_lease_4)
     l2 = api.lease_get_all({}).all()
     assert len(l2) == 1
     assert l2[0].to_dict() == l1.to_dict()
Esempio n. 8
0
 def test_lease_update_invalid_time(self):
     o1 = api.offer_create(test_offer_3)
     test_lease_4['offer_uuid'] = o1.uuid
     l1 = api.lease_create(test_lease_4)
     values = {
         'start_time': now + datetime.timedelta(days=101),
         'end_time': now
     }
     self.assertRaises(e.InvalidTimeRange, api.lease_update, l1.uuid,
                       values)
Esempio n. 9
0
 def test_lease_update(self):
     o1 = api.offer_create(test_offer_2)
     test_lease_4['offer_uuid'] = o1.uuid
     l1 = api.lease_create(test_lease_4)
     values = {
         'start_time': test_lease_5['start_time'],
         'end_time': test_lease_5['end_time']
     }
     api.lease_update(l1.uuid, values)
     l1 = api.lease_get_by_uuid(l1.uuid)
     self.assertEqual(test_lease_5['start_time'], l1.start_time)
     self.assertEqual(test_lease_5['end_time'], l1.end_time)
Esempio n. 10
0
    def test_lease_get_by_name(self):
        o1 = api.offer_create(test_offer_1)
        o2 = api.offer_create(test_offer_2)
        o3 = api.offer_create(test_offer_3)
        o4 = api.offer_create(test_offer_4)
        test_lease_1['offer_uuid'] = o1.uuid
        test_lease_2['offer_uuid'] = o2.uuid
        test_lease_3['offer_uuid'] = o3.uuid
        test_lease_4['offer_uuid'] = o4.uuid
        l1 = api.lease_create(test_lease_1)
        l2 = api.lease_create(test_lease_2)
        l3 = api.lease_create(test_lease_3)
        api.lease_create(test_lease_4)
        res = api.lease_get_by_name('l1')
        assert len(res) == 3
        self.assertEqual(l1.uuid, res[0].uuid)
        self.assertEqual(l1.project_id, res[0].project_id)

        self.assertEqual(l2.uuid, res[1].uuid)
        self.assertEqual(l2.project_id, res[1].project_id)

        self.assertEqual(l3.uuid, res[2].uuid)
        self.assertEqual(l3.project_id, res[2].project_id)
Esempio n. 11
0
 def test_offer_get_conflict_times(self):
     o1 = api.offer_create(test_offer_1)
     self.assertEqual(api.offer_get_conflict_times(o1), [])
     test_lease_3['offer_uuid'] = o1.uuid
     test_lease_4['offer_uuid'] = o1.uuid
     test_lease_5['offer_uuid'] = o1.uuid
     api.lease_create(test_lease_3)
     api.lease_create(test_lease_4)
     api.lease_create(test_lease_5)
     self.assertEqual(api.offer_get_conflict_times(o1),
                      [(now + datetime.timedelta(days=50),
                        now + datetime.timedelta(days=60))])
Esempio n. 12
0
    def test_lease_get_all_filter_by_time(self):
        api.lease_create(test_lease_1)
        api.lease_create(test_lease_2)
        api.lease_create(test_lease_3)

        start_time = test_lease_2['start_time'] + datetime.timedelta(days=1)
        end_time = test_lease_2['end_time'] + datetime.timedelta(days=-1)

        res = api.lease_get_all({
            'start_time': start_time,
            'end_time': end_time
        })
        res_uuids = [res_lease.to_dict()['uuid'] for res_lease in res]

        self.assertEqual(1, res.count())
        self.assertIn(test_lease_2['uuid'], res_uuids)
Esempio n. 13
0
 def test_lease_destroy(self):
     o1 = api.offer_create(test_offer_2)
     test_lease_4['offer_uuid'] = o1.uuid
     l1 = api.lease_create(test_lease_4)
     api.lease_destroy(l1.uuid)
     self.assertEqual(api.lease_get_by_uuid('lease_4'), None)
Esempio n. 14
0
 def test_lease_get_by_uuid(self):
     o1 = api.offer_create(test_offer_2)
     test_lease_4['offer_uuid'] = o1.uuid
     l1 = api.lease_create(test_lease_4)
     res = api.lease_get_by_uuid(l1.uuid)
     self.assertEqual(l1.uuid, res.uuid)
Esempio n. 15
0
    def test_offer_verify_availability(self):
        offer = api.offer_create(test_offer_1)

        test_lease_1['offer_uuid'] = offer.uuid
        test_lease_2['offer_uuid'] = offer.uuid
        test_lease_3['offer_uuid'] = offer.uuid

        api.lease_create(test_lease_1)
        api.lease_create(test_lease_2)
        api.lease_create(test_lease_3)

        start = now + datetime.timedelta(days=35)
        end = now + datetime.timedelta(days=40)
        api.offer_verify_availability(offer, start, end)

        start = now + datetime.timedelta(days=5)
        end = now + datetime.timedelta(days=10)
        api.offer_verify_availability(offer, start, end)

        start = now
        end = now + datetime.timedelta(days=10)
        api.offer_verify_availability(offer, start, end)

        start = now + datetime.timedelta(days=90)
        end = now + datetime.timedelta(days=100)
        api.offer_verify_availability(offer, start, end)

        start = now + datetime.timedelta(days=60)
        end = now + datetime.timedelta(days=100)
        api.offer_verify_availability(offer, start, end)

        start = now + datetime.timedelta(days=30)
        end = now + datetime.timedelta(days=50)
        api.offer_verify_availability(offer, start, end)

        start = now + datetime.timedelta(days=15)
        end = now + datetime.timedelta(days=16)
        self.assertRaises(e.OfferNoTimeAvailabilities,
                          api.offer_verify_availability, offer, start, end)

        start = now + datetime.timedelta(days=45)
        end = now + datetime.timedelta(days=55)
        self.assertRaises(e.OfferNoTimeAvailabilities,
                          api.offer_verify_availability, offer, start, end)

        start = now + datetime.timedelta(days=55)
        end = now + datetime.timedelta(days=65)
        self.assertRaises(e.OfferNoTimeAvailabilities,
                          api.offer_verify_availability, offer, start, end)

        start = now + datetime.timedelta(days=50)
        end = now + datetime.timedelta(days=65)
        self.assertRaises(e.OfferNoTimeAvailabilities,
                          api.offer_verify_availability, offer, start, end)

        start = now + datetime.timedelta(days=45)
        end = now + datetime.timedelta(days=60)
        self.assertRaises(e.OfferNoTimeAvailabilities,
                          api.offer_verify_availability, offer, start, end)

        start = now + datetime.timedelta(days=90)
        end = now + datetime.timedelta(days=105)
        self.assertRaises(e.OfferNoTimeAvailabilities,
                          api.offer_verify_availability, offer, start, end)

        start = now + datetime.timedelta(days=100)
        end = now + datetime.timedelta(days=105)
        self.assertRaises(e.OfferNoTimeAvailabilities,
                          api.offer_verify_availability, offer, start, end)

        start = now + datetime.timedelta(days=105)
        end = now + datetime.timedelta(days=110)
        self.assertRaises(e.OfferNoTimeAvailabilities,
                          api.offer_verify_availability, offer, start, end)

        start = now - datetime.timedelta(days=1)
        end = now + datetime.timedelta(days=5)
        self.assertRaises(e.OfferNoTimeAvailabilities,
                          api.offer_verify_availability, offer, start, end)

        start = now - datetime.timedelta(days=1)
        end = now
        self.assertRaises(e.OfferNoTimeAvailabilities,
                          api.offer_verify_availability, offer, start, end)

        start = now - datetime.timedelta(days=10)
        end = now - datetime.timedelta(days=5)
        self.assertRaises(e.OfferNoTimeAvailabilities,
                          api.offer_verify_availability, offer, start, end)

        start = now + datetime.timedelta(days=45)
        end = now + datetime.timedelta(days=55)
        self.assertRaises(e.OfferNoTimeAvailabilities,
                          api.offer_verify_availability, offer, start, end)

        test_lease_4['offer_uuid'] = offer.uuid
        api.lease_create(test_lease_4)
        start = now + datetime.timedelta(days=86)
        end = now + datetime.timedelta(days=87)
        api.offer_verify_availability(offer, start, end)