Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure error is raised from _ensure_user when the user doesn't exist #628

Merged
merged 1 commit into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions test_twarc2.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,12 @@ def test_list_tweets():
assert len(tweets) >= 90


def test_user_lookup_non_existent():
with pytest.raises(ValueError):
# This user does not exist, and a value error should be raised
T._ensure_user("noasdfasdf")


def test_twarc_metadata():

# With metadata (default)
Expand Down
10 changes: 5 additions & 5 deletions twarc/client2.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
POLL_FIELDS,
PLACE_FIELDS,
LIST_FIELDS,
ensure_flattened,
)
from twarc.decorators2 import *
from twarc.version import version, user_agent
Expand Down Expand Up @@ -1883,11 +1882,12 @@ def _ensure_user(self, user):

lookup = []
if len(user) > 15 or (is_numeric and self._id_exists(user)):
lookup = ensure_flattened(list(self.user_lookup([user])))
lookup = list(self.user_lookup([user]))[0]
else:
lookup = ensure_flattened(list(self.user_lookup([user], usernames=True)))
if lookup:
return lookup[-1]
lookup = list(self.user_lookup([user], usernames=True))[0]

if "data" in lookup:
return lookup["data"][0]
else:
raise ValueError(f"No such user {user}")

Expand Down