MCPcopy
hub / github.com/photonixapp/photonix / test_tasks_created_updated

Function test_tasks_created_updated

tests/test_task_queue.py:23–88  ·  view source on GitHub ↗
(photo_fixture_snow)

Source from the content-addressed store, hash-verified

21
22
23def 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

Callers

nothing calls this directly

Calls 7

getMethod · 0.80
startMethod · 0.80
saveMethod · 0.80
completeMethod · 0.80

Tested by

no test coverage detected