for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
import unittest
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
class SomeClass: def some_method(self): """Do x and return foo."""
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.
import coverpy
import httpretty
import os
class TestCoverpy(unittest.TestCase):
def setUp(self):
self.coverpy = coverpy.CoverPy()
# Set up paths...
self.ok_computer = os.path.join(os.path.dirname(__file__), 'mocks/OKComputer.json')
self.empty_response = os.path.join(os.path.dirname(__file__), 'mocks/SuchFakeAlbumPls.json')
@httpretty.activate
def test_get_cover_parse_result(self):
# OK Computer response
httpretty.register_uri(httpretty.GET,
"https://itunes.apple.com/search/?limit=1&entity=musicArtist%2CmusicTrack%2Calbum%2Cmix%2Csong&term=OK+Computer&media=music",
body=open(self.ok_computer).read(),
content_type="application/json")
# Request the content from the mock
result = self.coverpy.get_cover("OK Computer")
# Begin assertions
self.assertEquals(result.name, "OK Computer")
self.assertEquals(result.type, "album")
def test_get_cover_no_results(self):
# No results response
"https://itunes.apple.com/search/?limit=1&entity=musicArtist%2CmusicTrack%2Calbum%2Cmix%2Csong&term=Such+Fake+Album+Pls&media=music",
body=open(self.empty_response).read(),
# Assert a NoResultsException
with self.assertRaises(coverpy.exceptions.NoResultsException):
self.coverpy.get_cover("Such Fake Album Pls")
if __name__ == '__main__':
unittest.main()
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.