(photo_fixture_snow)
| 21 | |
| 22 | |
| 23 | def test_tasks_created_updated(photo_fixture_snow): |
| 24 | # Task should have been created for the fixture |
| 25 | task = Task.objects.get(type='ensure_raw_processed', status='P', subject_id=photo_fixture_snow.id) |
| 26 | assert (timezone.now() - task.created_at).seconds < 1 |
| 27 | assert (timezone.now() - task.updated_at).seconds < 1 |
| 28 | assert task.started_at == None |
| 29 | assert task.finished_at == None |
| 30 | |
| 31 | # Test manually starting makes intended changes |
| 32 | task.start() |
| 33 | assert task.status == 'S' |
| 34 | assert (timezone.now() - task.started_at).seconds < 1 |
| 35 | |
| 36 | # Undo last changes |
| 37 | task.status = 'P' |
| 38 | task.started_at = None |
| 39 | task.save() |
| 40 | |
| 41 | # Calling this function should complete the task and queue up a new one for generating thumbnails |
| 42 | ensure_raw_processing_tasks() |
| 43 | task = Task.objects.get(type='ensure_raw_processed', subject_id=photo_fixture_snow.id) |
| 44 | assert task.status == 'C' |
| 45 | assert (timezone.now() - task.started_at).seconds < 1 |
| 46 | assert (timezone.now() - task.finished_at).seconds < 1 |
| 47 | |
| 48 | # Check next task has been created |
| 49 | task = Task.objects.get(type='generate_thumbnails', subject_id=photo_fixture_snow.id) |
| 50 | assert task.status == 'P' |
| 51 | assert (timezone.now() - task.created_at).seconds < 1 |
| 52 | assert (timezone.now() - task.updated_at).seconds < 1 |
| 53 | assert task.started_at == None |
| 54 | assert task.finished_at == None |
| 55 | |
| 56 | # Process tasks to generate thumbnails which should add new task for classification |
| 57 | process_generate_thumbnails_tasks() |
| 58 | task = Task.objects.get(type='generate_thumbnails', subject_id=photo_fixture_snow.id) |
| 59 | assert task.status == 'C' |
| 60 | assert (timezone.now() - task.started_at).seconds < 10 |
| 61 | assert (timezone.now() - task.finished_at).seconds < 1 |
| 62 | |
| 63 | # Chekc next task has been added to classify images |
| 64 | task = Task.objects.get(type='classify_images', subject_id=photo_fixture_snow.id) |
| 65 | assert task.status == 'P' |
| 66 | assert (timezone.now() - task.created_at).seconds < 1 |
| 67 | assert (timezone.now() - task.updated_at).seconds < 1 |
| 68 | assert task.started_at == None |
| 69 | assert task.finished_at == None |
| 70 | |
| 71 | # Processing the classification task should create child processes |
| 72 | assert task.complete_with_children == False |
| 73 | assert task.status == 'P' |
| 74 | process_classify_images_tasks() |
| 75 | task = Task.objects.get(type='classify_images', subject_id=photo_fixture_snow.id) |
| 76 | assert task.status == 'S' |
| 77 | assert task.children.count() == 6 |
| 78 | assert task.complete_with_children == True |
| 79 | |
| 80 | # Completing all the child processes should set the parent task to completed |
nothing calls this directly
no test coverage detected