Add assert_startswith/endswith helper functions
This commit is contained in:
parent
fa601b8111
commit
60dea38d10
|
@ -107,8 +107,8 @@ class TestPyLastAlbum(PyLastTestCase):
|
||||||
image = album.get_cover_image()
|
image = album.get_cover_image()
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
self.assertTrue(image.startswith("https://"))
|
self.assert_startswith(image, "https://")
|
||||||
self.assertTrue(image.endswith(".png"))
|
self.assert_endswith(image, ".png")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -19,7 +19,7 @@ class TestPyLastLibrary(PyLastTestCase):
|
||||||
representation = repr(library)
|
representation = repr(library)
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
self.assertTrue(representation.startswith("pylast.Library("))
|
self.assert_startswith(representation, "pylast.Library(")
|
||||||
|
|
||||||
def test_str(self):
|
def test_str(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
|
@ -29,7 +29,7 @@ class TestPyLastLibrary(PyLastTestCase):
|
||||||
string = str(library)
|
string = str(library)
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
self.assertTrue(string.endswith("'s Library"))
|
self.assert_endswith(string, "'s Library")
|
||||||
|
|
||||||
def test_library_is_hashable(self):
|
def test_library_is_hashable(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
|
|
|
@ -42,7 +42,7 @@ class TestPyLastWithLibreFm(unittest.TestCase):
|
||||||
representation = repr(network)
|
representation = repr(network)
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
self.assertTrue(representation.startswith("pylast.LibreFMNetwork("))
|
self.assert_startswith(representation, "pylast.LibreFMNetwork(")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -327,12 +327,12 @@ class TestPyLastNetwork(PyLastTestCase):
|
||||||
# Assert
|
# Assert
|
||||||
self.assertEqual(len(images), 4)
|
self.assertEqual(len(images), 4)
|
||||||
|
|
||||||
self.assertTrue(images[pylast.SIZE_SMALL].startswith("https://"))
|
self.assert_startswith(images[pylast.SIZE_SMALL], "https://")
|
||||||
self.assertTrue(images[pylast.SIZE_SMALL].endswith(".png"))
|
self.assert_endswith(images[pylast.SIZE_SMALL], ".png")
|
||||||
self.assertIn("/34s/", images[pylast.SIZE_SMALL])
|
self.assertIn("/34s/", images[pylast.SIZE_SMALL])
|
||||||
|
|
||||||
self.assertTrue(images[pylast.SIZE_EXTRA_LARGE].startswith("https://"))
|
self.assert_startswith(images[pylast.SIZE_EXTRA_LARGE], "https://")
|
||||||
self.assertTrue(images[pylast.SIZE_EXTRA_LARGE].endswith(".png"))
|
self.assert_endswith(images[pylast.SIZE_EXTRA_LARGE], ".png")
|
||||||
self.assertIn("/300x300/", images[pylast.SIZE_EXTRA_LARGE])
|
self.assertIn("/300x300/", images[pylast.SIZE_EXTRA_LARGE])
|
||||||
|
|
||||||
def test_artist_search(self):
|
def test_artist_search(self):
|
||||||
|
@ -359,12 +359,12 @@ class TestPyLastNetwork(PyLastTestCase):
|
||||||
# Assert
|
# Assert
|
||||||
self.assertEqual(len(images), 5)
|
self.assertEqual(len(images), 5)
|
||||||
|
|
||||||
self.assertTrue(images[pylast.SIZE_SMALL].startswith("https://"))
|
self.assert_startswith(images[pylast.SIZE_SMALL], "https://")
|
||||||
self.assertTrue(images[pylast.SIZE_SMALL].endswith(".png"))
|
self.assert_endswith(images[pylast.SIZE_SMALL], ".png")
|
||||||
self.assertIn("/34s/", images[pylast.SIZE_SMALL])
|
self.assertIn("/34s/", images[pylast.SIZE_SMALL])
|
||||||
|
|
||||||
self.assertTrue(images[pylast.SIZE_EXTRA_LARGE].startswith("https://"))
|
self.assert_startswith(images[pylast.SIZE_EXTRA_LARGE], "https://")
|
||||||
self.assertTrue(images[pylast.SIZE_EXTRA_LARGE].endswith(".png"))
|
self.assert_endswith(images[pylast.SIZE_EXTRA_LARGE], ".png")
|
||||||
self.assertIn("/300x300/", images[pylast.SIZE_EXTRA_LARGE])
|
self.assertIn("/300x300/", images[pylast.SIZE_EXTRA_LARGE])
|
||||||
|
|
||||||
def test_track_search(self):
|
def test_track_search(self):
|
||||||
|
|
|
@ -52,6 +52,12 @@ class PyLastTestCase(unittest.TestCase):
|
||||||
api_key=API_KEY, api_secret=API_SECRET,
|
api_key=API_KEY, api_secret=API_SECRET,
|
||||||
username=self.username, password_hash=password_hash)
|
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):
|
def helper_is_thing_hashable(self, thing):
|
||||||
# Arrange
|
# Arrange
|
||||||
things = set()
|
things = set()
|
||||||
|
|
|
@ -20,7 +20,7 @@ class TestPyLastUser(PyLastTestCase):
|
||||||
representation = repr(user)
|
representation = repr(user)
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
self.assertTrue(representation.startswith("pylast.User('RJ',"))
|
self.assert_startswith(representation, "pylast.User('RJ',")
|
||||||
|
|
||||||
def test_str(self):
|
def test_str(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
|
@ -342,7 +342,7 @@ class TestPyLastUser(PyLastTestCase):
|
||||||
url = user.get_image()
|
url = user.get_image()
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
self.assertTrue(url.startswith("https://"))
|
self.assert_startswith(url, "https://")
|
||||||
|
|
||||||
def test_user_get_library(self):
|
def test_user_get_library(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
|
@ -392,8 +392,8 @@ class TestPyLastUser(PyLastTestCase):
|
||||||
image = user.get_image()
|
image = user.get_image()
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
self.assertTrue(image.startswith("https://"))
|
self.assert_startswith(image, "https://")
|
||||||
self.assertTrue(image.endswith(".png"))
|
self.assert_endswith(image, ".png")
|
||||||
|
|
||||||
def test_get_url(self):
|
def test_get_url(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
|
|
Loading…
Reference in a new issue