def test_upload_to_db_s3_OK_es_KO():
    label_file = "test/resources/labels.json"
    bucket_name = cluster_conf.BUCKET_NAME
    key_prefix = ""
    es_ip_host = cluster_conf.ES_HOST_IP
    es_port_host = cluster_conf.ES_HOST_PORT
    s3_success, es_success, fail = upload.upload_to_db(label_file,
                                                       es_ip_host,
                                                       es_port_host,
                                                       ES_TEST_INDEX,
                                                       bucket_name=bucket_name,
                                                       key_prefix=key_prefix,
                                                       overwrite=True)
    update_db.delete_pic_and_index(label_file,
                                   bucket_name,
                                   key_prefix,
                                   ES_TEST_INDEX,
                                   es_ip_host,
                                   es_port_host,
                                   s3_only=True)
    s3_success, es_success, fail = upload.upload_to_db(label_file,
                                                       es_ip_host,
                                                       es_port_host,
                                                       ES_TEST_INDEX,
                                                       bucket_name=bucket_name,
                                                       key_prefix=key_prefix,
                                                       overwrite=False)
    update_db.delete_pic_and_index(label_file, bucket_name, key_prefix,
                                   ES_TEST_INDEX, es_ip_host, es_port_host)
    assert (s3_success, es_success, fail) == (3, 0, 4)
Example #2
0
def create_and_delete_test_index():
    es_utils.delete_index(ES_TEST_INDEX, host_ip=ES_HOST_IP, port=ES_HOST_PORT)
    es_utils.create_es_index(ES_HOST_IP, ES_HOST_PORT, ES_TEST_INDEX)
    yield True
    update_db.delete_pic_and_index(LABELS, BUCKET_NAME, KEY_PREFIX,
                                   ES_TEST_INDEX, ES_HOST_IP, ES_HOST_PORT)
    update_db.delete_pic_and_index(LABELS, BUCKET_NAME, WRONG_KEY_PREFIX,
                                   ES_TEST_INDEX, ES_HOST_IP, ES_HOST_PORT)
def test_upload_to_db_key_prefix():
    label_file = "test/resources/labels.json"
    bucket_name = cluster_conf.BUCKET_NAME + "/"
    key_prefix = "/weird/path//"
    es_ip_host = cluster_conf.ES_HOST_IP
    es_port_host = cluster_conf.ES_HOST_PORT
    s3_success, es_success, fail = upload.upload_to_db(label_file,
                                                       es_ip_host,
                                                       es_port_host,
                                                       ES_TEST_INDEX,
                                                       bucket_name=bucket_name,
                                                       key_prefix=key_prefix,
                                                       overwrite=True)
    update_db.delete_pic_and_index(label_file, bucket_name, key_prefix,
                                   ES_TEST_INDEX, es_ip_host, es_port_host)
    assert (s3_success, es_success, fail) == (3, 3, 1)