diff --git a/stream/feed.py b/stream/feed.py index 5a17340..32040e7 100644 --- a/stream/feed.py +++ b/stream/feed.py @@ -20,7 +20,7 @@ def __init__(self, client, feed_slug, user_id, token): self.slug = feed_slug self.user_id = str(user_id) self.id = "%s:%s" % (feed_slug, user_id) - self.token = token + self.token = token.decode('utf-8') if isinstance(token, bytes) else token self.feed_url = "feed/%s/" % self.id.replace(":", "/") self.enriched_feed_url = "enrich/feed/%s/" % self.id.replace(":", "/") diff --git a/stream/tests/test_client.py b/stream/tests/test_client.py index ae69175..bf0db9b 100644 --- a/stream/tests/test_client.py +++ b/stream/tests/test_client.py @@ -17,6 +17,7 @@ import stream from stream import serializer from stream.exceptions import ApiKeyException, InputException +from stream.feed import Feed try: from unittest.case import TestCase @@ -1702,3 +1703,13 @@ def test_follow_stats(self): )["results"] self.assertEqual(response["following"]["count"], 0) self.assertEqual(response["followers"]["count"], 1) + + def test_token_type(self): + """ + test to check whether token is a byte or string + """ + with_bytes = Feed(client, "user", "1", b"token") + self.assertEqual(with_bytes.token, "token") + + with_str = Feed(client, "user", "1", "token") + self.assertEqual(with_str.token, "token")