def test_did_validate_event(self): handler = Mock() car_schema.validate = Mock() tracker = self.call_tracker(handler=handler, validate=car_schema.validate) self.Car.on('did_validate', handler) self.car.validate() self.assertEquals([call.validate(self.car), call.handler(self.car)], tracker.mock_calls)
def test_after_validate_middleware(self): middleware = Mock() car_schema.validate = Mock() tracker = self.call_tracker(middleware=middleware, validate=car_schema.validate) self.Car.after_validate(middleware) self.car.validate() self.assertEquals([call.validate(self.car), call.middleware(self.car)], tracker.mock_calls)
def test_service_edit_POST_request_perform_service_check( self, mock_messages): view = setup_view(ServiceEditView(), self.post_request, pk=self.service.pk) view.get_object = lambda: MagicMock(name='service') response = view.post(view.request) view.object.assert_has_calls([call.validate(), call.save()])
def test_service_add_POST_request_perform_service_check(self): view = setup_view(ServiceAddView(), self.get_request) view.object = MagicMock(spec_set=Service) view.object.pk = self.service.pk response = view.get_success_url() calls = [call.validate(), call.save()] view.object.assert_has_calls(calls)
def test_feature_run_order_install(self): """ A feature install should have it's methods run in the proper order """ with patch("sprinter.formula.base.FormulaBase", new=create_mock_formulabase()) as formulabase: with MockEnvironment(test_source, test_target, mock_formulabase=formulabase) as environment: environment.install() eq_( formulabase().method_calls, [call.should_run(), call.validate(), call.resolve(), call.prompt(), call.sync()], )
def test_move_then_validate(self): """Ensures the validate method is called""" mock_holder = MagicMock() self.patch_ctor_methods() mock_holder.attach_mock(self.mock_move, 'move') mock_holder.attach_mock(self.mock_validate, 'validate') self.construct_options() self.schedule_ctor_patch_cleanup() mock_holder.assert_has_calls([call.move(), call.validate()])
def test_feature_run_order_install(self, mock_feature): """ A feature install should have it's methods run in the proper order """ with patch('sprinter.core.featuredict.Feature', new=lambda *args: mock_feature) as mock_call: with MockEnvironment(test_source, test_target) as environment: environment.install() eq_(mock_call().method_calls, [call.should_run(), call.validate(), call.resolve(), call.prompt(), call.sync()])
def test_feature_run_order_deactivate(self): """ A feature deactivate should have it's methods run in the proper order """ with patch("sprinter.formula.base.FormulaBase", new=create_mock_formulabase()) as formulabase: with MockEnvironment(test_source, test_target, mock_formulabase=formulabase) as environment: environment.directory = Mock(spec=environment.directory) environment.directory.new = False environment.deactivate() eq_( formulabase().method_calls, [call.should_run(), call.validate(), call.resolve(), call.prompt(), call.deactivate()], )
def test_service_satus_POST_request_perform_service_check(self): view = setup_view(ServiceStatusView(), self.get_request) service = MagicMock(name='service') view.get_object = MagicMock(name='get_object', return_value=service) try: view.post(self.get_request) except: pass calls = [call.validate(), call.save()] service.assert_has_calls(calls)
def test_feature_run_order_deactivate(self, mock_feature): """ A feature deactivate should have it's methods run in the proper order """ with patch('sprinter.core.featuredict.Feature', new=lambda *args: mock_feature) as mock_call: with MockEnvironment(test_source, test_target) as environment: environment.directory = Mock(spec=environment.directory) environment.directory.new = False environment.deactivate() eq_(mock_call().method_calls, [call.should_run(), call.validate(), call.resolve(), call.prompt(), call.deactivate()])
def test_feature_run_order_install(self): """ A feature install should have it's methods run in the proper order """ with patch('sprinter.formula.base.FormulaBase', new=create_mock_formulabase()) as formulabase: with MockEnvironment(test_source, test_target, mock_formulabase=formulabase) as environment: environment.install() eq_(formulabase().method_calls, [ call.should_run(), call.validate(), call.resolve(), call.prompt(), call.sync() ])
def test_feature_run_order_activate(self): """ A feature should have it's methods run in the proper order """ with patch('sprinter.formula.base.FormulaBase', new=create_mock_formulabase()) as formulabase: with MockEnvironment(test_source, test_target, mock_formulabase=formulabase) as environment: environment.directory = Mock(spec=environment.directory) environment.directory.new = False environment.activate() eq_(formulabase().method_calls, [ call.should_run(), call.validate(), call.resolve(), call.prompt(), call.activate() ])
def test_feature_run_order_install(self): """ A feature install should have it's methods run in the proper order """ environment = create_mock_environment( target_config=test_target ) mock_formulabase = Mock(spec=FormulaBase) mock_formulabase.resolve.return_value = None mock_formulabase.validate.return_value = None mock_formulabase.prompt.return_value = None mock_formulabase.sync.return_value = None environment.formula_dict['sprinter.formulabase'] = Mock(return_value=mock_formulabase) environment.install() tools.eq_(mock_formulabase.method_calls, [call.should_run(), call.validate(), call.resolve(), call.prompt(), call.sync()])
def test_feature_run_order_activate(self): """ A feature should have it's methods run in the proper order """ environment = create_mock_environment( source_config=test_source, installed=True ) mock_formulabase = Mock(spec=FormulaBase) mock_formulabase.resolve.return_value = None mock_formulabase.validate.return_value = None mock_formulabase.prompt.return_value = None mock_formulabase.activate.return_value = None environment.formula_dict['sprinter.formulabase'] = Mock(return_value=mock_formulabase) environment.activate() tools.eq_(mock_formulabase.method_calls, [call.should_run(), call.validate(), call.resolve(), call.prompt(), call.activate()])