Ejemplo n.º 1
0
def test_select():
    db = Database()
    addr1 = 'localhost'
    addr2 = '127.0.0.1'
    addr3 = 'x011?!-\n/\\nw#!/.,x;{test}[lol]'
    host1 = Host(addr1, db)

    db.insert(Host(addr1, db))

    assert db.select()[0].get_addr() == addr1
    assert db.select(addr1).get_addr() == addr1
    assert db.select(addr2) == None

    assert db.select(addr3) == None
    assert db.select([addr1, addr2, addr3]) == None
    assert db.select((addr1, addr2, addr3)) == None
Ejemplo n.º 2
0
def test_insert():
    db = Database()
    addr1 = 'localhost'
    addr2 = '127.0.0.1'
    addr3 = 'x011?!-\n/\\nw#!/.,x;{test}[lol]'
    host1 = Host(addr1, db)

    db.insert(Host(addr1, db))
    db.insert(Host(addr2, db))

    assert db._Database__hosts[0].get_addr() == addr1
    assert db._Database__hosts[1].get_addr() == addr2

    with pytest.raises(ValueError):
        db.insert(addr1)
    with pytest.raises(ValueError):
        db.insert([addr1])
    with pytest.raises(ValueError):
        db.insert((addr1))