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

    assert str(host1) == json.dumps(host1.get_json(), indent=4, default=str)
Example #2
0
def test_get_addr():
    db = Database()
    addr1 = 'localhost'
    addr2 = '127.0.0.1'
    addr3 = 'x011?!-\n/\\nw#!/.,x;{test}[lol]'
    host1 = Host(addr1, db)
    host2 = Host(addr2, db)

    assert host1.get_addr() == host1._Host__addr
Example #3
0
def test___init__():
    db = Database()
    addr1 = 'localhost'
    addr2 = '127.0.0.1'
    addr3 = 'x011?!-\n/\\nw#!/.,x;{test}[lol]'
    host1 = Host(addr1, db)
    host2 = Host(addr2, db)

    assert host1._Host__db == db
    assert host1._Host__addr == addr1
Example #4
0
def test_get_csv():
    db = Database()
    addr1 = 'localhost'
    addr2 = '127.0.0.1'
    addr3 = 'x011?!-\n/\\nw#!/.,x;{test}[lol]'
    host1 = Host(addr1, db)
    host2 = Host(addr2, db)

    assert host1.get_csv(
    ) == f"{host1._Host__addr}, {host1._Host__alive}, {host1._Host__timestamp}\n"
Example #5
0
def test_is_alive():
    db = Database()
    addr1 = 'localhost'
    addr2 = '127.0.0.1'
    addr3 = 'x011?!-\n/\\nw#!/.,x;{test}[lol]'
    host1 = Host(addr1, db)
    host2 = Host(addr2, db)

    errors = []
    host1._Host__check_error(errors, '100%', 'host_packet_loss') == []
Example #6
0
def test_get_json():
    db = Database()
    addr1 = 'localhost'
    addr2 = '127.0.0.1'
    addr3 = 'x011?!-\n/\\nw#!/.,x;{test}[lol]'
    host1 = Host(addr1, db)
    host2 = Host(addr2, db)

    assert host1.get_json() == {
        'addr': host1._Host__addr,
        'alive': host1._Host__alive,
        'timestamp': host1._Host__timestamp,
        'errors': host1._Host__errors,
        'data': host1._Host__data,
    }
Example #7
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
Example #8
0
def test___error_equal():
    db = Database()
    addr1 = 'localhost'
    addr2 = '127.0.0.1'
    addr3 = 'x011?!-\n/\\nw#!/.,x;{test}[lol]'
    host1 = Host(addr1, db)
    host2 = Host(addr2, db)
    host3 = Host(addr2, db)

    assert db._Database__error_equal(host1.get_json(),
                                     host1.get_json()) == True
    assert db._Database__error_equal(host1.get_json(),
                                     host2.get_json()) == False

    host3._Host__alive = True
    assert db._Database__error_equal(host2.get_json(),
                                     host3.get_json()) == False
Example #9
0
def test_insert_error():
    db = Database()
    addr1 = 'localhost'
    addr2 = '127.0.0.1'
    addr3 = 'x011?!-\n/\\nw#!/.,x;{test}[lol]'
    host1 = Host(addr1, db)

    db.insert_error(host1.get_json())
    assert db._Database__errors[0] == host1.get_json()
Example #10
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))
Example #11
0
def test___eq__():
    db = Database()
    addr1 = 'localhost'
    addr2 = '127.0.0.1'
    addr3 = 'x011?!-\n/\\nw#!/.,x;{test}[lol]'
    host1 = Host(addr1, db)
    host2 = Host(addr2, db)
    host3 = Host(addr2, db)

    assert (host1 == host1) == True
    assert (host1 == host2) == False
    assert (host2 == host3) == True

    host3._Host__alive = True
    assert (host2 == host3) == False

    host3._Host__alive = False
    assert (host2 == host3) == True

    host3._Host__timestamp = 1
    assert (host2 == host3) == False
Example #12
0
def test_select_newest_errors():
    db = Database()
    addr1 = 'localhost'
    addr2 = '127.0.0.1'
    addr3 = 'x011?!-\n/\\nw#!/.,x;{test}[lol]'
    host1 = Host(addr1, db)

    assert db.select_newest_errors() == []
    db.insert_error(host1.get_json())
    assert len(db.select_newest_errors()) == 1
    assert db.select_newest_errors()[0] == host1.get_json()
    db.insert_error(host1.get_json())
    assert len(db.select_newest_errors()) == 1
    assert db.select_newest_errors()[0] == host1.get_json()
Example #13
0
def test_select_error():
    db = Database()
    addr1 = 'localhost'
    addr2 = '127.0.0.1'
    addr3 = 'x011?!-\n/\\nw#!/.,x;{test}[lol]'
    host1 = Host(addr1, db)

    db.insert_error(host1.get_json())
    assert len(db.select_error()) == 1
    assert db.select_error()[0] == host1.get_json()
    assert db.select_error(addr1) == host1.get_json()
    assert db.select_error(addr2) == {}

    assert db.select_error(addr3) == {}
    assert db.select_error([addr1, addr2, addr3]) == {}
    assert db.select_error((addr1, addr2, addr3)) == {}

    db.insert_error(host1.get_json())
    assert len(db.select_error()) == 1