Example #1
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 #2
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 #3
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 #4
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 #5
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
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,
    }