def make_comm_msg(msg_type: str, job_id: str, as_job_request: bool, content: dict = None): msg = {"content": {"data": {"request_type": msg_type, "job_id": job_id}}} if content is not None: msg["content"]["data"].update(content) if as_job_request: return JobRequest(msg) else: return msg
def test_request_ok(self): rq_msg = { "msg_id": "some_id", "content": { "data": { "request_type": "a_request" } }, } rq = JobRequest(rq_msg) self.assertEqual(rq.msg_id, "some_id") self.assertEqual(rq.request, "a_request") self.assertIsNone(rq.job_id)
def test_request_no_req(self): rq_msg = { "msg_id": "some_id", "content": { "data": { "request_type": None } } } rq_msg2 = {"msg_id": "some_other_id", "content": {"data": {}}} for msg in [rq_msg, rq_msg2]: with self.assertRaises(ValueError) as e: JobRequest(rq_msg) self.assertIn("Missing request type in job channel message!", str(e.exception))
def test_request_no_data(self): rq_msg = {"msg_id": "some_id", "content": {}} with self.assertRaises(ValueError) as e: JobRequest(rq_msg) self.assertIn("Improperly formatted job channel message!", str(e.exception))