Update tests and add instructions
This commit is contained in:
parent
42b6c0a19a
commit
21e43e4408
3 changed files with 46 additions and 4 deletions
20
tests/README.rst
Normal file
20
tests/README.rst
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
Package tests
|
||||||
|
============================================
|
||||||
|
Tests use the `unittest` framework. Each function has a corresponding unittest.
|
||||||
|
Sometimes there is a single unittest for multiple functions to ensure there are no permanent changes in the user's YouTube account (i.e. subscribe and unsubscribe).
|
||||||
|
|
||||||
|
Note that there must be a `headers_auth.json` in the project root to run authenticated tests.
|
||||||
|
For testing the song upload, there also needs to be a file with the name specified in the code in the project root.
|
||||||
|
For `test_get_owned_playlist` you need to modify the test to
|
||||||
|
|
||||||
|
Coverage badge
|
||||||
|
--------------
|
||||||
|
Install `coverage` and `coverage-badge` with pip. Run
|
||||||
|
|
||||||
|
`coverage run --source=ytmusicapi -m unittest discover tests`
|
||||||
|
|
||||||
|
to generate a coverage report in the project root. With
|
||||||
|
|
||||||
|
`coverage-badge -o coverage.svg`
|
||||||
|
|
||||||
|
you generate the badge. Move both files to the `tests` directory.
|
||||||
21
tests/coverage.svg
Normal file
21
tests/coverage.svg
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="99" height="20">
|
||||||
|
<linearGradient id="b" x2="0" y2="100%">
|
||||||
|
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
|
||||||
|
<stop offset="1" stop-opacity=".1"/>
|
||||||
|
</linearGradient>
|
||||||
|
<mask id="a">
|
||||||
|
<rect width="99" height="20" rx="3" fill="#fff"/>
|
||||||
|
</mask>
|
||||||
|
<g mask="url(#a)">
|
||||||
|
<path fill="#555" d="M0 0h63v20H0z"/>
|
||||||
|
<path fill="#a4a61d" d="M63 0h36v20H63z"/>
|
||||||
|
<path fill="url(#b)" d="M0 0h99v20H0z"/>
|
||||||
|
</g>
|
||||||
|
<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="14">coverage</text>
|
||||||
|
<text x="80" y="15" fill="#010101" fill-opacity=".3">85%</text>
|
||||||
|
<text x="80" y="14">85%</text>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 904 B |
|
|
@ -1,8 +1,9 @@
|
||||||
import unittest
|
import unittest
|
||||||
|
import os
|
||||||
from ytmusicapi.ytmusic import YTMusic
|
from ytmusicapi.ytmusic import YTMusic
|
||||||
|
|
||||||
youtube = YTMusic()
|
youtube = YTMusic()
|
||||||
youtube_auth = YTMusic('../headers_auth.json')
|
youtube_auth = YTMusic('headers_auth.json')
|
||||||
|
|
||||||
|
|
||||||
class TestYTMusic(unittest.TestCase):
|
class TestYTMusic(unittest.TestCase):
|
||||||
|
|
@ -86,11 +87,11 @@ class TestYTMusic(unittest.TestCase):
|
||||||
|
|
||||||
def test_get_uploaded_songs(self):
|
def test_get_uploaded_songs(self):
|
||||||
results = youtube_auth.get_uploaded_songs(126)
|
results = youtube_auth.get_uploaded_songs(126)
|
||||||
self.assertEqual(len(results), 126)
|
self.assertGreater(len(results), 100)
|
||||||
|
|
||||||
def test_upload_song(self):
|
def test_upload_song(self):
|
||||||
response = youtube_auth.upload_song('../12 - Turning Point 자.mp3')
|
response = youtube_auth.upload_song('12 - Turning Point 자.mp3')
|
||||||
self.assertEqual(response, 'STATUS_SUCCEEDED')
|
self.assertEqual(response.status_code, 409)
|
||||||
|
|
||||||
def test_delete_uploaded_song(self):
|
def test_delete_uploaded_song(self):
|
||||||
results = youtube_auth.get_uploaded_songs()
|
results = youtube_auth.get_uploaded_songs()
|
||||||
Loading…
Reference in a new issue