コード例 #1
0
def test_read_db_from_disk():
    """ Tests that database can be loaded from disk """
    d1 = Donor('Maggie', 1000, 2000, 3000)
    d2 = Donor('Doug', 1111, 2222, 3333, 4444, 5555)
    d3 = Donor('キラ')
    db1 = db()
    db1.add_donor(d1)
    db1.add_donor(d2)
    db1.add_donor(d3)
    db2 = db()
    db1.save_db_to_disk('./test_db.pkl')
    db2.read_db_from_disk('./test_db.pkl')
    assert str(d1) in str(db2.database)
    assert str(d2) in str(db2.database)
    assert str(d3) in str(db2.database)
    os.remove('./test_db.pkl')

    with pytest.raises(FileNotFoundError):
        db2.read_db_from_disk('./test_db.pkl')
コード例 #2
0
def test_save_db_to_disk():
    """ Tests that you can save the database to disk """
    d1 = Donor('Maggie', 1000, 2000, 3000)
    d2 = Donor('Doug', 1111, 2222, 3333, 4444, 5555)
    d3 = Donor('キラ')
    db1 = db()
    db1.add_donor(d1)
    db1.add_donor(d2)
    db1.add_donor(d3)
    db1.save_db_to_disk('./test_db.pkl')
    assert os.path.isfile('./test_db.pkl')
    os.remove('./test_db.pkl')
コード例 #3
0
def test_remove_donation():
    """ Test ability to remove a donation from a donor """
    d1 = Donor('Maggie', 1000, 2000, 3000)
    db1 = db(d1)
    assert 1000 in d1.donations
    db1.remove_donation('Maggie', 1000)
    assert 1000 not in d1.donations
    assert 2000 in d1.donations
    db1.remove_donation('Maggie', 2000)
    assert 2000 not in d1.donations
    assert db1.remove_donation('Doug', 2000) ==\
        'Donation 2000 from donor Doug not found in database'
コード例 #4
0
def test_donordb_repr():
    """ Tests donordb __repr__ method """
    d1 = Donor('Maggie', 1000, 2000, 3000)
    d2 = Donor('Doug', 1111, 2222, 3333, 4444, 5555)
    d3 = Donor('キラ', 9001)
    db1 = db()
    db1.add_donor(d1)
    db1.add_donor(d2)
    db1.add_donor(d3)
    string = f'{d1.name:>24} : {d1.donations}\n'
    string += f'{d2.name:>24} : {d2.donations}\n'
    string += f'{d3.name:>24} : {d3.donations}\n'
    assert string == repr(db1)
コード例 #5
0
def test_add_donor():
    """ Tests that you can add a donor to the database """
    d1 = Donor('Maggie')
    d2 = Donor('Doug', 1000)
    d3 = Donor('キラ', 9001)
    db1 = db(d1)
    db1.add_donor(d2)
    db1.add_donor(d3)
    assert str(d1) in str(db1.database)
    assert str(d2) in str(db1.database)
    assert str(d3) in str(db1.database)
    assert db1.add_donor('Maggie') == 'Maggie already exists in database'
    assert db1.add_donor('Kurami') == 'Kurami has been added to the database'
    assert 'Kurami' in str(db1.database)
コード例 #6
0
def test_rename_donor():
    """ Tests that you can rename a donor """
    d1 = Donor('Light', 1000, 2000, 3000)
    d2 = Donor('Doug', 1111, 2222, 3333, 4444, 5555)
    db1 = db()
    db1.add_donor(d1)
    db1.add_donor(d2)

    db1.rename_donor('Light', 'キラ')
    assert 'Light' not in str(db1.database)
    assert 'キラ' in str(db1.database)
    assert db1.rename_donor('Light',
                            'キラ') == 'Donor キラ already exists in database'
    assert db1.rename_donor('キラ',
                            'Doug') == 'Donor Doug already exists in database'
コード例 #7
0
def test_remove_donor():
    """ Tests ability to remove a donor from donordb """
    d1 = Donor('Maggie', 1000, 2000, 3000)
    d2 = Donor('Doug', 1111, 2222, 3333, 4444, 5555)
    d3 = Donor('キラ', 9001)
    db1 = db()
    db1.add_donor(d1)
    db1.add_donor(d2)
    db1.add_donor(d3)
    assert str(d1) in str(db1.database)
    db1.remove_donor('Maggie')
    assert str(d1) not in str(db1.database)
    assert str(d2) in str(db1.database)
    db1.remove_donor('Doug')
    assert str(d2) not in str(db1.database)
    assert db1.remove_donor('Kurami') == 'Kurami not found in database'
    assert 'Kurami' not in db1.database
コード例 #8
0
def test_add_donation2():
    """ Tests that you can add a donation to the database """
    d1 = Donor('Maggie')
    db1 = db(d1)
    assert 2000 not in db1.database['Maggie'].donations
    db1.add_donation('Maggie', 2000)
    assert 2000 in db1.database['Maggie'].donations
    db1.add_donation('Maggie', 5000)
    assert 5000 in db1.database['Maggie'].donations
    assert db1.add_donation(
        'Maggie', int('-1000')) == '-1000 is not a valid donation amount'
    assert -1000 not in db1.database
    assert db1.add_donation(
        'Maggie', 'foobar') == 'foobar is not a valid donation amount'
    assert 'foobar' not in db1.database
    assert db1.add_donation('Doug', 1000) == 'Doug not found in database'
    assert 1000 not in db1.database