Fixed bug 1800761

This commit is contained in:
Bob Luursema 2019-03-05 21:55:37 +01:00
parent 2a6378f489
commit c68d6dc3de
3 changed files with 28 additions and 17 deletions

View File

@ -273,6 +273,13 @@ class SongSelectForm(QtWidgets.QDialog, Ui_SongSelectDialog, RegistryProperties)
'There was a problem logging in, perhaps your username or password is incorrect?')
)
else:
if subscription_level == 'Free':
QtWidgets.QMessageBox.information(
self,
translate('SongsPlugin.SongSelectForm', 'Free user'),
translate('SongsPlugin.SongSelectForm',
'You logged in with a free account, the search will be limited to songs in the public domain.')
)
if self.save_password_checkbox.isChecked():
Settings().setValue(self.plugin.settings_section + '/songselect username', self.username_edit.text())
Settings().setValue(self.plugin.settings_section + '/songselect password', self.password_edit.text())

View File

@ -115,20 +115,31 @@ class SongSelectImport(object):
return False
if callback:
callback()
if posted_page.find('input', id='SearchText') is not None or posted_page.find('div', id="select-organization") is not None:
# Page if user is in an organization
if posted_page.find('input', id='SearchText') is not None:
self.subscription_level = self.find_subscription_level(posted_page)
return self.subscription_level
# Page if user is not in an organization
elif posted_page.find('div', id="select-organization") is not None:
try:
home_page = BeautifulSoup(self.opener.open(BASE_URL).read(), 'lxml')
except (TypeError, URLError) as error:
log.exception('Could not reach SongSelect, {error}'.format(error=error))
subscription_element = home_page.find('div', {'class': 'subscriptionlevel'})
if subscription_element is not None:
self.subscription_level = subscription_element.string.strip()
else:
self.subscription_level = 'premium'
self.subscription_level = self.find_subscription_level(home_page)
return self.subscription_level
else:
log.debug(posted_page)
return None
def find_subscription_level(self, page):
scripts = page.find_all('script')
for tag in scripts:
if tag.string:
match = re.search("'Subscription': '(?P<subscription_level>[^']+)", tag.string)
if match:
return match.group('subscription_level')
log.error('Could not determine SongSelect subscription level')
return 'unkown'
def logout(self):
"""

View File

@ -117,11 +117,7 @@ class TestSongSelectImport(TestCase, TestMixin):
mocked_login_page.find.side_effect = [{'value': 'blah'}, None]
mocked_posted_page = MagicMock()
mocked_posted_page.find.return_value = MagicMock()
mocked_home_page = MagicMock()
mocked_return = MagicMock()
mocked_return.string = 'premium'
mocked_home_page.find.return_value = mocked_return
MockedBeautifulSoup.side_effect = [mocked_login_page, mocked_posted_page, mocked_home_page]
MockedBeautifulSoup.side_effect = [mocked_login_page, mocked_posted_page]
mock_callback = MagicMock()
importer = SongSelectImport(None)
@ -132,8 +128,8 @@ class TestSongSelectImport(TestCase, TestMixin):
assert 3 == mock_callback.call_count, 'callback should have been called 3 times'
assert 2 == mocked_login_page.find.call_count, 'find should have been called twice on the login page'
assert 1 == mocked_posted_page.find.call_count, 'find should have been called once on the posted page'
assert 3 == mocked_opener.open.call_count, 'opener should have been called 3 times'
assert result is 'premium', 'The login method should have returned the subscription level'
assert 2 == mocked_opener.open.call_count, 'opener should have been called twice'
assert result is 'unkown', 'The login method should have returned the subscription level'
@patch('openlp.plugins.songs.lib.songselect.build_opener')
@patch('openlp.plugins.songs.lib.songselect.BeautifulSoup')
@ -151,9 +147,6 @@ class TestSongSelectImport(TestCase, TestMixin):
mocked_posted_page = MagicMock()
mocked_posted_page.find.return_value = MagicMock()
mocked_home_page = MagicMock()
mocked_return = MagicMock()
mocked_return.string = 'premium'
mocked_home_page.find.return_value = mocked_return
MockedBeautifulSoup.side_effect = [mocked_login_page, mocked_posted_page, mocked_home_page]
mock_callback = MagicMock()
importer = SongSelectImport(None)
@ -166,7 +159,7 @@ class TestSongSelectImport(TestCase, TestMixin):
assert 2 == mocked_login_page.find.call_count, 'find should have been called twice on the login page'
assert 1 == mocked_posted_page.find.call_count, 'find should have been called once on the posted page'
assert 'https://profile.ccli.com/do/login', mocked_opener.open.call_args_list[1][0][0]
assert result is 'premium', 'The login method should have returned the subscription level'
assert result is 'unkown', 'The login method should have returned the subscription level'
@patch('openlp.plugins.songs.lib.songselect.build_opener')
def test_logout(self, mocked_build_opener):