Skip to content

Commit

Permalink
Modified now that I know what Travis CI's sqlite prefers
Browse files Browse the repository at this point in the history
  • Loading branch information
Digant C Kasundra committed May 14, 2015
1 parent 2b71f1c commit 0f2aa65
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
6 changes: 4 additions & 2 deletions tests/model_tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ def fin():
return session

@pytest.fixture
def sample_data1(db_engine):
def sample_data1(session):
sql_file = open('tests/sample_data/sample_data1.sql')
sql = sql_file.read()
for statement in sql.split(";"):
db_engine.execute(statement)
session.execute(statement)

return session
16 changes: 8 additions & 8 deletions tests/model_tests/test_fates.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
from .fixtures import db_engine, session, sample_data1


def test_creation(session, sample_data1):
event_types = session.query(models.EventType).all()
def test_creation(sample_data1):
event_types = sample_data1.query(models.EventType).all()
assert len(event_types) == 4

event_type1 = event_types[2]
event_type2 = event_types[3]

models.Fate.create(session, event_type1, event_type2, "New fate")
session.commit()
models.Fate.create(sample_data1, event_type1, event_type2, "New fate")
sample_data1.commit()

fates = session.query(models.Fate).all()
fates = sample_data1.query(models.Fate).all()

# the total number of fates should be 2 now. We care about the new one
assert len(fates) == 2
Expand All @@ -28,12 +28,12 @@ def test_creation(session, sample_data1):
assert fate.description == "New fate"


def test_duplicate(session, sample_data1):
event_types = session.query(models.EventType).all()
def test_duplicate(sample_data1):
event_types = sample_data1.query(models.EventType).all()
assert len(event_types) == 4

event_type1 = event_types[0]
event_type2 = event_types[1]

with pytest.raises(IntegrityError):
models.Fate.create(session, event_type1, event_type2, "Dup fate")
models.Fate.create(sample_data1, event_type1, event_type2, "Dup fate")
19 changes: 14 additions & 5 deletions tests/sample_data/sample_data1.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
INSERT INTO `event_types` (`id`, `category`, `state`, `description`)
INSERT INTO event_types
VALUES
(1,'system-reboot','required','This system requires a reboot.');

INSERT INTO event_types
VALUES
(2,'system-reboot','completed','This system rebooted.');

INSERT INTO event_types
VALUES
(3,'system-maintenance','required','This system requires maintenance.');

INSERT INTO event_types
VALUES
(1,'system-reboot','required','This system requires a reboot.'),
(2,'system-reboot','completed','This system rebooted.'),
(3,'system-maintenance','required','This system requires maintenance.'),
(4,'system-maintenance','completed','System maintenance completed.');

INSERT INTO `fates` (`id`, `creation_type_id`, `completion_type_id`, `description`)
INSERT INTO fates
VALUES
(1,1,2,'A system that needs a reboot can be cleared by rebooting the machine.');

0 comments on commit 0f2aa65

Please sign in to comment.