def test_get_endorsed_from_dump(self, mock_dump): # my_nation and my_region expects canonicalized input obj = data.Data(mock.Mock(), mock.Mock(), '', 'my_region', 'my_nation') obj.get_endorsed_from_dump(mock_dump) assert obj.endorsed == {'nation_1', 'nation_2'}
def test_endorseable_iterator_empty_endoresable(self): obj = data.Data(mock.Mock(), mock.Mock(), '', '', '') obj.endorseable = [] iterator = obj.get_endorseable_iter() with pytest.raises(StopIteration): next(iterator)
def test_get_endorsed_nations_up_to_date_cache(self, mock_dump_file, setup_mock_cache, remove_mock_cache): cache = data.Cache('cache.json', '12:00:00') obj = data.Data(mock.Mock(), cache, 'dump.xml.gz', 'my_region', 'my_nation') obj.get_endorsed_nations() assert obj.endorsed == {'nation_3', 'nation_4'}
def test_get_endorsed_nations_not_yet_exist_cache(self, mock_dump_file, remove_mock_cache): cache = data.Cache('cache.json', '13:00:00') obj = data.Data(mock.Mock(), cache, 'dump.xml.gz', 'my_region', 'my_nation') obj.get_endorsed_nations() assert obj.endorsed == {'nation_1', 'nation_2'} assert os.path.exists('cache.json')
def test_endorseable_iterator(self): obj = data.Data(mock.Mock(), mock.Mock(), '', '', '') obj.endorseable = ['nation_1', 'nation_2', 'nation_3'] iterator = obj.get_endorseable_iter() first_result = next(iterator) next(iterator) assert first_result == 'nation_1' assert obj.endorseable == ['nation_2', 'nation_3'] assert 'nation_1' in obj.endorsed
def test_gen_endorseable(self): get_wa_members = mock.Mock( return_value={'nation1', 'nation2', 'nation3', 'nation4'}) get_region_members = mock.Mock( return_value={'nation1', 'nation2', 'nation3', 'nation5'}) mock_api = mock.Mock(get_wa_members=get_wa_members, get_region_members=get_region_members) obj = data.Data(mock_api, mock.Mock(), '', '', '') obj.endorsed = {'nation1'} obj.gen_endorseable() assert all(nation in ['nation2', 'nation3'] for nation in obj.endorseable)
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