Ejemplo n.º 1
0
def test_list_all_rentals(_list_all_rentals):
    """ customers """
    HPNorton = l.HPNortonDB()
    HPNorton.drop_database()
    HPNorton.insert_to_mongo("./data/rental.csv")
    my_response = HPNorton.list_all_rentals()
    assert my_response == _list_all_rentals
Ejemplo n.º 2
0
def main(argv=None):
    """ Database main function """
    args = parse_cmd_arguments(argv)
    HPNorton = db.HPNortonDB()

    func_struct = (
        (args.disable_log, disable_log, ()),
        (args.all_products, HPNorton.list_all_products, ()),
        (args.available_products, HPNorton.show_available_products, ()),
        (args.all_customers, HPNorton.list_all_customers, ()),
        (args.all_rentals, HPNorton.list_all_rentals, ()),
        (args.drop_collections, HPNorton.drop_collections, ()),
        (args.drop_database, HPNorton.drop_database, ()),
        (
            args.rentals_for_customer,
            HPNorton.rentals_for_customer,
            (args.rentals_for_customer,),
        ),
        (
            args.customers_renting_product,
            HPNorton.customers_renting_product,
            (args.customers_renting_product,),
        ),
        (args.parallel, HPNorton.parallel, (args.parallel,)),
        (args.linear, HPNorton.linear, (args.linear,)),
    )

    pprint(
        list(
            map(
                lambda x: x[1](*x[2]),
                filter(lambda x: x[0] is not False, func_struct),
            )
        )
    )
Ejemplo n.º 3
0
def test_rentals_for_customer(_list_rentals_for_customer):
    """ rentals for customers """
    HPNorton = l.HPNortonDB()
    HPNorton.drop_database()
    HPNorton.insert_to_mongo("./data/customers.csv")
    HPNorton.insert_to_mongo("./data/product.csv")
    HPNorton.insert_to_mongo("./data/rental.csv")
    my_response = HPNorton.rentals_for_customer("C000001")
    assert my_response == _list_rentals_for_customer
Ejemplo n.º 4
0
def test_show_available_products(_show_available_products):
    """ available products """
    HPNorton = l.HPNortonDB()
    HPNorton.drop_database()

    HPNorton.insert_to_mongo("./data/product.csv")
    HPNorton.DB_NAME = "HPNorton_PyMongo_L10"
    students_response = HPNorton.show_available_products()
    assert students_response == _show_available_products
Ejemplo n.º 5
0
def test_drop_databases():
    """ Test drop HPNorton database """
    HPNorton = l.HPNortonDB()

    HPNorton.insert_to_mongo("./data/customers.csv")
    assert ("HPNorton_PyMongo_L10"
            in HPNorton.mongo.connection.list_database_names())
    HPNorton.drop_database()
    assert ("HPNorton_PyMongo_L10"
            not in HPNorton.mongo.connection.list_database_names())
Ejemplo n.º 6
0
def test_show_rentals(_list_customers_renting_product):
    """ rentals """
    HPNorton = l.HPNortonDB()
    HPNorton.drop_database()

    HPNorton.insert_to_mongo("./data/customers.csv")
    HPNorton.insert_to_mongo("./data/product.csv")
    HPNorton.insert_to_mongo("./data/rental.csv")
    students_response = HPNorton.customers_renting_product("P000001")
    assert students_response == _list_customers_renting_product
Ejemplo n.º 7
0
def test_parallel(_linear_insert):
    """ parallel import csv """
    HPNorton = l.HPNortonDB()
    HPNorton.drop_database()

    results = HPNorton.parallel(
        ["./data/customers.csv", "./data/product.csv", "./data/rental.csv"])

    for result in results:
        del result[next(iter(result))]["elapsed"]

    assert _linear_insert == results
Ejemplo n.º 8
0
def test_insert_to_mongo():
    """ import given csv file into mongo """
    HPNorton = l.HPNortonDB()
    HPNorton.drop_collections()

    results = HPNorton.insert_to_mongo("./data/product.csv")
    results = results["product"]
    assert results["success"] == 9
    assert results["fail"] == 0
    assert results["total_records"] == 9
    assert results["elapsed"] > 0

    results = HPNorton.insert_to_mongo("./data/customers.csv")
    results = results["customers"]
    assert results["success"] == 9
    assert results["fail"] == 0
    assert results["total_records"] == 9
    assert results["elapsed"] > 0

    results = HPNorton.insert_to_mongo("./data/rental.csv")
    results = results["rental"]
    assert results["success"] == 9
    assert results["fail"] == 0
    assert results["total_records"] == 9
    assert results["elapsed"] > 0

    results = HPNorton.insert_to_mongo("./data/product.csv")
    results = results["product"]
    assert results["success"] == 0
    assert results["fail"] == 9
    assert results["total_records"] == 9
    assert results["elapsed"] > 0

    results = HPNorton.insert_to_mongo("./data/customers.csv")
    results = results["customers"]
    assert results["success"] == 0
    assert results["fail"] == 9
    assert results["total_records"] == 9
    assert results["elapsed"] > 0

    results = HPNorton.insert_to_mongo("./data/rental.csv")
    results = results["rental"]
    assert results["success"] == 0
    assert results["fail"] == 9
    assert results["total_records"] == 9
    assert results["elapsed"] > 0
Ejemplo n.º 9
0
def test_drop_collections():
    """ Test drop HPNorton collections """
    HPNorton = l.HPNortonDB()

    HPNorton.insert_to_mongo("./data/customers.csv")
    HPNorton.insert_to_mongo("./data/product.csv")
    HPNorton.insert_to_mongo("./data/rental.csv")
    collection_names = (
        HPNorton.mongo.connection.HPNorton_PyMongo_L10.list_collection_names())
    assert "customers" in collection_names
    assert "product" in collection_names
    assert "rental" in collection_names
    HPNorton.drop_collections()
    collection_names = (
        HPNorton.mongo.connection.HPNorton_PyMongo_L10.list_collection_names())
    assert "customers" not in collection_names
    assert "product" not in collection_names
    assert "rental" not in collection_names