示例#1
0
    def update(self, cache=None):
        if cache is None:
            cache = self.cache

        if self.cache:
            update()

        self.__init__(cache=cache)
示例#2
0
文件: fake.py 项目: licheng5625/coder
    def update(self, cache=None):
        if cache is not None:
            self.cache = cache

        if self.cache:
            update()

        self.load()
示例#3
0
文件: fake.py 项目: licheng5625/coder
    def update(self, cache=None):
        if cache is not None:
            self.cache = cache

        if self.cache:
            update()

        self.load()
示例#4
0
    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()
示例#5
0
    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()
示例#6
0
    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()
示例#7
0
    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()
示例#8
0
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
示例#9
0
    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()
示例#10
0
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
示例#11
0
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)
示例#12
0
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)
示例#13
0
def test_update():
    assert not utils.exist()
    utils.update()
    assert utils.exist()
    utils.update()
    assert utils.exist()
示例#14
0
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)
示例#15
0
def test_update():
    assert not utils.exist()
    utils.update()
    assert utils.exist()
    utils.update()
    assert utils.exist()