def test_no_handle_when_modfreq_once(self): """C{handle_part} is not called if frequency is once.""" self.frequency = "once" mod_mock = mock.Mock(frequency=settings.PER_ONCE) handlers.run_part(mod_mock, self.data, self.filename, self.payload, self.frequency, self.headers) self.assertEqual(0, mod_mock.handle_part.call_count)
def test_no_handle_when_modfreq_once(self): """C{handle_part} is not called if frequency is once.""" self.frequency = "once" mod_mock = self.mocker.mock() getattr(mod_mock, "frequency") self.mocker.result(settings.PER_ONCE) self.mocker.replay() handlers.run_part(mod_mock, self.data, self.filename, self.payload, self.frequency, self.headers)
def test_normal_version_1(self): """ C{handle_part} is called without C{frequency} for C{handler_version} == 1. """ mod_mock = mock.Mock(frequency=settings.PER_INSTANCE, handler_version=1) handlers.run_part(mod_mock, self.data, self.filename, self.payload, self.frequency, self.headers) # Assert that the handle_part() method of the mock object got # called with the expected arguments. mod_mock.handle_part.assert_called_once_with(self.data, self.ctype, self.filename, self.payload)
def test_exception_is_caught(self): """Exceptions within C{handle_part} are caught and logged.""" mod_mock = mock.Mock(frequency=settings.PER_INSTANCE, handler_version=1) mod_mock.handle_part.side_effect = Exception try: handlers.run_part(mod_mock, self.data, self.filename, self.payload, self.frequency, self.headers) except Exception: self.fail("Exception was not caught in handle_part") mod_mock.handle_part.assert_called_once_with(self.data, self.ctype, self.filename, self.payload)
def test_modfreq_per_always(self): """ C{handle_part} is called regardless of frequency if nofreq is always. """ self.frequency = "once" mod_mock = mock.Mock(frequency=settings.PER_ALWAYS, handler_version=1) handlers.run_part(mod_mock, self.data, self.filename, self.payload, self.frequency, self.headers) # Assert that the handle_part() method of the mock object got # called with the expected arguments. mod_mock.handle_part.assert_called_once_with(self.data, self.ctype, self.filename, self.payload)
def test_no_handle_when_modfreq_once(self): """C{handle_part} is not called if frequency is once.""" self.frequency = "once" mod_mock = mock.Mock(frequency=settings.PER_ONCE) handlers.run_part(mod_mock, self.data, self.filename, self.payload, self.frequency, self.headers) # Assert that the handle_part() method of the mock object got # called with the expected arguments. mod_mock.handle_part.assert_called_with_once( self.data, self.ctype, self.filename, self.payload)
def test_exception_is_caught(self): """Exceptions within C{handle_part} are caught and logged.""" mod_mock = self.mocker.mock() getattr(mod_mock, "frequency") self.mocker.result(settings.PER_INSTANCE) getattr(mod_mock, "handler_version") self.mocker.result(1) mod_mock.handle_part(self.data, self.ctype, self.filename, self.payload) self.mocker.throw(Exception()) self.mocker.replay() handlers.run_part(mod_mock, self.data, self.filename, self.payload, self.frequency, self.headers)
def test_normal_version_1(self): """ C{handle_part} is called without C{frequency} for C{handler_version} == 1. """ mod_mock = self.mocker.mock() getattr(mod_mock, "frequency") self.mocker.result(settings.PER_INSTANCE) getattr(mod_mock, "handler_version") self.mocker.result(1) mod_mock.handle_part(self.data, self.ctype, self.filename, self.payload) self.mocker.replay() handlers.run_part(mod_mock, self.data, self.filename, self.payload, self.frequency, self.headers)
def test_modfreq_per_always(self): """ C{handle_part} is called regardless of frequency if nofreq is always. """ self.frequency = "once" mod_mock = self.mocker.mock() getattr(mod_mock, "frequency") self.mocker.result(settings.PER_ALWAYS) getattr(mod_mock, "handler_version") self.mocker.result(1) mod_mock.handle_part(self.data, self.ctype, self.filename, self.payload) self.mocker.replay() handlers.run_part(mod_mock, self.data, self.filename, self.payload, self.frequency, self.headers)
def test_modfreq_per_always(self): """ C{handle_part} is called regardless of frequency if nofreq is always. """ self.frequency = "once" mod_mock = mock.Mock(frequency=settings.PER_ALWAYS, handler_version=1) handlers.run_part( mod_mock, self.data, self.filename, self.payload, self.frequency, self.headers, ) # Assert that the handle_part() method of the mock object got # called with the expected arguments. mod_mock.handle_part.assert_called_once_with( self.data, self.ctype, self.filename, self.payload )
def test_exception_is_caught(self): """Exceptions within C{handle_part} are caught and logged.""" mod_mock = mock.Mock( frequency=settings.PER_INSTANCE, handler_version=1 ) mod_mock.handle_part.side_effect = Exception try: handlers.run_part( mod_mock, self.data, self.filename, self.payload, self.frequency, self.headers, ) except Exception: self.fail("Exception was not caught in handle_part") mod_mock.handle_part.assert_called_once_with( self.data, self.ctype, self.filename, self.payload )
def test_normal_version_1(self): """ C{handle_part} is called without C{frequency} for C{handler_version} == 1. """ mod_mock = mock.Mock( frequency=settings.PER_INSTANCE, handler_version=1 ) handlers.run_part( mod_mock, self.data, self.filename, self.payload, self.frequency, self.headers, ) # Assert that the handle_part() method of the mock object got # called with the expected arguments. mod_mock.handle_part.assert_called_once_with( self.data, self.ctype, self.filename, self.payload )