def test_create_or_edit_dispatch_with_fail_to_get_text(self, caplog): mock_obj = mock.Mock() ins = updater.DispatchUpdater(mock_obj, mock_obj, mock_obj, mock_obj) ins.edit_dispatch = mock.Mock() ins.get_dispatch_text = mock.Mock(side_effect=exceptions.DispatchRenderingError) this_dispatch_config = {'title': 'test_title', 'category': '1', 'subcategory': '100', 'ns_id': '12345'} ins.create_or_edit_dispatch('test_name', 'edit', this_dispatch_config)
def test_update_dispatch_with_remove_action(self): mock_obj = mock.Mock() ins = updater.DispatchUpdater(mock_obj, mock_obj, mock_obj, mock_obj) ins.dispatch_config = {'test_name': {'title': 'test_title', 'category': '1', 'subcategory': '100', 'ns_id': '12345', 'action': 'remove'}} ins.remove_dispatch = mock.Mock() ins.update_dispatch('test_name') ins.remove_dispatch.assert_called_with('12345')
def test_create_dispatch(self): create_dispatch = mock.Mock(return_value='12345') dispatch_api = mock.Mock(create_dispatch=create_dispatch) dispatch_loader = mock.Mock(add_dispatch_id=mock.Mock()) mock_obj = mock.Mock() ins = updater.DispatchUpdater(dispatch_api, mock_obj, mock_obj, dispatch_loader) params = {'title': 'test_title', 'text': 'test_text', 'category': '1', 'subcategory': '100'} ins.create_dispatch('test_name', params) dispatch_loader.add_dispatch_id.assert_called_with('test_name', '12345')
def test_login_owner_nations(self): login = mock.Mock() dispatch_api = mock.Mock(login=login) creds = {'test_nation': '12345'} mock_obj = mock.Mock() ins = updater.DispatchUpdater(dispatch_api, creds, mock_obj, mock_obj) dispatch_config = {'test_name': {'title': 'test_title', 'category': '1', 'subcategory': '100', 'ns_id': '12345', 'action': 'remove'}} ins.login_owner_nation('test_nation', dispatch_config) login.assert_called_with('test_nation', autologin='******') assert ins.dispatch_config == dispatch_config
def test_create_or_edit_dispatch_with_edit_action(self): mock_obj = mock.Mock() ins = updater.DispatchUpdater(mock_obj, mock_obj, mock_obj, mock_obj) ins.edit_dispatch = mock.Mock() ins.get_dispatch_text = mock.Mock(return_value='test_text') this_dispatch_config = {'title': 'test_title', 'category': '1', 'subcategory': '100', 'ns_id': '12345'} ins.create_or_edit_dispatch('test_name', 'edit', this_dispatch_config) ins.edit_dispatch.assert_called_with('12345', {'title': 'test_title', 'text': 'test_text', 'category': '1', 'subcategory': '100'})
def __init__(self, config): ns_api = nationstates.Nationstates(user_agent=config['general']['user_agent']) dispatch_api = api_adapter.DispatchAPI(ns_api) plugin_options = config['plugins'] loader_config = config['loader_config'] self.dispatch_loader = loader.DispatchLoader(plugin_options['dispatch_loader'], loader_config) self.var_loader = loader.VarLoader(plugin_options['var_loader'], loader_config) self.dispatch_config = None bb_config = config['bbcode'] template_config= config['template_renderer'] self.renderer = renderer.DispatchRenderer(self.dispatch_loader, self.var_loader, bb_config, template_config) self.cred_loader = loader.CredLoader(plugin_options['cred_loader'], loader_config) self.creds = utils.CredManager(self.cred_loader, dispatch_api) self.updater = updater.DispatchUpdater(dispatch_api, self.creds, self.renderer, self.dispatch_loader)