Exemplo n.º 1
0
def up_method(method, test_set):
    handler = TestHandler(Matcher())
    logger = logging.getLogger()
    logger.addHandler(handler)

    radu = RadulaProxy(connection=boto.connect_s3())
    radu.make_bucket(subject=TEST_BUCKET)
    sys.stdout.truncate(0)

    args = vars(_parse_args(["-y", method]))
    args.update(test_set)
    getattr(radu, args.get("command"))(**args)

    assert_false(handler.matches(levelno=logging.ERROR))
    assert_false(handler.matches(levelno=logging.WARNING))
    assert_true(handler.matches(levelno=logging.INFO))
    msgs = [
        "uploading",
        "tests.s3.amazonaws.com/data.txt",
        "Checksum Verified!"
    ]

    fmt = "Expecting log message containing '{0}'"
    for msg in msgs:
        assert_true(
            handler.matches(message=msg),
            msg=fmt.format(msg)
        )
Exemplo n.º 2
0
def dl_method(method, test_set):
    handler = TestHandler(Matcher())
    logger = logging.getLogger()
    logger.addHandler(handler)

    radu = RadulaProxy(connection=boto.connect_s3())
    radu.make_bucket(subject=TEST_BUCKET)

    # give something to download
    args = vars(_parse_args(['up']))
    args.update({"subject": TEST_FILE, "target": REMOTE_FILE})
    radu.upload(**args)
    sys.stdout.truncate(0)

    args = vars(_parse_args([method]))
    args.update(test_set)
    args.update({"force": True})
    getattr(radu, args.get("command"))(**args)

    out = sys.stdout.getvalue().strip()
    msgs = [
        "Download Progress",
        "100.00%",
    ]

    for msg in msgs:
        fmt = "Expecting log message containing '{0}'".format(msg)
        assert_true(handler.matches(message=msg), msg=fmt.format(msg))

    target = test_set.get("target", TEST_FILE)
    assert_true(os.path.isfile(target))
    if target != TEST_FILE:
        os.remove(target)
Exemplo n.º 3
0
def copy_method(method):
    handler = TestHandler(Matcher())
    logger = logging.getLogger()
    logger.addHandler(handler)
    radu = RadulaProxy(connection=boto.connect_s3())
    radu.make_bucket(subject=TEST_BUCKET)

    # give something to download
    args = vars(_parse_args(['up']))
    args.update({
        "subject": TEST_FILE,
        "target": REMOTE_FILE
    })
    radu.upload(**args)
    sys.stdout.truncate(0)

    # 'threads' needed
    args = vars(_parse_args(['-y', method]))
    target_file = REMOTE_FILE + '-copy'
    args.update({
        "subject": REMOTE_FILE,
        "target": target_file
    })
    radu.streaming_copy(**args)

    msgs = [
        "Finished uploading",
        "tests.s3.amazonaws.com/data.txt",
        "Download URL",
        "Key data matches!"
    ]

    for msg in msgs:
        fmt = "Expecting log message containing '{0}'"
        assert_true(handler.matches(message=msg), msg=fmt.format(msg))

    radu.keys(subject=TEST_BUCKET)
    keys = [k.strip() for k in sys.stdout.getvalue().strip().split("\n")]
    expected = [REMOTE_FILE, target_file]

    fmt = "Expecting output containing '{0}'"
    for expected_key in expected:
        expected_key = os.path.basename(expected_key)
        assert_in(expected_key, keys, msg=fmt.format(expected_key))
Exemplo n.º 4
0
def verify_test():
    # ensure original text
    with open(TEST_FILE, 'w') as test_file:
        test_file.write("data")
    radu = RadulaProxy(connection=boto.connect_s3())
    radu.make_bucket(subject=TEST_BUCKET)

    # give something to download
    args = vars(_parse_args(['up']))
    args.update({"subject": TEST_FILE, "target": REMOTE_FILE})
    radu.upload(**args)
    sys.stdout.truncate(0)

    handler = TestHandler(Matcher())
    logger = logging.getLogger()
    logger.addHandler(handler)

    # 'threads' needed
    args = vars(_parse_args(["verify"]))
    args.update({"subject": TEST_FILE, "target": REMOTE_FILE})
    radu.verify(**args)

    assert_false(handler.matches(levelno=logging.ERROR))
    assert_false(handler.matches(levelno=logging.WARNING))
    assert_true(handler.matches(levelno=logging.INFO))
    msgs = [
        "Checksum Verified!",
        '8d777f385d3dfec8815d20f7496026dc',
    ]

    for msg in msgs:
        fmt = "Expecting log message containing '{0}'"
        assert_true(handler.matches(message=msg), msg=fmt.format(msg))
