Skip to content

Commit

Permalink
Update requirements fake useragent (#183)
Browse files Browse the repository at this point in the history
* Update requirements

* Change bigger to bigger or equal then

* Disable QA on those lines
  • Loading branch information
melroy89 committed Aug 2, 2023
1 parent bc0710e commit 3d9d8f4
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 45 deletions.
50 changes: 25 additions & 25 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
attrs==22.2.0
black==23.1.0
attrs==23.1.0
black==23.7.0
build==0.10.0
cachetools==5.3.0
chardet==5.1.0
click==8.1.3
cachetools==5.3.1
chardet==5.2.0
click==8.1.6
colorama==0.4.6
coverage==7.2.1
distlib==0.3.6
exceptiongroup==1.1.0
fastjsonschema==2.16.3
filelock==3.9.0
importlib-metadata==6.0.0
importlib-resources==5.12.0
coverage==7.2.7
distlib==0.3.7
exceptiongroup==1.1.2
fastjsonschema==2.18.0
filelock==3.12.2
importlib-metadata==6.8.0
importlib-resources==6.0.0
iniconfig==2.0.0
isort==5.12.0
mypy-extensions==1.0.0
packaging==23.0
pathspec==0.11.0
packaging==23.1
pathspec==0.11.2
pep517==0.13.0
platformdirs==3.1.0
pluggy==1.0.0
platformdirs==3.10.0
pluggy==1.2.0
py==1.11.0
pyparsing==3.0.9
pyproject_api==1.5.0
pyparsing==3.1.1
pyproject_api==1.5.3
pyproject_hooks==1.0.0
pytest==7.2.2
pytest-cov==4.0.0
ruff==0.0.257
pytest==7.4.0
pytest-cov==4.1.0
ruff==0.0.282
six==1.16.0
tomli==2.0.1
tox==4.4.6
validate-pyproject==0.12.1
virtualenv==20.20.0
zipp==3.15.0
tox==4.6.4
validate-pyproject==0.13
virtualenv==20.24.2
zipp==3.16.2
6 changes: 3 additions & 3 deletions src/fake_useragent/fake.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def __getattr__(self, attr):
filter(
lambda x: x["browser"] in self.browsers
and x["os"] in self.os
and x["percent"] > self.min_percentage,
and x["percent"] >= self.min_percentage,
self.data_browsers,
)
)
Expand All @@ -91,14 +91,14 @@ def __getattr__(self, attr):
filter(
lambda x: x["browser"] == attr
and x["os"] in self.os
and x["percent"] > self.min_percentage,
and x["percent"] >= self.min_percentage,
self.data_browsers,
)
)

# Pick a random browser user-agent from the filtered browsers
# And return the useragent string.
return random.choice(filtered_browsers).get("useragent")
return random.choice(filtered_browsers).get("useragent") # noqa: S311
except (KeyError, IndexError):
if self.fallback is None:
raise FakeUserAgentError(
Expand Down
30 changes: 13 additions & 17 deletions tests/test_fake.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,6 @@ def setUp(self):
def tearDown(self):
pass

def _probe(self, ua):
ua.edge
ua.google
ua.chrome
ua.googlechrome
ua.google_chrome
ua["google chrome"]
ua.firefox
ua.ff
ua.safari
ua.random
ua["random"]

def test_fake_init(self):
ua = UserAgent()

Expand All @@ -41,10 +28,19 @@ def test_fake_init(self):
self.assertTrue(ua.random)
self.assertIsInstance(ua.random, str)

def test_fake_user_agent_browsers(self):
def test_fake_probe_user_agent_browsers(self):
ua = UserAgent()

self._probe(ua)
ua.edge # noqa: B018
ua.google # noqa: B018
ua.chrome # noqa: B018
ua.googlechrome # noqa: B018
ua.google_chrome # noqa: B018
ua["google chrome"] # noqa: B018
ua.firefox # noqa: B018
ua.ff # noqa: B018
ua.safari # noqa: B018
ua.random # noqa: B018
ua["random"] # noqa: B018

def test_fake_data_browser_type(self):
ua = UserAgent()
Expand Down Expand Up @@ -84,7 +80,7 @@ def test_fake_safe_attrs(self):
ua = UserAgent(safe_attrs=("__injections__",))

with pytest.raises(AttributeError):
ua.__injections__
ua.__injections__ # noqa: B018

def test_fake_version(self):
assert VERSION == settings.__version__
Expand Down

0 comments on commit 3d9d8f4

Please sign in to comment.