예제 #1
0
def test_creation():
    db = DB()

    # should not exist
    assert not os.path.isfile(db.path)
    assert not db.db_exists()

    # should exist
    db.init_db()
    assert os.path.isfile(db.path)
    assert db.db_exists()

    ts_orig = os.path.getmtime(db.path)
    # should not overwrite
    db.init_db()
    ts_new = os.path.getmtime(db.path)
    assert ts_orig == ts_new

    # should  overwrite
    db.init_db(overwrite=True)
    ts_new = os.path.getmtime(db.path)
    assert ts_orig != ts_new

    # remove the db manually... cleanup
    os.remove(db.path)
예제 #2
0
def test_delete_person():
    """Functional task of adding people and updating some people."""
    db = DB()
    db.init_db(overwrite=True)

    for p in test_people_inputs:
        db.add_person(p)  # add people to db

    deleted_person = test_people_inputs.pop(1)
    db.delete_person(*deleted_person.get_name())

    db_people = db.get_people()
    for p in test_people_inputs:
        assert p.deep_membership(db_people)
    for p in db_people:
        assert p.deep_membership(test_people_inputs)

    db.drop_db()
예제 #3
0
def test_drop():
    db = DB()

    # should not exist
    assert not db.db_exists()

    # should exist
    db.init_db()
    assert db.db_exists()

    db.drop_db()
    assert not db.db_exists()
예제 #4
0
def test_add_get_people():
    """Functional task of adding people and retrieving the same people."""
    db = DB()
    db.init_db(overwrite=True)

    for p in test_people_inputs:
        db.add_person(p)
        # test get as we add each
        p_from_db = db.get_person(*p.get_name())
        assert p_from_db == p

    # testing getting all people
    db_people = db.get_people()
    for p in test_people_inputs:
        assert p in db_people
    for p in db_people:
        assert p in test_people_inputs

    db.drop_db()
예제 #5
0
def person_cli():
    settings = Settings()

    parser = argparse.ArgumentParser(
        description="Interface with the person db")
    subparsers = parser.add_subparsers(help="person db CLI subcommands",
                                       dest="{add,get,del}")
    subparsers.required = True

    # subparser to add/update person
    parser_add = subparsers.add_parser("add", help="add/update person")
    parser_add.add_argument("first_name", help="contact's first name")
    parser_add.add_argument("last_name", help="contact's last name")
    parser_add.add_argument(
        "-t",
        "--attributes",
        nargs="+",
        help="<attribute>=<value> (attributes include" + ": " +
        ", ".join(poundingpave.person.required_attributes) + ")")
    parser_add.set_defaults(func=add_person_cli)

    # subparser to query people
    parser_get = subparsers.add_parser("get", help="query person")
    group_get = parser_get.add_mutually_exclusive_group(required=True)
    group_get.add_argument("-a",
                           "--all",
                           action='store_true',
                           help="retrieve all")
    group_get.add_argument("-p",
                           "--person",
                           nargs=2,
                           metavar=("first_name", "last_name"),
                           help="retrieve person with first and last name")
    parser_get.set_defaults(func=print_person_cli)

    # subparser to delete person
    parser_del = subparsers.add_parser("del", help="delete person")
    parser_del.add_argument("first_name", help="contact's first name")
    parser_del.add_argument("last_name", help="contact's last name")
    parser_del.set_defaults(func=del_person_cli)

    # subparser for testing...
    parser_test = subparsers.add_parser("test")
    parser_test.add_argument("attrs", nargs="*", metavar="key=value")
    parser_test.set_defaults(func=run_test_cli)

    db = Person_DB_CSV(settings.db_people_path)
    args = parser.parse_args()

    args.func(args, db)
예제 #6
0
def test_existence():

    db = DB()

    # should not exist
    assert not db.db_exists()

    # should exist
    db.init_db()
    assert db.db_exists()

    os.remove(db.path)
    assert not db.db_exists()
예제 #7
0
def test_update_people():
    """Functional task of adding people and updating some people."""
    db = DB()
    db.init_db(overwrite=True)

    for p in test_people_inputs:
        db.add_person(p)  # add people to db

    updated_test_people = []

    test_people_inputs[0].set_company("new comp")
    test_people_inputs[0].set_work_phone("spam")
    updated_test_people.append(test_people_inputs[0])

    test_people_inputs[1].set_email("fake email")
    tst_cp_1 = copy.deepcopy(test_people_inputs[1])
    test_people_inputs[1].reset_notes()
    test_people_inputs[1].add_notes("first note")
    tst_cp_1.add_notes("first note")
    test_people_inputs[1].add_notes(["2nd note", '3rd note'])
    tst_cp_1.add_notes(["2nd note", '3rd note'])

    test_people_inputs[1].reset_interactions()
    test_people_inputs[1].add_interactions(["2nd note", '3rd note'])
    tst_cp_1.add_interactions(["2nd note", '3rd note'])
    updated_test_people.append(tst_cp_1)

    test_people_inputs[2].set_role("fake job")
    test_people_inputs[2].set_mobile_phone("not real")
    tst_cp_2 = copy.deepcopy(test_people_inputs[2])
    test_people_inputs[2].reset_notes()
    test_people_inputs[2].reset_interactions()
    updated_test_people.append(tst_cp_2)

    tst_cp_3 = copy.deepcopy(test_people_inputs[3])
    test_people_inputs[3].reset_notes()
    test_people_inputs[3].reset_interactions()
    test_people_inputs[3].update({
        'company': 'comp a',
        'email': 'email b',
        'mobile_phone': 'phone c',
        'work_phone': 'phone d',
        'interaction': ["itc e", "itc f", "itc g"],
        'notes': ['notes h', 'notes i']
    })

    tst_cp_3.set_company('comp a')
    tst_cp_3.set_email('email b')
    tst_cp_3.set_mobile_phone('phone c')
    tst_cp_3.set_work_phone('phone d')

    tst_cp_3.add_notes(['notes h', 'notes i'])
    tst_cp_3.add_interactions(["itc e", "itc f", "itc g"])
    updated_test_people.append(tst_cp_3)

    # make changes in db
    for p in test_people_inputs:
        db.add_person(p, overwrite=True)

    db_people = db.get_people()
    for p in updated_test_people:
        assert p.deep_membership(db_people)
    for p in db_people:
        assert p.deep_membership(updated_test_people)

    db.drop_db()
예제 #8
0
def test_header():
    db = DB()
    assert db.header() == [
        'first_name', 'last_name', 'company', 'email', 'mobile_phone',
        'work_phone', 'role', 'interaction', 'notes'
    ]