Skip to content

Commit

Permalink
Merge pull request #8 from GiedriusS/infinite_loop
Browse files Browse the repository at this point in the history
libtn: add workaround for broken pagination
  • Loading branch information
GiedriusS authored Oct 13, 2020
2 parents a26a30c + 797e177 commit 5d04d04
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 12 deletions.
7 changes: 6 additions & 1 deletion libtn.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,12 @@ def get_status(self):

while True:
fol = self.get_followed_channels({'offset': offset,
'limit': LIMIT})
'limit': LIMIT,
# Workaround for
# https://github.com/twitchdev/issues/issues/237.
# Doesn't really matter in our
# case.
'sortby': 'last_broadcast'})
for chan in fol:
followed_chans.append(chan)

Expand Down
86 changes: 75 additions & 11 deletions test_libtn.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,93 @@ class LibTest(unittest.TestCase):
def test_get_followed_channels(self):
api = libtn.NotifyApi('test_account123322', None, None, False)

list_of_chans = api.get_followed_channels({'offset': 0, 'limit': 1})
list_of_chans = api.get_followed_channels({'offset': 0,
'limit': 1,
# Workaround for
# https://github.com/twitchdev/issues/issues/237.
# Doesn't really matter in our
# case. Without this, `offset'
# does not work.
'sortby': 'last_broadcast'
})
self.assertEqual(len(list_of_chans), 1)
self.assertEqual(list_of_chans[0], 'xangold')

list_of_chans = api.get_followed_channels({'offset': 1, 'limit': 1})
self.assertEqual(list_of_chans[0], 'grossie_gore')

list_of_chans = api.get_followed_channels({'offset': 1,
'limit': 1,
# Workaround for
# https://github.com/twitchdev/issues/issues/237.
# Doesn't really matter in our
# case. Without this, `offset'
# does not work.
'sortby': 'last_broadcast'
})
self.assertEqual(len(list_of_chans), 0)

list_of_chans = api.get_followed_channels({'offset': 0, 'limit': 100})
self.assertEqual(list_of_chans[0], 'xangold')
list_of_chans = api.get_followed_channels({'offset': 0,
'limit': 100,
# Workaround for
# https://github.com/twitchdev/issues/issues/237.
# Doesn't really matter in our
# case. Without this, `offset'
# does not work.
'sortby': 'last_broadcast'
})
self.assertEqual(list_of_chans[0], 'grossie_gore')
self.assertEqual(len(list_of_chans), 1)

list_of_chans = api.get_followed_channels({'offset': 1, 'limit': 100})
list_of_chans = api.get_followed_channels({'offset': 1,
'limit': 100,
# Workaround for
# https://github.com/twitchdev/issues/issues/237.
# Doesn't really matter in our
# case. Without this, `offset'
# does not work.
'sortby': 'last_broadcast'
})
self.assertEqual(len(list_of_chans), 0)

api = libtn.NotifyApi('test_account5555666', None, None, False)
list_of_chans = api.get_followed_channels({'offset': 0, 'limit': 1})
list_of_chans = api.get_followed_channels({'offset': 0,
'limit': 1,
# Workaround for
# https://github.com/twitchdev/issues/issues/237.
# Doesn't really matter in our
# case. Without this, `offset'
# does not work.
'sortby': 'last_broadcast'
})
self.assertEqual(len(list_of_chans), 0)
list_of_chans = api.get_followed_channels({'offset': 1, 'limit': 1})
list_of_chans = api.get_followed_channels({'offset': 1,
'limit': 1,
# Workaround for
# https://github.com/twitchdev/issues/issues/237.
# Doesn't really matter in our
# case. Without this, `offset'
# does not work.
'sortby': 'last_broadcast'
})
self.assertEqual(len(list_of_chans), 0)

api = libtn.NotifyApi('metasigma', None, None, False)
list_of_chans = api.get_followed_channels({'offset': 0, 'limit': 100})
list_of_chans2 = api.get_followed_channels({'offset': 100, 'limit': 100})
list_of_chans = api.get_followed_channels({'offset': 0,
'limit': 100,
# Workaround for
# https://github.com/twitchdev/issues/issues/237.
# Doesn't really matter in our
# case. Without this, `offset'
# does not work.
'sortby': 'last_broadcast'
})
list_of_chans2 = api.get_followed_channels({'offset': 100,
'limit': 100,
# Workaround for
# https://github.com/twitchdev/issues/issues/237.
# Doesn't really matter in our
# case. Without this, `offset'
# does not work.
'sortby': 'last_broadcast'
})
self.assertEqual(len(list_of_chans)+len(list_of_chans2) > 100, True)

def test_check_if_online(self):
Expand Down

0 comments on commit 5d04d04

Please sign in to comment.