Skip to content

Commit 96f52c2

Browse files
committed
Unit tests
1 parent 5dccf15 commit 96f52c2

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

app/tests/test_api.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,18 @@ def test_projects_and_tasks(self):
222222
# Task should have failed to be restarted
223223
self.assertTrue("has no processing node" in task.last_error)
224224

225-
# Cannot cancel, restart or delete a task for which we don't have permission
226-
for action in ['cancel', 'remove', 'restart']:
225+
# Cannot cancel, restart, delete, compact a task for which we don't have permission
226+
for action in ['cancel', 'remove', 'restart', 'compact']:
227227
res = client.post('/api/projects/{}/tasks/{}/{}/'.format(other_project.id, other_task.id, action))
228228
self.assertEqual(res.status_code, status.HTTP_404_NOT_FOUND)
229229

230+
# Can compact
231+
self.assertFalse(task.compacted)
232+
res = client.post('/api/projects/{}/tasks/{}/compact/'.format(project.id, task.id))
233+
self.assertEqual(res.status_code, status.HTTP_200_OK)
234+
task.refresh_from_db()
235+
self.assertTrue(task.compacted)
236+
230237
# Can delete
231238
res = client.post('/api/projects/{}/tasks/{}/remove/'.format(project.id, task.id))
232239
self.assertTrue(res.data["success"])

app/tests/test_api_task.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,6 @@ def connTimeout(*args, **kwargs):
963963
task.refresh_from_db()
964964
self.assertTrue(task.last_error is None)
965965

966-
967966
# Reassigning the task to another project should move its assets
968967
self.assertTrue(os.path.exists(full_task_directory_path(task.id, project.id)))
969968
self.assertTrue(len(task.scan_images()) == 2)
@@ -974,6 +973,23 @@ def connTimeout(*args, **kwargs):
974973
self.assertFalse(os.path.exists(full_task_directory_path(task.id, project.id)))
975974
self.assertTrue(os.path.exists(full_task_directory_path(task.id, other_project.id)))
976975

976+
# Move back
977+
task.project = project
978+
task.save()
979+
task.refresh_from_db()
980+
981+
# Compacting the task should remove the images
982+
# but not the assets
983+
self.assertTrue(len(os.listdir(task.assets_path())) > 0)
984+
self.assertEqual(len(task.scan_images()), 2)
985+
986+
res = client.post("/api/projects/{}/tasks/{}/compact/".format(project.id, task.id))
987+
self.assertEqual(res.status_code, status.HTTP_200_OK)
988+
task.refresh_from_db()
989+
990+
self.assertTrue(len(os.listdir(task.assets_path())) > 0)
991+
self.assertEqual(len(task.scan_images()), 0)
992+
977993
# Restart node-odm as to not generate orthophotos
978994
testWatch.clear()
979995
with start_processing_node(["--test_skip_orthophotos"]):

app/tests/test_app.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ def test_views(self):
101101
self.assertEqual(res.content.decode("utf-8").count('href="/processingnode/'), 3)
102102
self.assertTemplateUsed(res, 'app/dashboard.html')
103103

104+
# There should be an onboarding message
105+
self.assertTrue('To create a map, press the' in res.content.decode("utf-8"))
106+
107+
# But not if we disable it
108+
settings.DASHBOARD_ONBOARDING = False
109+
res = c.get('/dashboard/', follow=True)
110+
self.assertFalse('To create a map, press the' in res.content.decode("utf-8"))
111+
settings.DASHBOARD_ONBOARDING = True
112+
104113
# The API should return 3 nodes
105114
res = c.get('/api/processingnodes/')
106115
self.assertEqual(len(res.data), 3)

0 commit comments

Comments
 (0)