def test_stop_run(self): run_id = new_run(self, add_tasks=1) with self.assertRaises(HTTPUnauthorized): response = ApiView(self.invalid_password_request()).stop_run() self.assertTrue("error" in response) print(response["error"]) run = self.rundb.get_run(run_id) self.assertFalse(run["finished"]) message = "/api/stop_run request" request = self.correct_password_request( {"run_id": run_id, "task_id": 0, "message": message} ) with self.assertRaises(HTTPUnauthorized): response = ApiView(request).stop_run() self.assertTrue(error in response) sefl.assertFalse(run["tasks"][0]["active"]) self.rundb.userdb.user_cache.update_one( {"username": self.username}, {"$set": {"cpu_hours": 10000}} ) response = ApiView(request).stop_run() response.pop("duration", None) self.assertTrue(response == {}) # run = self.rundb.get_run(run_id) self.assertTrue(run["finished"]) self.assertTrue(message in run["stop_reason"])
def test_beat(self): run_id = new_run(self, add_tasks=1) with self.assertRaises(HTTPUnauthorized): response = ApiView(self.invalid_password_request()).beat() self.assertTrue("error" in response) print(response["error"]) request = self.correct_password_request({"run_id": run_id, "task_id": 0}) response = ApiView(request).beat() response.pop("duration", None) self.assertEqual(response, {})
def test_upload_pgn(self): run_id = new_run(self, add_tasks=1) pgn_text = "1. e4 e5 2. d4 d5" request = self.correct_password_request( { "run_id": run_id, "task_id": 0, "pgn": base64.b64encode( zlib.compress(pgn_text.encode("utf-8")) ).decode(), } ) response = ApiView(request).upload_pgn() response.pop("duration", None) self.assertTrue(response == {}) pgn_filename_prefix = "{}-{}".format(run_id, 0) pgn = self.rundb.get_pgn(pgn_filename_prefix) self.assertEqual(pgn, pgn_text) self.rundb.pgndb.delete_one({"run_id": pgn_filename_prefix})
def test_failed_task(self): run_id = new_run(self, add_tasks=1) run = self.rundb.get_run(run_id) # Request fails if username/password is invalid request = self.invalid_password_request() with self.assertRaises(HTTPUnauthorized): response = ApiView(self.invalid_password_request()).update_task() self.assertTrue("error" in response) print(response["error"]) self.assertTrue(run["tasks"][0]["active"]) message = "Sorry but I can't run this" request = self.correct_password_request( {"run_id": run_id, "task_id": 0, "message": message} ) response = ApiView(request).failed_task() response.pop("duration", None) self.assertEqual(response, {}) self.assertFalse(run["tasks"][0]["active"]) request = self.correct_password_request({"run_id": run_id, "task_id": 0}) response = ApiView(request).failed_task() self.assertTrue("info" in response) print(response["info"]) self.assertFalse(run["tasks"][0]["active"]) # revive task run["tasks"][0]["active"] = True self.rundb.buffer(run, True) request = self.correct_password_request( {"run_id": run_id, "task_id": 0, "message": message} ) response = ApiView(request).failed_task() response.pop("duration", None) self.assertTrue(response == {}) self.assertFalse(run["tasks"][0]["active"])