def setUp(self): self.tracker = DummyRequisitionTracker()
class TestDummyRequisitionTracker(TestCase): def setUp(self): self.tracker = DummyRequisitionTracker() def test_receive(self): """ Check if calling receive() without apply_fixtures raises DataBaseError. """ with self.assertRaises(sqlite3.OperationalError): self.tracker.receive() def test_done(self): """Check if calling done() without apply_fixtures raises ValueError.""" with self.assertRaises(DataBaseError): self.tracker.done(TEST_REQUISITION) def test_receive_with_fixtures(self): """ Test receive Requisition instances from tracker. Receive from DummyRequisitionTracker applying fixtures. """ self.tracker.testing_apply_fixtures() self.assertEqual(self.tracker.receive()[0].as_dict(), TEST_REQUISITION.as_dict()) def test_done_with_fixtures(self): """ Test removing Requisition instances from tracker. Remove from DummyRequisitionTracker applying fixtures. """ self.tracker.testing_apply_fixtures() self.tracker.done(TEST_REQUISITION) dummy_requisitions = [item.as_dict() for item in self.tracker.receive()] self.assertNotIn(TEST_REQUISITION.as_dict(), dummy_requisitions) def test_done_by_id(self): """ Test removing Requisition instances by candidate_id. Remove from DummyRequisitionTracker applying fixtures. """ self.tracker.testing_apply_fixtures() done_response = self.tracker.done_by_id( TEST_REQUISITION.as_dict()['candidate_id'] ) dummy_requisitions = [item.as_dict() for item in self.tracker.receive()] self.assertEquals(done_response, True) self.assertNotIn(TEST_REQUISITION.as_dict(), dummy_requisitions) def test_done_by_invalid_id(self): """ Test removing Requisition instances by invalid candidate_id. Remove from DummyRequisitionTracker applying fixtures. """ self.tracker.testing_apply_fixtures() done_response = self.tracker.done_by_id('abcde') dummy_requisitions = [item.as_dict() for item in self.tracker.receive()] self.assertEquals(done_response, False) self.assertIn(TEST_REQUISITION.as_dict(), dummy_requisitions)