def test_tasks_delete(self): filepath1 = Files.temp_put("foobar") filepath2 = Files.temp_put("foobar") assert os.path.exists(filepath1) assert os.path.exists(filepath2) self.db.session.add(db.Task(filepath1, status=db.Task.FINISHED)) self.db.session.add(db.Task(filepath2, status=db.Task.FINISHED)) data = { "task_ids": "1 2", } assert self.client.delete("/api/tasks", data=data).json == { "success": True, } assert not os.path.exists(filepath1) assert not os.path.exists(filepath2) assert self.client.delete("/api/task/1").json == { "success": False, "message": "Task already deleted", } assert self.client.delete("/api/task/2").json == { "success": False, "message": "Task already deleted", } assert not os.path.exists(filepath1) assert not os.path.exists(filepath2)
def test_task_delete(self): filepath = Files.temp_put("foobar") assert os.path.exists(filepath) self.db.session.add(db.Task(filepath, status=db.Task.FINISHED)) assert self.client.delete("/api/task/1").json == { "success": True, } assert not os.path.exists(filepath) assert self.client.delete("/api/task/1").json == { "success": False, "message": "Task already deleted", } assert not os.path.exists(filepath)
def setUp(self): self.db = db.db self.db.create_all() # Create some tasks in task with different statuses dates_completed = [None, None, None, "2017-8-15 14:00:00"] statuses = ["pending", "pending", "pending", "deleted"] prios = [1, 1, 5, 1] for c in range(4): fd, path = tempfile.mkstemp() with open(path, "wb") as fw: fw.write(os.urandom(64)) kwargs = { "status": statuses[c], "priority": prios[c], } task = db.Task(path=path, filename=os.path.basename(path), **kwargs) if dates_completed[c] is not None: task.completed = datetime.datetime.strptime( dates_completed[c], "%Y-%m-%d %H:%M:%S") task.submitted = datetime.datetime.strptime( "2017-8-15 13:40:00", "%Y-%m-%d %H:%M:%S") self.db.session.add(task) self.db.session.commit() # Create some nodes and status reports node_statuses = json.load(open("tests/files/nodestatus.json", "rb")) now = datetime.datetime.strptime("2017-8-15 13:40:00", "%Y-%m-%d %H:%M:%S") for name in ["node1", "node2"]: self.db.session.add( db.Node(name, "http://localhost:9085/", "normal")) for node_status in node_statuses: now = now + datetime.timedelta(seconds=10) name = node_status.get("hostname") self.db.session.add(db.NodeStatus(name, now, node_status)) self.db.session.commit() self.db.session.flush()
def test_scheduler(self, p, q): self.db.session.add( db.Node("node0", "http://localhost:8090/", "normal")) self.db.session.add(db.Task(path="foobar")) self.db.session.commit() task = db.Task.query.first() assert task.status == db.Task.PENDING q.return_value = { "tasks": { "pending": 0, }, } p.side_effect = StopIteration with pytest.raises(StopIteration): instance.scheduler() task = db.Task.query.first() assert task.path == "foobar" assert task.status == db.Task.ASSIGNED assert task.node_id == 1