def update(self, cache=None): if cache is None: cache = self.cache if self.cache: update() self.__init__(cache=cache)
def update(self, cache=None): if cache is not None: self.cache = cache if self.cache: update() self.load()
def update(self, cache=None): with self.update.lock: if cache is not None: self.cache = cache if self.cache: update(self.path) self.load()
def update(self, cache=None): with self.update.lock: if cache is not None: assert isinstance(cache, bool), \ 'cache must be True or False' self.cache = cache if self.cache: update(self.path) self.load()
def update(self, cache=None): with self.update.lock: if cache is not None: assert isinstance(cache, bool), \ 'cache must be True or False' self.cache = cache if self.cache: update( self.path, use_cache_server=self.use_cache_server, verify_ssl=self.verify_ssl, ) self.load()
def test_utils_update(path): utils.update(path, use_cache_server=False) mtime = os.path.getmtime(path) _load = utils.load with mock.patch( 'fake_useragent.utils.load', side_effect=_load, ) as mocked: utils.update(path, use_cache_server=False) mocked.assert_called() assert os.path.getmtime(path) != mtime
def test_utils_load_no_use_cache_server(path): denied_urls = [ 'https://www.w3schools.com/browsers/browsers_stats.asp', 'http://useragentstring.com/pages/useragentstring.php', ] with mock.patch( 'fake_useragent.utils.Request', side_effect=partial(_request, denied_urls=denied_urls), ): with pytest.raises(errors.FakeUserAgentError): utils.load(use_cache_server=False) with pytest.raises(errors.FakeUserAgentError): utils.load_cached(path, use_cache_server=False) with pytest.raises(errors.FakeUserAgentError): utils.update(path, use_cache_server=False)
def test_update(): assert not utils.exist() utils.update() assert utils.exist() utils.update() assert utils.exist()
def test_update(): assert not utils.exist(settings.DB) utils.update(settings.DB) assert utils.exist(settings.DB) utils.update(settings.DB) assert utils.exist(settings.DB)