Skip to content

Commit

Permalink
Unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pierotofy committed Jun 11, 2021
1 parent 9675d8a commit 9a4f65e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
38 changes: 38 additions & 0 deletions app/tests/test_api_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,35 @@ def test_task(self):
with Image.open(io.BytesIO(res.content)) as i:
self.assertEqual(i.width, 512)
self.assertEqual(i.height, 512)

# Cannot set invalid scene
res = client.post("/api/projects/{}/tasks/{}/3d/scene".format(project.id, task.id), json.dumps({ "garbage": "" }), content_type="application/json")
self.assertEqual(res.status_code, status.HTTP_400_BAD_REQUEST)

# Can set scene
res = client.post("/api/projects/{}/tasks/{}/3d/scene".format(project.id, task.id), json.dumps({ "type": "Potree" }), content_type="application/json")
self.assertEqual(res.status_code, status.HTTP_200_OK)
self.assertEqual(res.data['success'], True)

# Can set camera view
res = client.post("/api/projects/{}/tasks/{}/3d/cameraview".format(project.id, task.id), json.dumps({ "position": [0,5,0], "target": [0,0,0] }), content_type="application/json")
self.assertEqual(res.status_code, status.HTTP_200_OK)
self.assertEqual(res.data['success'], True)

# Can read potree scene
res = client.get("/api/projects/{}/tasks/{}/3d/scene".format(project.id, task.id))
self.assertEqual(res.status_code, status.HTTP_200_OK)
self.assertListEqual(res.data['view']['position'], [0,5,0])
self.assertListEqual(res.data['view']['target'], [0,0,0])

# Setting scene does not change view key, even if specified
res = client.post("/api/projects/{}/tasks/{}/3d/scene".format(project.id, task.id), json.dumps({ "type": "Potree", "view": { "position": [9,9,9], "target": [0,0,0] }, "measurements": [1, 2] }), content_type="application/json")
self.assertEqual(res.status_code, status.HTTP_200_OK)

res = client.get("/api/projects/{}/tasks/{}/3d/scene".format(project.id, task.id))
self.assertEqual(res.status_code, status.HTTP_200_OK)
self.assertListEqual(res.data['view']['position'], [0,5,0])
self.assertListEqual(res.data['measurements'], [1, 2])

# Cannot access tile 0/0/0
res = client.get("/api/projects/{}/tasks/{}/orthophoto/tiles/0/0/0.png".format(project.id, task.id))
Expand Down Expand Up @@ -647,6 +676,9 @@ def accessResources(expectedStatus):
res = other_client.get("/api/projects/{}/tasks/{}/".format(project.id, task.id))
self.assertEqual(res.status_code, expectedStatus)

res = other_client.get("/api/projects/{}/tasks/{}/3d/scene".format(project.id, task.id))
self.assertEqual(res.status_code, expectedStatus)

accessResources(status.HTTP_404_NOT_FOUND)

# Original owner enables sharing
Expand All @@ -664,6 +696,12 @@ def accessResources(expectedStatus):
})
self.assertEqual(res.status_code, status.HTTP_404_NOT_FOUND)

# He cannot save a scene / change camera view
res = other_client.post("/api/projects/{}/tasks/{}/3d/cameraview".format(project.id, task.id), json.dumps({ "position": [0,0,0], "target": [0,0,0] }), content_type="application/json")
self.assertEqual(res.status_code, status.HTTP_404_NOT_FOUND)
res = other_client.post("/api/projects/{}/tasks/{}/3d/scene".format(project.id, task.id), json.dumps({ "type": "Potree", "modified": True }), content_type="application/json")
self.assertEqual(res.status_code, status.HTTP_404_NOT_FOUND)

# User logs out
other_client.logout()

Expand Down
2 changes: 1 addition & 1 deletion webodm/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

# SECURITY WARNING: don't run with debug turned on a public facing server!
DEBUG = os.environ.get('WO_DEBUG', 'YES') == 'YES' or TESTING
DEV = os.environ.get('WO_DEV', 'NO') == 'YES'
DEV = os.environ.get('WO_DEV', 'NO') == 'YES' and not TESTING
SESSION_COOKIE_SECURE = CSRF_COOKIE_SECURE = os.environ.get('WO_SSL', 'NO') == 'YES'
INTERNAL_IPS = ['127.0.0.1']

Expand Down

0 comments on commit 9a4f65e

Please sign in to comment.