Skip to content

Commit

Permalink
Merge pull request #628 from DocNow/fix_626
Browse files Browse the repository at this point in the history
Ensure error is raised from _ensure_user when the user doesn't exist
  • Loading branch information
igorbrigadir committed Apr 20, 2022
2 parents 52f72a9 + b62c47e commit 68210a8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
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

0 comments on commit 68210a8

Please sign in to comment.