def test_response_error(self): res = Responses.encode_fail("Test error") res_q = SQS(self.cli.cli_q_name) res_q.send(res, {}) with self.assertRaises(Exception): self.cli.wait_response()
def send_file(self, name, really): my_queue_name = my_queue_name_prefix + str(uuid.uuid4()) with SQS(my_queue_name) as my_queue: remote_file_name = my_queue_name + "-normal-file.txt" if really: s3 = S3(args.bucket) s3.upload(local_file=name, remote_file=remote_file_name) sqs = SQS(args.queue) sqs.send(msg=Requests.encode_file(remote_file_name, my_queue_name), attrs={}) count = 0 msg = {} while count < 100: msg = my_queue.recv() if msg is None: time.sleep(0.005) count += 1 else: break else: self.fail("No response from the server") res = Responses.decode(msg["Body"]) if really: self.assertTrue("error" not in res) self.assertTrue("s3url" in res) parts = res["s3url"].split() self.assertEqual(len(parts), 2) bucket = parts[0] name = parts[1] res_s3 = S3(bucket) local_file = "{}-downloaded.txt".format(name) res_s3.download(local_file=local_file, remote_file=name) data = "" with open(local_file, "r") as f: data = f.read() decoded = json.loads(data) os.remove(local_file) return decoded else: self.assertTrue("error" in res) self.assertTrue("s3url" not in res)
def test_response(self): #self.out_b.upload("lorem.txt", "a.txt") res = Responses.encode_success("{} a.txt".format(self.out_b.name)) res_q = SQS(self.cli.cli_q_name) res_q.send(res, {}) res = self.cli.wait_response()
def send_error(queue_name): try: sqs = SQS(queue_name) sqs.send(msg=Responses.encode_fail("Shit hit the fan"), attrs={}) except BaseException as e: print("Well, that went really wrong: {}".format(e))