Total Complexity | 4 |
Total Lines | 33 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | import unittest |
||
6 | class TestCoverpy(unittest.TestCase): |
||
7 | def setUp(self): |
||
8 | self.coverpy = coverpy.CoverPy() |
||
9 | # Set up paths... |
||
10 | self.ok_computer = os.path.join(os.path.dirname(__file__), 'mocks/OKComputer.json') |
||
11 | self.empty_response = os.path.join(os.path.dirname(__file__), 'mocks/SuchFakeAlbumPls.json') |
||
12 | |||
13 | @httpretty.activate |
||
14 | def test_get_cover_parse_result(self): |
||
15 | # OK Computer response |
||
16 | httpretty.register_uri(httpretty.GET, |
||
17 | "https://itunes.apple.com/search/?limit=1&entity=musicArtist%2CmusicTrack%2Calbum%2Cmix%2Csong&term=OK+Computer&media=music", |
||
18 | body=open(self.ok_computer).read(), |
||
19 | content_type="application/json") |
||
20 | |||
21 | # Request the content from the mock |
||
22 | result = self.coverpy.get_cover("OK Computer") |
||
23 | |||
24 | # Begin assertions |
||
25 | self.assertEquals(result.name, "OK Computer") |
||
26 | self.assertEquals(result.type, "album") |
||
27 | |||
28 | @httpretty.activate |
||
29 | def test_get_cover_no_results(self): |
||
30 | # No results response |
||
31 | httpretty.register_uri(httpretty.GET, |
||
32 | "https://itunes.apple.com/search/?limit=1&entity=musicArtist%2CmusicTrack%2Calbum%2Cmix%2Csong&term=Such+Fake+Album+Pls&media=music", |
||
33 | body=open(self.empty_response).read(), |
||
34 | content_type="application/json") |
||
35 | |||
36 | # Assert a NoResultsException |
||
37 | with self.assertRaises(coverpy.exceptions.NoResultsException): |
||
38 | self.coverpy.get_cover("Such Fake Album Pls") |
||
39 | |||
41 | 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.