diff --git a/tests/README.rst b/tests/README.rst new file mode 100644 index 0000000..8be643b --- /dev/null +++ b/tests/README.rst @@ -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. \ No newline at end of file diff --git a/tests/coverage.svg b/tests/coverage.svg new file mode 100644 index 0000000..318685c --- /dev/null +++ b/tests/coverage.svg @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + coverage + coverage + 85% + 85% + + diff --git a/ytmusicapi/test.py b/tests/test.py similarity index 94% rename from ytmusicapi/test.py rename to tests/test.py index da29015..42dd009 100644 --- a/ytmusicapi/test.py +++ b/tests/test.py @@ -1,8 +1,9 @@ import unittest +import os from ytmusicapi.ytmusic import YTMusic youtube = YTMusic() -youtube_auth = YTMusic('../headers_auth.json') +youtube_auth = YTMusic('headers_auth.json') class TestYTMusic(unittest.TestCase): @@ -86,11 +87,11 @@ class TestYTMusic(unittest.TestCase): def test_get_uploaded_songs(self): results = youtube_auth.get_uploaded_songs(126) - self.assertEqual(len(results), 126) + self.assertGreater(len(results), 100) def test_upload_song(self): - response = youtube_auth.upload_song('../12 - Turning Point 자.mp3') - self.assertEqual(response, 'STATUS_SUCCEEDED') + response = youtube_auth.upload_song('12 - Turning Point 자.mp3') + self.assertEqual(response.status_code, 409) def test_delete_uploaded_song(self): results = youtube_auth.get_uploaded_songs()