Add more tests
This commit is contained in:
parent
74fc9fd470
commit
6f543999d1
6 changed files with 29 additions and 13 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -3,4 +3,6 @@
|
||||||
headers_auth.json
|
headers_auth.json
|
||||||
docs/build
|
docs/build
|
||||||
**.bat
|
**.bat
|
||||||
**.cfg
|
**.cfg
|
||||||
|
**.mp3
|
||||||
|
.coverage
|
||||||
|
|
@ -19,12 +19,14 @@ Before making changes to the code, install the development requirements using
|
||||||
|
|
||||||
pip install -e .[dev]
|
pip install -e .[dev]
|
||||||
|
|
||||||
Before committing, run style and linter checks using
|
Before committing, stage your files and run style and linter checks:
|
||||||
|
|
||||||
.. code-block::
|
.. code-block::
|
||||||
|
|
||||||
|
git add .
|
||||||
pre-commit run
|
pre-commit run
|
||||||
|
|
||||||
|
pre-commit will unstage any files that do not pass. Fix the issues until all checks pass and commit.
|
||||||
|
|
||||||
Code structure
|
Code structure
|
||||||
---------------
|
---------------
|
||||||
|
|
|
||||||
|
|
@ -9,13 +9,13 @@
|
||||||
</mask>
|
</mask>
|
||||||
<g mask="url(#a)">
|
<g mask="url(#a)">
|
||||||
<path fill="#555" d="M0 0h63v20H0z"/>
|
<path fill="#555" d="M0 0h63v20H0z"/>
|
||||||
<path fill="#97CA00" d="M63 0h36v20H63z"/>
|
<path fill="#4c1" d="M63 0h36v20H63z"/>
|
||||||
<path fill="url(#b)" d="M0 0h99v20H0z"/>
|
<path fill="url(#b)" d="M0 0h99v20H0z"/>
|
||||||
</g>
|
</g>
|
||||||
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
|
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
|
||||||
<text x="31.5" y="15" fill="#010101" fill-opacity=".3">coverage</text>
|
<text x="31.5" y="15" fill="#010101" fill-opacity=".3">coverage</text>
|
||||||
<text x="31.5" y="14">coverage</text>
|
<text x="31.5" y="14">coverage</text>
|
||||||
<text x="80" y="15" fill="#010101" fill-opacity=".3">93%</text>
|
<text x="80" y="15" fill="#010101" fill-opacity=".3">96%</text>
|
||||||
<text x="80" y="14">93%</text>
|
<text x="80" y="14">96%</text>
|
||||||
</g>
|
</g>
|
||||||
</svg>
|
</svg>
|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 904 B After Width: | Height: | Size: 901 B |
|
|
@ -11,6 +11,9 @@ youtube_brand = YTMusic(config['auth']['headers'], config['auth']['brand_account
|
||||||
|
|
||||||
|
|
||||||
class TestYTMusic(unittest.TestCase):
|
class TestYTMusic(unittest.TestCase):
|
||||||
|
def test_init(self):
|
||||||
|
self.assertRaises(Exception, YTMusic, "{}")
|
||||||
|
|
||||||
def test_setup(self):
|
def test_setup(self):
|
||||||
YTMusic.setup(config['auth']['headers_file'])
|
YTMusic.setup(config['auth']['headers_file'])
|
||||||
|
|
||||||
|
|
@ -19,13 +22,19 @@ class TestYTMusic(unittest.TestCase):
|
||||||
###############
|
###############
|
||||||
|
|
||||||
def test_search(self):
|
def test_search(self):
|
||||||
results = youtube_auth.search("Oasis Wonderwall")
|
query = "Oasis Wonderwall"
|
||||||
|
self.assertRaises(Exception, youtube_auth.search, query, "song")
|
||||||
|
results = youtube_auth.search(query)
|
||||||
self.assertGreater(len(results), 0)
|
self.assertGreater(len(results), 0)
|
||||||
results = youtube_auth.search("Oasis Wonderwall", 'videos')
|
results = youtube_auth.search(query, 'songs')
|
||||||
self.assertGreater(len(results), 0)
|
self.assertGreater(len(results), 0)
|
||||||
results = youtube_auth.search("Oasis Wonderwall", 'albums')
|
results = youtube_auth.search(query, 'videos')
|
||||||
self.assertGreater(len(results), 0)
|
self.assertGreater(len(results), 0)
|
||||||
results = youtube_auth.search("Oasis Wonderwall", 'artists')
|
results = youtube_auth.search(query, 'albums')
|
||||||
|
self.assertGreater(len(results), 0)
|
||||||
|
results = youtube_auth.search(query, 'artists')
|
||||||
|
self.assertGreater(len(results), 0)
|
||||||
|
results = youtube_auth.search(query, 'playlists')
|
||||||
self.assertGreater(len(results), 0)
|
self.assertGreater(len(results), 0)
|
||||||
|
|
||||||
def test_get_artist(self):
|
def test_get_artist(self):
|
||||||
|
|
@ -162,6 +171,7 @@ class TestYTMusic(unittest.TestCase):
|
||||||
self.assertGreater(len(results), 25)
|
self.assertGreater(len(results), 25)
|
||||||
|
|
||||||
def test_upload_song(self):
|
def test_upload_song(self):
|
||||||
|
self.assertRaises(Exception, youtube_auth.upload_song, 'song.wav')
|
||||||
response = youtube_auth.upload_song(config['uploads']['file'])
|
response = youtube_auth.upload_song(config['uploads']['file'])
|
||||||
self.assertEqual(response.status_code, 409)
|
self.assertEqual(response.status_code, 409)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,4 +3,4 @@ from ytmusicapi.ytmusic import YTMusic
|
||||||
|
|
||||||
__copyright__ = 'Copyright 2020 sigma67'
|
__copyright__ = 'Copyright 2020 sigma67'
|
||||||
__license__ = 'MIT'
|
__license__ = 'MIT'
|
||||||
__title__ = 'ytmusicapi'
|
__title__ = 'ytmusicapi'
|
||||||
|
|
|
||||||
|
|
@ -132,6 +132,11 @@ class YTMusic:
|
||||||
body = {'query': query}
|
body = {'query': query}
|
||||||
endpoint = 'search'
|
endpoint = 'search'
|
||||||
search_results = []
|
search_results = []
|
||||||
|
filters = ['albums', 'artists', 'playlists', 'songs', 'videos']
|
||||||
|
if filter and filter not in filters:
|
||||||
|
raise Exception(
|
||||||
|
"Invalid filter provided. Please use one of the following filters or leave out the parameter: "
|
||||||
|
+ ', '.join(filters))
|
||||||
|
|
||||||
if filter:
|
if filter:
|
||||||
param1 = 'Eg-KAQwIA'
|
param1 = 'Eg-KAQwIA'
|
||||||
|
|
@ -150,9 +155,6 @@ class YTMusic:
|
||||||
|
|
||||||
body['params'] = param1 + param2 + param3
|
body['params'] = param1 + param2 + param3
|
||||||
|
|
||||||
elif filter not in ['albums', 'artists', 'playlists', 'songs', 'videos', None]:
|
|
||||||
return search_results
|
|
||||||
|
|
||||||
response = self.__send_request(endpoint, body)
|
response = self.__send_request(endpoint, body)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue