def test_should_call_session_to_delete(self, db_mock): session = self.mock.MagicMock() db_mock.session = session abstract_model = models.AbstractModel() abstract_model.delete_db() self.assertTrue(session.delete.called)
def test_should_call_session_to_flush_if_commit_is_false(self, db_mock): session = self.mock.MagicMock() db_mock.session = session qm = models.AbstractModel() qm.save_db(commit=False) self.assertTrue(session.flush.called)
def test_should_call_session_to_add(self, db_mock): session = self.mock.MagicMock() db_mock.session = session qm = models.AbstractModel() qm.save_db() self.assertTrue(session.add.called)
def test_should_call_set_values(self, set_values_mock, save_db_mock, db_mock): session = self.mock.MagicMock() db_mock.session = session abstract_model = models.AbstractModel() abstract_model.create_from_dict({'key': 'value'}) self.assertTrue(set_values_mock.called)
def test_should_call_save_db(self, save_db_mock, set_values_mock): instance = self.mock.MagicMock() abstract_model = models.AbstractModel() abstract_model.update_from_dict({'oi': 'oi'}) self.assertTrue(save_db_mock.called)
def test_should_raise_repository_error_if_exception_raised(self): abstract_model = models.AbstractModel() with self.assertRaises(exceptions.RepositoryError): abstract_model.update_from_dict({'key': 'value'})
def setUp(self): self.abstract_model = models.AbstractModel() self.abstract_model.attr1 = '' self.abstract_model.attr2 = ''