Exemplo n.º 5
0
def verify_test():
    # ensure original text
    with open(TEST_FILE, 'w') as test_file:
        test_file.write("data")
    radu = RadulaProxy(connection=boto.connect_s3())
    radu.make_bucket(subject=TEST_BUCKET)

    # give something to download
    args = vars(_parse_args(['up']))
    args.update({
        "subject": TEST_FILE,
        "target": REMOTE_FILE
    })
    radu.upload(**args)
    sys.stdout.truncate(0)

    handler = TestHandler(Matcher())
    logger = logging.getLogger()
    logger.addHandler(handler)

    # 'threads' needed
    args = vars(_parse_args(["verify"]))
    args.update({
        "subject": TEST_FILE,
        "target": REMOTE_FILE
    })
    radu.verify(**args)

    assert_false(handler.matches(levelno=logging.ERROR))
    assert_false(handler.matches(levelno=logging.WARNING))
    assert_true(handler.matches(levelno=logging.INFO))
    msgs = [
        "Checksum Verified!",
        '8d777f385d3dfec8815d20f7496026dc',
    ]

    for msg in msgs:
        fmt = "Expecting log message containing '{0}'"
        assert_true(handler.matches(message=msg), msg=fmt.format(msg))
Exemplo n.º 6
0
def copy_method(method):
    handler = TestHandler(Matcher())
    logger = logging.getLogger()
    logger.addHandler(handler)
    radu = RadulaProxy(connection=boto.connect_s3())
    radu.make_bucket(subject=TEST_BUCKET)

    # give something to download
    args = vars(_parse_args(['up']))
    args.update({"subject": TEST_FILE, "target": REMOTE_FILE})
    radu.upload(**args)
    sys.stdout.truncate(0)

    # 'threads' needed
    args = vars(_parse_args(['-y', method]))
    target_file = REMOTE_FILE + '-copy'
    args.update({"subject": REMOTE_FILE, "target": target_file})
    radu.streaming_copy(**args)

    msgs = [
        "Finished uploading", "tests.s3.amazonaws.com/data.txt",
        "Download URL", "Checksum Verified!"
    ]

    for msg in msgs:
        fmt = "Expecting log message containing '{0}'"
        assert_true(handler.matches(message=msg), msg=fmt.format(msg))

    radu.keys(subject=TEST_BUCKET)
    keys = [k.strip() for k in sys.stdout.getvalue().strip().split("\n")]
    expected = [REMOTE_FILE, target_file]

    fmt = "Expecting output containing '{0}'"
    for expected_key in expected:
        expected_key = os.path.basename(expected_key)
        assert_in(expected_key, keys, msg=fmt.format(expected_key))
Exemplo n.º 7
0
def up_method(method, test_set):
    handler = TestHandler(Matcher())
    logger = logging.getLogger()
    logger.addHandler(handler)

    radu = RadulaProxy(connection=boto.connect_s3())
    radu.make_bucket(subject=TEST_BUCKET)
    sys.stdout.truncate(0)

    args = vars(_parse_args(["-y", method]))
    args.update(test_set)
    getattr(radu, args.get("command"))(**args)

    assert_false(handler.matches(levelno=logging.ERROR))
    assert_false(handler.matches(levelno=logging.WARNING))
    assert_true(handler.matches(levelno=logging.INFO))
    msgs = [
        "uploading", "tests.s3.amazonaws.com/data.txt", "Checksum Verified!"
    ]

    fmt = "Expecting log message containing '{0}'"
    for msg in msgs:
        assert_true(handler.matches(message=msg), msg=fmt.format(msg))