Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
pierotofy committed Sep 11, 2023
1 parent e510e2f commit ba2d42b
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions app/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
import os

from django.contrib.auth.models import User
from guardian.shortcuts import assign_perm, get_objects_for_user
Expand Down Expand Up @@ -140,22 +141,26 @@ def test_projects_and_tasks(self):
self.assertEqual(res.status_code, status.HTTP_200_OK)
self.assertTrue(res.data == "")

data_path = task.data_path()
if not os.path.exists(data_path):
os.makedirs(data_path, exist_ok=True)

task.console.reset("line1\nline2\nline3")
task.save()

res = client.get('/api/projects/{}/tasks/{}/output/'.format(project.id, task.id))
self.assertEqual(res.status_code, status.HTTP_200_OK)
self.assertTrue(res.data == task.console.output())
self.assertEqual(res.data, task.console.output())

# Console output with line num
res = client.get('/api/projects/{}/tasks/{}/output/?line=2'.format(project.id, task.id))
self.assertTrue(res.data == "line3")
self.assertEqual(res.data, "line3")

# Console output with line num out of bounds
res = client.get('/api/projects/{}/tasks/{}/output/?line=3'.format(project.id, task.id))
self.assertTrue(res.data == "")
self.assertEqual(res.data, "")
res = client.get('/api/projects/{}/tasks/{}/output/?line=-1'.format(project.id, task.id))
self.assertTrue(res.data == task.console.output())
self.assertEqual(res.data, task.console.output())

# Cannot list task details for a task belonging to a project we don't have access to
res = client.get('/api/projects/{}/tasks/{}/'.format(other_project.id, other_task.id))
Expand Down

0 comments on commit ba2d42b

Please sign in to comment.