Skip to content

Commit

Permalink
Fix favorite tests (#932)
Browse files Browse the repository at this point in the history
  • Loading branch information
mediaminister authored Jan 23, 2022
1 parent e4c4096 commit f14c0fd
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion resources/lib/favorites.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def update(self, program_name, title, program_id, is_favorite=True):
return True

# Lookup program_id
if program_id == 'None':
if program_id == 'None' or program_id is None:
program_id = self.get_program_id_graphql(program_name)

# Update local favorites cache
Expand Down
8 changes: 3 additions & 5 deletions resources/lib/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
from data import CHANNELS, SECONDS_MARGIN
from kodiutils import colour, get_setting_bool, localize, localize_datelong, log, url_for
from utils import (add_https_proto, capitalize, find_entry, from_unicode,
html_to_kodi, reformat_url, reformat_image_url, shorten_link, to_unicode, unescape,
url_to_episode)
html_to_kodi, reformat_url, reformat_image_url, shorten_link, to_unicode, unescape)


class Metadata:
Expand Down Expand Up @@ -74,7 +73,6 @@ def get_context_menu(self, api_data, program_name, cache_file):
if episode_id is not None:
# We need to ensure forward slashes are quoted
title = to_unicode(quote_plus(from_unicode(title)))
url = url_to_episode(api_data.get('url', ''))
if self._resumepoints.is_watchlater(episode_id):
extras = {}
# If we are in a watchlater menu, move cursor down before removing a favorite
Expand All @@ -83,14 +81,14 @@ def get_context_menu(self, api_data, program_name, cache_file):
# Unwatch context menu
context_menu.append((
capitalize(localize(30402)),
'RunPlugin(%s)' % url_for('unwatchlater', episode_id=episode_id, title=title, url=url, **extras)
'RunPlugin(%s)' % url_for('unwatchlater', episode_id=episode_id, title=title, **extras)
))
watchlater_marker = '[COLOR={highlighted}]ᶫ[/COLOR]'
else:
# Watch context menu
context_menu.append((
capitalize(localize(30401)),
'RunPlugin(%s)' % url_for('watchlater', episode_id=episode_id, title=title, url=url)
'RunPlugin(%s)' % url_for('watchlater', episode_id=episode_id, title=title)
))

# FOLLOW PROGRAM
Expand Down
22 changes: 15 additions & 7 deletions resources/lib/resumepoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

try: # Python 3
from urllib.error import HTTPError
from urllib.parse import urlencode
except ImportError: # Python 2
from urllib import urlencode
from urllib2 import HTTPError

from data import SECONDS_MARGIN
Expand Down Expand Up @@ -229,8 +231,13 @@ def get_watchlater(self):
'Authorization': 'Bearer ' + vrtlogin_at,
'Accept': 'application/json',
}
querystring = 'tileType=mixed-content&tileContentType=episode&tileOrientation=landscape&layout=slider&title=Later+kijken'
watchlater_json = get_url_json(url='{}?{}'.format(self.WATCHLATER_REST_URL, querystring), cache=None, headers=headers, raise_errors='all')
payload = dict(
tileType='mixed-content',
tileContentType='episode',
tileOrientation='landscape',
layout='slider',
title='Later kijken')
watchlater_json = get_url_json(url='{}?{}'.format(self.WATCHLATER_REST_URL, urlencode(payload)), cache=None, headers=headers, raise_errors='all')
return watchlater_json

def set_watchlater_graphql(self, episode_id, title, watch_later=True):
Expand Down Expand Up @@ -270,11 +277,12 @@ def set_watchlater_graphql(self, episode_id, title, watch_later=True):
def _generate_watchlater_dict(watchlater_json):
"""Generate a simple watchlater dict with episodeIds and episodeTitles"""
watchlater_dict = {}
for item in watchlater_json.get(':items', []):
episode_id = watchlater_json.get(':items')[item].get('data').get('episode').get('id')
title = watchlater_json.get(':items')[item].get('description')
watchlater_dict[episode_id] = dict(
title=title)
if watchlater_json is not None:
for item in watchlater_json.get(':items', []):
episode_id = watchlater_json.get(':items')[item].get('data').get('episode').get('id')
title = watchlater_json.get(':items')[item].get('description')
watchlater_dict[episode_id] = dict(
title=title)
return watchlater_dict

def is_watchlater(self, episode_id):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_apihelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class TestApiHelper(unittest.TestCase):
def test_get_api_data_single_season(self):
"""Test listing episodes for a single season (het-journaal)"""
title_items, sort, ascending, content = self._apihelper.list_episodes(program='het-journaal', season='allseasons')
self.assertTrue(100 <= len(title_items) <= 140, 'We got %s items instead.' % len(title_items))
self.assertTrue(90 <= len(title_items) <= 140, 'We got %s items instead.' % len(title_items))
self.assertEqual(sort, 'dateadded')
self.assertFalse(ascending)
self.assertEqual(content, 'episodes')
Expand Down
5 changes: 2 additions & 3 deletions tests/test_favorites.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ def test_follow_unfollow(self):
"""Test following and unfollowing programs"""
programs = [
{'program_title': 'Winteruur', 'program_name': 'winteruur'},
{'program_title': 'De Campus Cup', 'program_name': 'de-campus-cup'},
{'program_title': 'Terug naar Siberië', 'program_name': 'terug-naar-siberie'},
{'program_title': 'Belle & Sebastian', 'program_name': 'belle---sebastian'},
{'program_title': 'Thuis', 'program_name': 'thuis'},
{'program_title': '#LikeMe', 'program_name': '-likeme'},
]
for program_item in programs:
program_title = program_item.get('program_title')
Expand Down

0 comments on commit f14c0fd

Please sign in to comment.