Added test suites for fixes

This commit is contained in:
Manuel Cortez 2018-12-30 01:11:33 -06:00
parent 9aa61b1e7b
commit 95fdae058d
4 changed files with 48 additions and 2 deletions

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
import unittest
testmodules = ['test.test_storage', 'test.test_extractors']
testmodules = ['test.test_storage', 'test.test_extractors', 'test.test_fixes']
suite = unittest.TestSuite()

View File

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
""" Unittests for extractors present in MusicDL. """
from __future__ import unicode_literals
import sys
@ -16,10 +17,11 @@ else:
class extractorsTestCase(unittest.TestCase):
def setUp(self):
""" Configure i18n functions for avoiding a traceback later. """
i18n.setup()
def search(self, extractor_name, search_query="piano", skip_validation=False):
""" Blank here"""
""" Search a video in the passed extractor name. """
# Test basic instance stuff.
extractor_instance = getattr(extractors, extractor_name).interface()
extractor_instance.search(search_query)
@ -47,6 +49,7 @@ class extractorsTestCase(unittest.TestCase):
self.assertNotEquals(item.download_url, "")
def search_blank(self, extractor_name, search_query=""):
""" Attempt to search in any extractor by passing a blank string. """
extractor_instance = getattr(extractors, extractor_name).interface()
self.assertRaises(ValueError, extractor_instance.search, search_query)
@ -59,21 +62,27 @@ class extractorsTestCase(unittest.TestCase):
self.search_blank("youtube")
def test_youtube_direct_link(self):
""" Testing a search in youtube by passing a direct link. """
self.search("youtube", "https://www.youtube.com/watch?v=hwDiI9p9L-g")
def test_youtube_playlist(self):
""" Testing a youtube search by passing a link to a playlist. """
self.search("youtube", "https://www.youtube.com/playlist?list=PLqivnvaruBVH8fqI5JU9h5jZKV-32bbEn", skip_validation=True)
def test_mailru_search(self):
""" Testing a mail.ru search. """
self.search("mailru")
def test_mailru_search_blank(self):
""" Testing a mail.ru search when text is blank. """
self.search_blank("mailru")
def test_zaycev_search(self):
""" Testing a search made in zaycev.net """
self.search("zaycev")
def test_zaycev_search_blank(self):
""" Testing a search in zaycev.net when text is blank. """
self.search_blank("zaycev")
if __name__ == "__main__":

31
src/test/test_fixes.py Normal file
View File

@ -0,0 +1,31 @@
""" Unittests for fixers applied in some cases. """
from __future__ import unicode_literals
import os
import sys
import unittest
import winpaths
from fixes import fix_requests
# Let's import the reload function
if sys.version[0] == "3":
from imp import reload
class fixesTestCase(unittest.TestCase):
def test_winpaths_error_in_python3(self):
""" Testing the winpaths error happening only in Python 3 due to changes introduced to ctypes. """
# If this test fails, it means winpaths has been updated to fix the ctypes issue already.
# Therefore this test and the corresponding issue should be removed.
if sys.version[0] != "3":
return
# A reload of winpaths is needed to rever the fix of winpaths, if has been applied before
reload(winpaths)
self.assertRaises(AttributeError, winpaths.get_appdata)
def test_requests_fix(self):
""" Testing the requests fix and check if the certificates file exists in the provided path. """
fix_requests.fix()
self.assertTrue(os.path.exists(os.environ["REQUESTS_CA_BUNDLE"]))
if __name__ == "__main__":
unittest.main()

View File

@ -1,11 +1,13 @@
""" Unittests for Path generation stuff. """
from __future__ import unicode_literals
import os
import sys
import shutil
import unittest
import tempfile
import storage
import paths
from fixes import fix_winpaths
class storageTestCase(unittest.TestCase):
@ -18,8 +20,10 @@ class storageTestCase(unittest.TestCase):
def test_installer_path(self):
""" Testing if paths are generated appropiately. """
# this is a temporary fix for winpaths.
fake_installer_file = open(os.path.join(paths.app_path(), "uninstall.exe"), "w")
fake_installer_file.close()
fix_winpaths.fix()
storage.setup()
self.assertEquals(storage.app_type, "installed")
self.assertTrue(os.path.exists(storage.data_directory))
@ -27,9 +31,11 @@ class storageTestCase(unittest.TestCase):
def tearDown(self):
""" Removes uninstall.exe created for tests and data path."""
fix_winpaths.fix()
if os.path.exists(paths.app_data_path("musicDL")):
shutil.rmtree(paths.app_data_path("musicDL"))
if os.path.exists(os.path.join(paths.app_path(), "uninstall.exe")):
os.remove(os.path.join(paths.app_path(), "uninstall.exe"))
if __name__ == "__main__":
unittest.main()