Refactor get_wiki things to remove duplication
This commit is contained in:
parent
ac87cee29d
commit
342bb94045
36
pylast.py
36
pylast.py
|
@ -1449,25 +1449,12 @@ class _BaseObject(object):
|
||||||
|
|
||||||
self._request(self.ws_prefix + '.share', False, params)
|
self._request(self.ws_prefix + '.share', False, params)
|
||||||
|
|
||||||
def get_wiki_published_date(self):
|
def get_wiki(self, section):
|
||||||
"""
|
|
||||||
Returns the date of publishing this version of the wiki.
|
|
||||||
Only for Album/Tag/Track.
|
|
||||||
"""
|
|
||||||
|
|
||||||
doc = self._request(self.ws_prefix + ".getInfo", True)
|
|
||||||
|
|
||||||
if len(doc.getElementsByTagName("wiki")) == 0:
|
|
||||||
return
|
|
||||||
|
|
||||||
node = doc.getElementsByTagName("wiki")[0]
|
|
||||||
|
|
||||||
return _extract(node, "published")
|
|
||||||
|
|
||||||
def get_wiki_summary(self):
|
|
||||||
"""
|
"""
|
||||||
Returns the summary of the wiki.
|
Returns the summary of the wiki.
|
||||||
Only for Album/Track.
|
Only for Album/Track.
|
||||||
|
section can be "content", "summary" or "published"
|
||||||
|
(for published date)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
doc = self._request(self.ws_prefix + ".getInfo", True)
|
doc = self._request(self.ws_prefix + ".getInfo", True)
|
||||||
|
@ -1477,22 +1464,7 @@ class _BaseObject(object):
|
||||||
|
|
||||||
node = doc.getElementsByTagName("wiki")[0]
|
node = doc.getElementsByTagName("wiki")[0]
|
||||||
|
|
||||||
return _extract(node, "summary")
|
return _extract(node, section)
|
||||||
|
|
||||||
def get_wiki_content(self):
|
|
||||||
"""
|
|
||||||
Returns the content of the wiki.
|
|
||||||
Only for Album/Track.
|
|
||||||
"""
|
|
||||||
|
|
||||||
doc = self._request(self.ws_prefix + ".getInfo", True)
|
|
||||||
|
|
||||||
if len(doc.getElementsByTagName("wiki")) == 0:
|
|
||||||
return
|
|
||||||
|
|
||||||
node = doc.getElementsByTagName("wiki")[0]
|
|
||||||
|
|
||||||
return _extract(node, "content")
|
|
||||||
|
|
||||||
def get_shouts(self, limit=50, cacheable=False):
|
def get_shouts(self, limit=50, cacheable=False):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -680,7 +680,18 @@ class TestPyLast(unittest.TestCase):
|
||||||
album = pylast.Album("Test Artist", "Test Album", self.network)
|
album = pylast.Album("Test Artist", "Test Album", self.network)
|
||||||
|
|
||||||
# Act
|
# Act
|
||||||
wiki = album.get_wiki_content()
|
wiki = album.get_wiki("content")
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
self.assertIsNotNone(wiki)
|
||||||
|
self.assertGreaterEqual(len(wiki), 1)
|
||||||
|
|
||||||
|
def test_album_wiki_published(self):
|
||||||
|
# Arrange
|
||||||
|
album = pylast.Album("Test Artist", "Test Album", self.network)
|
||||||
|
|
||||||
|
# Act
|
||||||
|
wiki = album.get_wiki("published")
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
self.assertIsNotNone(wiki)
|
self.assertIsNotNone(wiki)
|
||||||
|
@ -691,7 +702,7 @@ class TestPyLast(unittest.TestCase):
|
||||||
album = pylast.Album("Test Artist", "Test Album", self.network)
|
album = pylast.Album("Test Artist", "Test Album", self.network)
|
||||||
|
|
||||||
# Act
|
# Act
|
||||||
wiki = album.get_wiki_summary()
|
wiki = album.get_wiki("summary")
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
self.assertIsNotNone(wiki)
|
self.assertIsNotNone(wiki)
|
||||||
|
@ -702,7 +713,7 @@ class TestPyLast(unittest.TestCase):
|
||||||
track = pylast.Track("Test Artist", "Test Title", self.network)
|
track = pylast.Track("Test Artist", "Test Title", self.network)
|
||||||
|
|
||||||
# Act
|
# Act
|
||||||
wiki = track.get_wiki_content()
|
wiki = track.get_wiki("content")
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
self.assertIsNotNone(wiki)
|
self.assertIsNotNone(wiki)
|
||||||
|
@ -713,7 +724,7 @@ class TestPyLast(unittest.TestCase):
|
||||||
track = pylast.Track("Test Artist", "Test Title", self.network)
|
track = pylast.Track("Test Artist", "Test Title", self.network)
|
||||||
|
|
||||||
# Act
|
# Act
|
||||||
wiki = track.get_wiki_summary()
|
wiki = track.get_wiki("summary")
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
self.assertIsNotNone(wiki)
|
self.assertIsNotNone(wiki)
|
||||||
|
@ -1283,6 +1294,7 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
if test is not None and len(test):
|
if test is not None and len(test):
|
||||||
suite = unittest.TestSuite()
|
suite = unittest.TestSuite()
|
||||||
|
|
||||||
suite.addTest(TestPyLast(test))
|
suite.addTest(TestPyLast(test))
|
||||||
unittest.TextTestRunner().run(suite)
|
unittest.TextTestRunner().run(suite)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue