Skip to content

Commit

Permalink
Added a helper test for hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
Digant C Kasundra committed May 23, 2015
1 parent 75c45a6 commit 27b8217
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions tests/model_tests/test_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,47 @@
from sqlalchemy.exc import IntegrityError

from hermes import exc
from hermes import models
from hermes.models import Host

from .fixtures import db_engine, session
from .fixtures import db_engine, session, sample_data1


def test_creation(session):
models.Host.create(session, "abc-123")
Host.create(session, "abc-123")
session.commit()

hosts = session.query(models.Host).all()
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"


def test_duplicate(session):
models.Host.create(session, "abc-123")
Host.create(session, "abc-123")

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

models.Host.create(session, "abc-456")
Host.create(session, "abc-456")


def test_required(session):
models.Host.create(session, "abc-123")
Host.create(session, "abc-123")

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

def test_helpers(sample_data1):
host = Host.get_host(sample_data1, "example.dropbox.com")
assert host.id == 1
assert host.hostname == "example.dropbox.com"

events = host.get_latest_events().all()

assert len(events) == 2
assert events[0].note == "example.dropbox.com rebooted."

0 comments on commit 27b8217

Please sign in to comment.