def test_utils_rm(path): assert not os.path.isfile(path) with io.open(path, mode='wb') as fp: fp.write(b'\n') assert os.path.isfile(path) utils.rm(path) assert not os.path.isfile(path)
def test_cache_server(): clear() fallback = 'Foo Browser' settings.BROWSER_BASE_PAGE = 'http://example.com/' settings.BROWSERS_STATS_PAGE = 'http://example.com/' ua = UserAgent(fallback=fallback) assert ua.random != fallback assert ua.ie != fallback utils.rm(settings.DB)
def test_custom_path(): location = os.path.join( tempfile.gettempdir(), 'fake_useragent' + uuid.uuid1().hex + '.json', ) ua = UserAgent(path=location) assert utils.exist(location) check_dict(ua.data) mtime = os.path.getmtime(location) ua.update() assert os.path.getmtime(location) != mtime utils.rm(location)
def test_rm(): assert utils.exist() utils.rm() assert not utils.exist()
def test_user_agent(): clear() assert not utils.exist(settings.DB) ua = UserAgent(cache=False) assert ua.ie is not None assert ua.msie is not None assert ua.internetexplorer is not None assert ua.internet_explorer is not None assert ua['internet explorer'] is not None assert ua.google is not None assert ua.chrome is not None assert ua.googlechrome is not None assert ua.google_chrome is not None assert ua['google chrome'] is not None assert ua.firefox is not None assert ua.ff is not None assert ua.ie is not None assert ua.safari is not None assert ua.random is not None assert ua['random'] is not None try: assert ua.non_existing is None except FakeUserAgentError: pass else: assert False try: assert ua['non_existing'] except FakeUserAgentError: pass else: assert False data1 = ua.data ua.update(settings.DB) data2 = ua.data assert data1 == data2 assert data1 is not data2 clear() del ua ua = UserAgent() assert utils.exist(settings.DB) data1 = ua.data clear() ua.update(settings.DB) assert utils.exist(settings.DB) data2 = ua.data assert data1 == data2 assert data1 is not data2 utils.rm(settings.DB)
def test_rm(): assert utils.exist(settings.DB) utils.rm(settings.DB) assert not utils.exist(settings.DB)