def setup(self): """ Set up the unit test suite. .. versionadded:: 0.2.0 """ self.database = MockDatabase()
def setup(self): """ Set up the unit test suite. .. versionadded:: 0.2.0 """ self.database = MockDatabase()
class TestMockDatabase(object): """ Nose unit test suite for Probe MockDatabase. .. versionadded:: 0.2.0 """ class MockRecord: def __init__(self, value): self.id = None self.value = value def setup(self): """ Set up the unit test suite. .. versionadded:: 0.2.0 """ self.database = MockDatabase() def teardown(self): """ Tear down the unit test suite. .. versionadded:: 0.2.0 """ pass def test_init(self): """ Test that the database has been initialised correctly. .. versionadded:: 0.2.0 """ assert_equals(self.database.pending, []) assert_equals(self.database.data, []) assert_equals(self.database.unique, False) assert_true(self.database.keys) def test_add(self): """ Test that data has been added to the database. .. versionadded:: 0.2.0 """ self.database.add("data") assert_equals(self.database.pending, ["data"]) assert_equals(self.database.data, []) def test_commit(self): """ Test that changes have been comitted to the database. .. versionadded:: 0.2.0 """ record = self.MockRecord("data") self.database.add(record) assert_equals(self.database.pending, [record]) assert_equals(self.database.data, []) assert_equals(self.database.pending[0].id, None) self.database.commit() assert_equals(self.database.pending, []) assert_equals(self.database.data, [record]) assert_true(self.database.data[0].id != None) # check that the behaviour is "correct" when unique mode is enabled self.database.unique = True self.database.add(record) assert_equals(self.database.pending, [record]) assert_equals(self.database.data, [record]) assert_raises(MockDatabaseError, self.database.commit) def test_query(self): """ Test that the queried results are returned from the database. .. versionadded:: 0.2.0 """ record = self.MockRecord("data") # setup some test data self.database.add(record) self.database.commit() result = self.database.query(self.MockRecord) # actually do the test assert_equals(type(result), MockDatabaseFilter) # make sure the expected data type is returned assert_equals(result.filter(None).all(), [record]) # make sure the query actually finds the record def test_rollback(self): """ Test that pending changes are rolled back. .. versionadded:: 0.2.0 """ self.database.add("data") assert_equals(self.database.pending, ["data"]) assert_equals(self.database.data, []) self.database.rollback() assert_equals(self.database.pending, []) assert_equals(self.database.data, [])
class TestMockDatabase(object): """ Nose unit test suite for Probe MockDatabase. .. versionadded:: 0.2.0 """ class MockRecord: def __init__(self, value): self.id = None self.value = value def setup(self): """ Set up the unit test suite. .. versionadded:: 0.2.0 """ self.database = MockDatabase() def teardown(self): """ Tear down the unit test suite. .. versionadded:: 0.2.0 """ pass def test_init(self): """ Test that the database has been initialised correctly. .. versionadded:: 0.2.0 """ assert_equals(self.database.pending, []) assert_equals(self.database.data, []) assert_equals(self.database.unique, False) assert_true(self.database.keys) def test_add(self): """ Test that data has been added to the database. .. versionadded:: 0.2.0 """ self.database.add("data") assert_equals(self.database.pending, ["data"]) assert_equals(self.database.data, []) def test_commit(self): """ Test that changes have been comitted to the database. .. versionadded:: 0.2.0 """ record = self.MockRecord("data") self.database.add(record) assert_equals(self.database.pending, [record]) assert_equals(self.database.data, []) assert_equals(self.database.pending[0].id, None) self.database.commit() assert_equals(self.database.pending, []) assert_equals(self.database.data, [record]) assert_true(self.database.data[0].id != None) # check that the behaviour is "correct" when unique mode is enabled self.database.unique = True self.database.add(record) assert_equals(self.database.pending, [record]) assert_equals(self.database.data, [record]) assert_raises(MockDatabaseError, self.database.commit) def test_query(self): """ Test that the queried results are returned from the database. .. versionadded:: 0.2.0 """ record = self.MockRecord("data") # setup some test data self.database.add(record) self.database.commit() result = self.database.query(self.MockRecord) # actually do the test assert_equals( type(result), MockDatabaseFilter) # make sure the expected data type is returned assert_equals( result.filter(None).all(), [record]) # make sure the query actually finds the record def test_rollback(self): """ Test that pending changes are rolled back. .. versionadded:: 0.2.0 """ self.database.add("data") assert_equals(self.database.pending, ["data"]) assert_equals(self.database.data, []) self.database.rollback() assert_equals(self.database.pending, []) assert_equals(self.database.data, [])