Skip to content

Commit

Permalink
kind should be optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Link512 committed Dec 4, 2018
1 parent 75cbed7 commit 81c218d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 10 additions & 2 deletions stream/reactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ def add_child(self, kind, parent_id, user_id, data=None, target_feeds=None):
"reaction/", service_name="api", signature=self.token, data=payload
)

def filter(self, kind, **params):
def filter(self, **params):
lookup_field = ""
lookup_value = ""
kind = None

if "kind" in params:
kind = params.pop("kind")

if "reaction_id" in params:
lookup_field = "reaction_id"
Expand All @@ -60,8 +64,12 @@ def filter(self, kind, **params):
lookup_field = "user_id"
lookup_value = params.pop("user_id")

endpoint = "reaction/%s/%s/" % (lookup_field, lookup_value)
if kind is not None:
endpoint = "reaction/%s/%s/%s/" % (lookup_field, lookup_value, kind)

return self.client.get(
"reaction/%s/%s/%s/" % (lookup_field, lookup_value, kind),
endpoint,
service_name="api",
signature=self.token,
params=params,
Expand Down
4 changes: 1 addition & 3 deletions stream/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1243,12 +1243,10 @@ def test_reaction_filter_random(self):
id_lte="54a60c1e-4ee3-494b-a1e3-50c06acb5ed4",
)
self.c.reactions.filter(
kind="dunno",
activity_id="54a60c1e-4ee3-494b-a1e3-50c06acb5ed4",
id_lte="54a60c1e-4ee3-494b-a1e3-50c06acb5ed4",
)
self.c.reactions.filter(
kind="val",
user_id="mike", id_lte="54a60c1e-4ee3-494b-a1e3-50c06acb5ed4"
)

Expand All @@ -1269,7 +1267,7 @@ def test_reaction_filter(self):
response = self.c.reactions.add("comment", activity_id, user)
reaction_comment = self.c.reactions.get(response["id"])

r = self.c.reactions.filter(kind="like", reaction_id=reaction["id"])
r = self.c.reactions.filter(reaction_id=reaction["id"])
self._first_result_should_be(r, child)

r = self.c.reactions.filter(kind="like", activity_id=activity_id, id_lte=reaction["id"])
Expand Down

0 comments on commit 81c218d

Please sign in to comment.