def test_bucket_operations_bin(requireMocking): """ simple test for out bucket :param requireMocking: :return: """ bucket = Bucket(os.environ["resultTable"]) assert not bucket.exists("test.zip") bucket.save("test.zip", str.encode("tada")) assert bucket.exists("test.zip") assert bucket.load("test.zip", binary=True) == str.encode("tada") bucket.delete("test.zip") assert not bucket.exists("test.zip")
def test_bucket_operations_txt(requireMocking): """ simple test for out bucket :param requireMocking: :return: """ bucket = Bucket(os.environ["resultTable"]) assert not bucket.exists("test.txt") bucket.save("test.txt", "tada") assert bucket.exists("test.txt") assert bucket.load("test.txt") == "tada" bucket.delete("test.txt") assert not bucket.exists("test.txt")
def test_get(requireMocking): # test inexistent file event = {"pathParameters": {"sample": "test"}} result = exists.exists(event, {}) print(json.dumps(result, indent=2)) assert 404 == result['statusCode'] # test existing file data_carrot = Bucket(os.environ['dataBucket']) data_carrot.save('test', 'blah') result = exists.exists(event, {}) print(json.dumps(result, indent=2)) assert 200 == result['statusCode']
def triggerEvent(data): """ submits the given data to the queue :param data: requires sample :return: a serialized version of the submitted message """ validate(data, __RESULT_SCHEMA__) timestamp = int(time.time() * 1000) data['time'] = timestamp data['id'] = data['sample'] if 'sample' in data: table = Bucket(os.environ['resultTable']) # lookup from the stasis tables the correct file handle # TODO right now we are faking it name = get_file_handle(data['id']) existing = table.exists(name) if existing: existing = json.loads(table.load(name)) # need to append and/or update result to injections data['injections'] = { **existing['injections'], **data['injections'] } result = table.save( name, json.dumps(TableManager().sanitize_json_for_dynamo(data))) return { 'body': json.dumps(data), 'statusCode': result['ResponseMetadata']['HTTPStatusCode'], 'isBase64Encoded': False, 'headers': __HTTP_HEADERS__ } else: return { 'body': json.dumps({'error': 'no sample provided'}), 'statusCode': 400, 'isBase64Encoded': False, 'headers': __HTTP_HEADERS__ }