예제 #1
0
def test_update_reservation(sample_shared_resource: Resource):
    old_timestamp = datetime(year=200, month=1, day=1, tzinfo=utc)
    sample_shared_resource.last_check_in = old_timestamp
    sample_shared_resource.save()

    allocator.update_reservation(sample_shared_resource)
    sample_shared_resource.refresh_from_db(fields=['last_check_in'])
    assert sample_shared_resource.last_check_in != old_timestamp
예제 #2
0
def make_reservation(resource: Resource, user: settings.AUTH_USER_MODEL,
                     used_for: str):
    # If we are multi threaded there could be a race condition here between when grab and when used
    logger.info(
        f"Reservation being made user={user.username} used_for={used_for} resource={resource}"
    )
    with transaction.atomic():
        resource.user = user
        resource.used_for = used_for
        resource.use_password = token_urlsafe(nbytes=10)
        resource.last_check_in = now()
        resource.last_reserved = now()
        resource.save()
        for_all_devices(resource.device_set.all(), 'share')
예제 #3
0
def refresh_reservation(resource: Resource):
    logger.info(f"Reservation device shares being refresh resource={resource}")
    resource.last_check_in = now()
    for_all_devices(resource.device_set.all(), 'refresh')
    resource.save()
예제 #4
0
def update_reservation(resource: Resource):
    logger.info(
        f"Reservation being being updated user={resource.user.username} resource={resource}"
    )
    resource.last_check_in = now()
    resource.save()