def test_sendBatchMessages(sqs): fake_data0 = {"foo": "bar"} fake_data1 = {"john": "doe"} jsonized0 = json.dumps(fake_data0) jsonized1 = json.dumps(fake_data1) md5_0 = hashlib.md5(jsonized0.encode("utf-8")).hexdigest() md5_1 = hashlib.md5(jsonized1.encode("utf-8")).hexdigest() proj = generate_proj() from ndingest.ndqueue.cleanupqueue import CleanupQueue CleanupQueue.createQueue(proj) cleanup_queue = CleanupQueue(proj) try: response = cleanup_queue.sendBatchMessages([fake_data0, fake_data1], 0) assert "Successful" in response success_ids = [] for msg_result in response["Successful"]: id = msg_result["Id"] success_ids.append(id) if id == "0": assert md5_0 == msg_result["MD5OfMessageBody"] elif id == "1": assert md5_1 == msg_result["MD5OfMessageBody"] assert "0" in success_ids assert "1" in success_ids finally: for message_id, receipt_handle, _ in cleanup_queue.receiveMessage(): cleanup_queue.deleteMessage(message_id, receipt_handle)
class Test_Cleanup_Queue(): def setup_class(self): """Setup class parameters""" if 'SQS_ENDPOINT' in dir(settings): self.endpoint_url = settings.SQS_ENDPOINT else: self.endpoint_url = None CleanupQueue.createQueue(nd_proj, endpoint_url=self.endpoint_url) self.cleanup_queue = CleanupQueue(nd_proj, endpoint_url=self.endpoint_url) def teardown_class(self): """Teardown parameters""" CleanupQueue.deleteQueue(nd_proj, endpoint_url=self.endpoint_url) def test_Message(self): """Testing the upload queue""" supercuboid_key = 'kasthuri11&image&0&0' self.cleanup_queue.sendMessage(supercuboid_key) for message_id, receipt_handle, message_body in self.cleanup_queue.receiveMessage(): assert(supercuboid_key == message_body) response = self.cleanup_queue.deleteMessage(message_id, receipt_handle) assert('Successful' in response) def test_sendBatchMessages(self): fake_data0 = {'foo': 'bar'} fake_data1 = {'john': 'doe'} jsonized0 = json.dumps(fake_data0) jsonized1 = json.dumps(fake_data1) md5_0 = hashlib.md5(jsonized0.encode('utf-8')).hexdigest() md5_1 = hashlib.md5(jsonized1.encode('utf-8')).hexdigest() try: response = self.cleanup_queue.sendBatchMessages([fake_data0, fake_data1], 0) assert('Successful' in response) success_ids = [] for msg_result in response['Successful']: id = msg_result['Id'] success_ids.append(id) if id == '0': assert(md5_0 == msg_result['MD5OfMessageBody']) elif id == '1': assert(md5_1 == msg_result['MD5OfMessageBody']) assert('0' in success_ids) assert('1' in success_ids) finally: for message_id, receipt_handle, _ in self.cleanup_queue.receiveMessage(): self.cleanup_queue.deleteMessage(message_id, receipt_handle)