diff --git a/tests/test_album.py b/tests/test_album.py index 2c7f369..a44305b 100755 --- a/tests/test_album.py +++ b/tests/test_album.py @@ -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__': diff --git a/tests/test_library.py b/tests/test_library.py index 1e437f1..ca87c8e 100755 --- a/tests/test_library.py +++ b/tests/test_library.py @@ -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 diff --git a/tests/test_librefm.py b/tests/test_librefm.py index 7c958cb..ab3ea3f 100755 --- a/tests/test_librefm.py +++ b/tests/test_librefm.py @@ -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__': diff --git a/tests/test_network.py b/tests/test_network.py index e1896ea..e41a9fc 100755 --- a/tests/test_network.py +++ b/tests/test_network.py @@ -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): diff --git a/tests/test_pylast.py b/tests/test_pylast.py index 9ebbcc1..c09ad27 100755 --- a/tests/test_pylast.py +++ b/tests/test_pylast.py @@ -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() diff --git a/tests/test_user.py b/tests/test_user.py index c742bd3..ecb7c94 100755 --- a/tests/test_user.py +++ b/tests/test_user.py @@ -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