Esempio n. 1
0
def test_creation(session):
    Host.create(session, "abc-123")
    session.commit()

    hosts = session.query(Host).all()

    assert len(hosts) == 1
    assert hosts[0].id == 1
    assert hosts[0].hostname == "abc-123"

    host = Host.get_host(session, "abc-123")
    assert host.id == 1
    assert host.hostname == "abc-123"
Esempio n. 2
0
def test_duplicate(session):
    Host.create(session, "abc-123")

    with pytest.raises(IntegrityError):
        Host.create(session, "abc-123")

    Host.create(session, "abc-456")
Esempio n. 3
0
def test_get_latest_events(session):
    event_type1 = EventType.create(session, "foo", "bar", "test type 1")
    event_type2 = EventType.create(session, "foo", "baz", "test type 2")

    host1 = Host.create(session, "server1")
    host2 = Host.create(session, "server2")

    Event.create(session, host1, "testman", event_type1)
    Event.create(session, host1, "testman", event_type2)
    Event.create(session, host2, "testman", event_type1)
    Event.create(session, host1, "testman", event_type1)
    Event.create(session, host1, "testman", event_type2)
    last_type2 = Event.create(session, host2, "testman", event_type2)
    last_type1 = Event.create(session, host2, "testman", event_type1)

    events1 = event_type1.get_latest_events().all()
    events2 = event_type2.get_latest_events().all()

    assert len(events1) == 4
    assert len(events2) == 3

    assert events1[0] == last_type1
    assert events2[0] == last_type2
Esempio n. 4
0
def test_get_latest_events(session):
    event_type1 = EventType.create(session, "foo", "bar", "test type 1")
    event_type2 = EventType.create(session, "foo", "baz", "test type 2")

    host1 = Host.create(session, "server1")
    host2 = Host.create(session, "server2")

    Event.create(session, host1, "testman", event_type1)
    Event.create(session, host1, "testman", event_type2)
    Event.create(session, host2, "testman", event_type1)
    Event.create(session, host1, "testman", event_type1)
    Event.create(session, host1, "testman", event_type2)
    last_type2 = Event.create(session, host2, "testman", event_type2)
    last_type1 = Event.create(session, host2, "testman", event_type1)

    events1 = event_type1.get_latest_events().all()
    events2 = event_type2.get_latest_events().all()

    assert len(events1) == 4
    assert len(events2) == 3

    assert events1[0] == last_type1
    assert events2[0] == last_type2
Esempio n. 5
0
def test_required(session):
    Host.create(session, "abc-123")

    with pytest.raises(exc.ValidationError):
        Host.create(session, None)