Exemplo n.º 1
0
    def test_load(self, setup_cache_file, remove_cache_file):
        obj = data.Cache('cache.json', '00:00:00')

        is_exist = obj.load()

        assert obj == {'key1': ['data1', 'data2']}
        assert is_exist
Exemplo n.º 2
0
    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'}
Exemplo n.º 3
0
    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')
Exemplo n.º 4
0
    def test_save(self, remove_cache_file):
        obj = data.Cache('cache.json', '00:00:00')
        obj['key1'] = ['data1', 'data2']

        obj.save()

        with open('cache.json') as f:
            result = json.load(f)

        assert result == {'created_time': 1, 'key1': ['data1', 'data2']}
Exemplo n.º 5
0
    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
Exemplo n.º 6
0
    def test_is_update(self):
        obj = data.Cache('', '12:00:00')
        obj.created_day = datetime.date.fromisoformat('1970-01-01')

        assert obj.is_updated