Merge pull request #269 from pylast/fix-ci

Fix some tests and code to make tests pass
This commit is contained in:
Hugo 2018-05-27 20:44:26 +03:00 committed by GitHub
commit c8d349cfb6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 13 deletions

View file

@ -833,7 +833,7 @@ class _Request(object):
'User-Agent': "pylast" + '/' + __version__
}
(HOST_NAME, HOST_SUBDIR) = self.network.ws_server
(host_name, host_subdir) = self.network.ws_server
if self.network.is_proxy_enabled():
conn = HTTPSConnection(
@ -843,17 +843,17 @@ class _Request(object):
try:
conn.request(
method='POST', url="https://" + HOST_NAME + HOST_SUBDIR,
method='POST', url="https://" + host_name + host_subdir,
body=data, headers=headers)
except Exception as e:
raise NetworkError(self.network, e)
else:
conn = HTTPSConnection(context=SSL_CONTEXT, host=HOST_NAME)
conn = HTTPSConnection(context=SSL_CONTEXT, host=host_name)
try:
conn.request(
method='POST', url=HOST_SUBDIR, body=data, headers=headers)
method='POST', url=host_subdir, body=data, headers=headers)
except Exception as e:
raise NetworkError(self.network, e)
@ -889,6 +889,7 @@ class _Request(object):
raise MalformedResponseError(self.network, e)
e = doc.getElementsByTagName('lfm')[0]
# logger.debug(doc.toprettyxml())
if e.getAttribute('status') != "ok":
e = doc.getElementsByTagName('error')[0]
@ -2300,7 +2301,7 @@ class User(_BaseObject, _Chartable):
country = _extract(doc, "country")
if country is None:
if country is None or country == "None":
return None
else:
return Country(country, self.network)
@ -2496,17 +2497,13 @@ class User(_BaseObject, _Chartable):
class AuthenticatedUser(User):
def __init__(self, network):
User.__init__(self, "", network)
User.__init__(self, network.username, network)
def _get_params(self):
return {"user": self.get_name()}
def get_name(self):
"""Returns the name of the authenticated user."""
doc = self._request("user.getInfo", True, {"user": ""}) # hack
self.name = _extract(doc, "name")
return self.name

View file

@ -39,7 +39,7 @@ class PyLastTestCase(unittest.TestCase):
self.assertTrue(str.endswith(suffix, start, end))
@flaky(max_runs=3, min_passes=1)
@flaky(max_runs=1, min_passes=1)
class TestPyLastWithLastFm(PyLastTestCase):
secrets = None

View file

@ -40,8 +40,8 @@ class TestPyLastTrack(TestPyLastWithLastFm):
# Assert
loved = lastfm_user.get_loved_tracks(limit=1)
if len(loved): # OK to be empty but if not:
self.assertNotEqual(str(loved.track.artist), "Test Artist")
self.assertNotEqual(str(loved.track.title), "test title")
self.assertNotEqual(str(loved[0].track.artist), "Test Artist")
self.assertNotEqual(str(loved[0].track.title), "test title")
def test_user_play_count_in_track_info(self):
# Arrange