def test_login_forbidden_exception(self): mock_nation = mock.Mock(get_shards=mock.Mock( side_effect=nationstates.exceptions.Forbidden)) mock_api = mock.Mock(nation=mock.Mock(return_value=mock_nation)) ns_api = api_adapter.NS_API(mock_api, 'my_nation') with pytest.raises(exceptions.AuthError): ns_api.login('hunterprime123') == '12345678'
def test_login(self): mock_nation = mock.Mock(get_shards=mock.Mock( return_value={'headers': { 'X-Pin': '12345678' }})) mock_api = mock.Mock(nation=mock.Mock(return_value=mock_nation)) ns_api = api_adapter.NS_API(mock_api, 'my_nation') assert ns_api.login('hunterprime123') == '12345678' assert mock_nation.get_shards.called_with('my_nation', 'hunterprime123')
def test_get_region_members(self): mock_nations = [ mock.Mock(nation_name='testnation1'), mock.Mock(nation_name='testnation2') ] mock_region = mock.Mock(nations=mock_nations) mock_nation = mock.Mock(region=mock_region) mock_api = mock.Mock(nation=mock.Mock(return_value=mock_nation)) ns_api = api_adapter.NS_API(mock_api, 'my_nation') assert ns_api.get_region_members() == {'testnation1', 'testnation2'} assert mock_api.nation.called_with('my_nation')
def __init__(self, config): conf = config['General'] my_nation = utils.canonical(conf['my_nation']) self.password = conf['password'] user_agent = conf['user_agent'] if user_agent == '': raise exceptions.UserError('You need to set the user agent!') ns_api = nationstates.Nationstates(user_agent=user_agent) ns_api = api_adapter.NS_API(ns_api, my_nation) ns_site = executor.NSSite(user_agent) self.executor = executor.EndorseExecutor(ns_api, ns_site) cache_conf = config['Cache'] cache = data.Cache(info.CACHE_PATH, cache_conf['daily_dump_update_time']) self.ns_data = data.Data(ns_api, cache, info.DATA_DUMP_PATH, conf['my_region'], my_nation, cache_conf['update_from_dump']) self.endorseable_iter = None
def test_get_wa_members(self): mock_wa = mock.Mock(members='testnation1;testnation2') mock_api = mock.Mock(wa=mock.Mock(return_value=mock_wa)) ns_api = api_adapter.NS_API(mock_api, '') assert ns_api.get_wa_members() == {'testnation1', 'testnation2'}