def _populate_database(): get_user_model().objects.create_user(username='******', password='******') get_user_model().objects.create_superuser(username='******', password='******') image_name = 'test-image.jpg' image_bytes = None with open(CURRENT_DIR + '/' + image_name, 'rb') as image: image_bytes = image.read() resource = Resource( external_id='recpbs29kfas9i', url='https://test.test/resource.pdf' ) resource.image.save(image_name, ContentFile(image_bytes), save=True) resource.save() for external_id in ('recZxlcM61qaDoOkc', 'recYK5ljTyL3b18J3', 'recvSDrARAcmKogbD'): practice = Practice( external_id=external_id, main_resource=resource, ) practice.image.save(image_name, ContentFile(image_bytes), save=True) practice.save() for category_id in ('rec82929kfas9i', 'rec0098afaooka', 'recppasf09aii'): category = Category( external_id=category_id, practice_external_ids=['recZxlcM61qaDoOkc'] ) category.image.save(image_name, ContentFile(image_bytes), save=True) category.save() category.practices.add(Practice.objects.filter(external_id='recZxlcM61qaDoOkc').first())
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
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')
def _populate_database(): User.objects.create_user(username='******', password='******') User.objects.create_superuser(username='******', password='******') image_name = 'test-image.jpg' image_bytes = None with open(CURRENT_DIR + '/' + image_name, 'rb') as image: image_bytes = image.read() resource = Resource(external_id='recpbs29kfas9i', url='https://test.test/resource.pdf') resource.image.save(image_name, ContentFile(image_bytes), save=True) resource.save() for external_id in ('recZxlcM61qaDoOkc', 'recYK5ljTyL3b18J3', 'recvSDrARAcmKogbD'): practice = Practice( external_id=external_id, main_resource=resource, ) practice.image.save(image_name, ContentFile(image_bytes), save=True) practice.save()
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()
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()