Skip to content

Commit

Permalink
Merge pull request #151 from tzumainn/fix-offer-claim
Browse files Browse the repository at this point in the history
Fix bug with claiming offer
  • Loading branch information
tzumainn authored Feb 13, 2024
2 parents 7789605 + 3068eaf commit 6aa851b
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
Expand Down
3 changes: 2 additions & 1 deletion esi_leap/api/controllers/v1/offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ def claim(self, offer_uuid, new_lease):
lease_dict['start_time'] = datetime.datetime.now()

if 'end_time' not in lease_dict:
q = offer.get_first_availability(lease_dict['start_time'])
q = offer.get_next_lease_start_time(
lease_dict['start_time'])
if q is None:
lease_dict['end_time'] = offer.end_time
else:
Expand Down
6 changes: 3 additions & 3 deletions esi_leap/db/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ def offer_get_conflict_times(offer_ref):
return IMPL.offer_get_conflict_times(offer_ref)


def offer_get_first_availability(offer_uuid, start, end):
return IMPL.offer_get_first_availability(
offer_uuid, start, end)
def offer_get_next_lease_start_time(offer_uuid, start):
return IMPL.offer_get_next_lease_start_time(
offer_uuid, start)


def offer_verify_availability(offer_ref, start, end):
Expand Down
5 changes: 3 additions & 2 deletions esi_leap/db/sqlalchemy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def offer_get_conflict_times(offer_ref):
).all()


def offer_get_first_availability(offer_uuid, start):
def offer_get_next_lease_start_time(offer_uuid, start):
l_query = model_query(models.Lease)

return l_query.with_entities(
Expand All @@ -179,7 +179,8 @@ def offer_get_first_availability(offer_uuid, start):
(models.Lease.status == statuses.ACTIVE)
).\
order_by(models.Lease.start_time).\
filter(models.Lease.end_time >= start).first()
filter((models.Lease.end_time >= start) &
(models.Lease.start_time >= start)).first()


def offer_verify_availability(offer_ref, start, end):
Expand Down
5 changes: 3 additions & 2 deletions esi_leap/objects/offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ def get_availabilities(self):

return avails

def get_first_availability(self, start):
return self.dbapi.offer_get_first_availability(self.uuid, start)
def get_next_lease_start_time(self, start):
return self.dbapi.offer_get_next_lease_start_time(
self.uuid, start)

def create(self, context=None):
updates = self.obj_get_changes()
Expand Down
27 changes: 22 additions & 5 deletions esi_leap/tests/db/sqlalchemy/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,20 @@
status=statuses.EXPIRED,
)

test_lease_7 = dict(
uuid='77777',
project_id='1e5533_2',
owner_id='0wn3r_2',
name='l1',
resource_uuid='1111',
resource_type='dummy_node',
purpose='test_purpose',
start_time=now - datetime.timedelta(days=10),
end_time=now + datetime.timedelta(days=10),
properties={},
status=statuses.ACTIVE,
)

test_event_1 = dict(
id=1,
event_type='fake:event:start',
Expand Down Expand Up @@ -340,15 +354,18 @@ def test_offer_get_conflict_times(self):
[(now + datetime.timedelta(days=50),
now + datetime.timedelta(days=60))])

def test_offer_get_first_availability(self):
def test_offer_get_next_lease_start_time(self):
o1 = api.offer_create(test_offer_1)
self.assertEqual(api.offer_get_first_availability
self.assertEqual(api.offer_get_next_lease_start_time
(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),))
test_lease_7['offer_uuid'] = o1.uuid
api.lease_create(test_lease_7)
self.assertEqual(
api.offer_get_next_lease_start_time(
o1.uuid, o1.start_time),
(now + datetime.timedelta(days=50),))

def test_offer_get_by_uuid(self):
o1 = api.offer_create(test_offer_1)
Expand Down

0 comments on commit 6aa851b

Please sign in to comment.