Add assert_startswith/endswith helper functions

This commit is contained in:
Hugo 2018-04-16 18:31:33 +03:00
parent fa601b8111
commit 60dea38d10
6 changed files with 23 additions and 17 deletions

View file

@ -107,8 +107,8 @@ class TestPyLastAlbum(PyLastTestCase):
image = album.get_cover_image()
# Assert
self.assertTrue(image.startswith("https://"))
self.assertTrue(image.endswith(".png"))
self.assert_startswith(image, "https://")
self.assert_endswith(image, ".png")
if __name__ == '__main__':

View file

@ -19,7 +19,7 @@ class TestPyLastLibrary(PyLastTestCase):
representation = repr(library)
# Assert
self.assertTrue(representation.startswith("pylast.Library("))
self.assert_startswith(representation, "pylast.Library(")
def test_str(self):
# Arrange
@ -29,7 +29,7 @@ class TestPyLastLibrary(PyLastTestCase):
string = str(library)
# Assert
self.assertTrue(string.endswith("'s Library"))
self.assert_endswith(string, "'s Library")
def test_library_is_hashable(self):
# Arrange

View file

@ -42,7 +42,7 @@ class TestPyLastWithLibreFm(unittest.TestCase):
representation = repr(network)
# Assert
self.assertTrue(representation.startswith("pylast.LibreFMNetwork("))
self.assert_startswith(representation, "pylast.LibreFMNetwork(")
if __name__ == '__main__':

View file

@ -327,12 +327,12 @@ class TestPyLastNetwork(PyLastTestCase):
# Assert
self.assertEqual(len(images), 4)
self.assertTrue(images[pylast.SIZE_SMALL].startswith("https://"))
self.assertTrue(images[pylast.SIZE_SMALL].endswith(".png"))
self.assert_startswith(images[pylast.SIZE_SMALL], "https://")
self.assert_endswith(images[pylast.SIZE_SMALL], ".png")
self.assertIn("/34s/", images[pylast.SIZE_SMALL])
self.assertTrue(images[pylast.SIZE_EXTRA_LARGE].startswith("https://"))
self.assertTrue(images[pylast.SIZE_EXTRA_LARGE].endswith(".png"))
self.assert_startswith(images[pylast.SIZE_EXTRA_LARGE], "https://")
self.assert_endswith(images[pylast.SIZE_EXTRA_LARGE], ".png")
self.assertIn("/300x300/", images[pylast.SIZE_EXTRA_LARGE])
def test_artist_search(self):
@ -359,12 +359,12 @@ class TestPyLastNetwork(PyLastTestCase):
# Assert
self.assertEqual(len(images), 5)
self.assertTrue(images[pylast.SIZE_SMALL].startswith("https://"))
self.assertTrue(images[pylast.SIZE_SMALL].endswith(".png"))
self.assert_startswith(images[pylast.SIZE_SMALL], "https://")
self.assert_endswith(images[pylast.SIZE_SMALL], ".png")
self.assertIn("/34s/", images[pylast.SIZE_SMALL])
self.assertTrue(images[pylast.SIZE_EXTRA_LARGE].startswith("https://"))
self.assertTrue(images[pylast.SIZE_EXTRA_LARGE].endswith(".png"))
self.assert_startswith(images[pylast.SIZE_EXTRA_LARGE], "https://")
self.assert_endswith(images[pylast.SIZE_EXTRA_LARGE], ".png")
self.assertIn("/300x300/", images[pylast.SIZE_EXTRA_LARGE])
def test_track_search(self):

View file

@ -52,6 +52,12 @@ class PyLastTestCase(unittest.TestCase):
api_key=API_KEY, api_secret=API_SECRET,
username=self.username, password_hash=password_hash)
def assert_startswith(self, str, prefix, start=None, end=None):
self.assertTrue(str.startswith(prefix, start, end))
def assert_endswith(self, str, suffix, start=None, end=None):
self.assertTrue(str.endswith(suffix, start, end))
def helper_is_thing_hashable(self, thing):
# Arrange
things = set()

View file

@ -20,7 +20,7 @@ class TestPyLastUser(PyLastTestCase):
representation = repr(user)
# Assert
self.assertTrue(representation.startswith("pylast.User('RJ',"))
self.assert_startswith(representation, "pylast.User('RJ',")
def test_str(self):
# Arrange
@ -342,7 +342,7 @@ class TestPyLastUser(PyLastTestCase):
url = user.get_image()
# Assert
self.assertTrue(url.startswith("https://"))
self.assert_startswith(url, "https://")
def test_user_get_library(self):
# Arrange
@ -392,8 +392,8 @@ class TestPyLastUser(PyLastTestCase):
image = user.get_image()
# Assert
self.assertTrue(image.startswith("https://"))
self.assertTrue(image.endswith(".png"))
self.assert_startswith(image, "https://")
self.assert_endswith(image, ".png")
def test_get_url(self):
# Arrange