diff --git a/.travis.yml b/.travis.yml index 9e5a8f0..1ad915a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,11 +42,12 @@ install: - python3 -m pip install --upgrade -r tests/requirements.txt script: - - python3 -m pytest + - python3 -m pytest -v # Force code-style for folders that we already did, only on 1 job - if [[ $TRAVIS_PYTHON_VERSION == "3.7" ]]; then python3 -m black tests -l120 --py36 -N --check; fi - if [[ $TRAVIS_PYTHON_VERSION == "3.7" ]]; then python3 -m black tools -l120 --py36 -N --check; fi + - if [[ $TRAVIS_PYTHON_VERSION == "3.7" ]]; then python3 -m black util -l120 --py36 -N --check; fi - if [[ $TRAVIS_PYTHON_VERSION == "3.7" ]]; then python3 -m black sabnzbd/utils -l120 --py36 -N --check; fi notifications: diff --git a/appveyor.yml b/appveyor.yml index 346f9d1..a431d72 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -20,4 +20,4 @@ install: - python -m pip install --upgrade -r tests/requirements.txt build_script: - - python -m pytest \ No newline at end of file + - python -m pytest -v \ No newline at end of file diff --git a/tests/test_mailslot.py b/tests/test_win_utils.py similarity index 74% rename from tests/test_mailslot.py rename to tests/test_win_utils.py index 5d944cb..8753d45 100644 --- a/tests/test_mailslot.py +++ b/tests/test_win_utils.py @@ -27,6 +27,8 @@ import pytest if not sys.platform.startswith("win"): pytest.skip("Skipping Windows-only tests", allow_module_level=True) +import util.apireg as ar + class TestMailslot: def test_mailslot_basic(self): @@ -49,3 +51,23 @@ class TestMailslot: # Client outputs nothing assert not client_p.stdout.readlines() + + +class TestAPIReg: + def test_set_get_connection_info_user(self): + """ Test the saving of the URL in USER-registery + We can't test the SYSTEM one. + """ + + test_url = "sab_test:8080" + ar.set_connection_info(test_url, True) + assert ar.get_connection_info(True) == test_url + assert not ar.get_connection_info(False) + + # Remove and check if gone + ar.del_connection_info(True) + assert not ar.get_connection_info(True) + + def test_get_install_lng(self): + """ Not much to test yet.. """ + assert ar.get_install_lng() == "en" diff --git a/util/apireg.py b/util/apireg.py index eb093d5..3e2de17 100644 --- a/util/apireg.py +++ b/util/apireg.py @@ -44,10 +44,10 @@ def get_connection_info(user=True): try: hive = winreg.ConnectRegistry(None, section) - key = winreg.OpenKey(hive, keypath + r'\api') + key = winreg.OpenKey(hive, keypath + r"\api") for i in range(0, winreg.QueryInfoKey(key)[1]): name, value, val_type = winreg.EnumValue(key, i) - if name == 'url': + if name == "url": url = value winreg.CloseKey(key) @@ -70,11 +70,11 @@ def set_connection_info(url, user=True): hive = winreg.ConnectRegistry(None, section) try: winreg.CreateKey(hive, keypath) - except: + except OSError: pass key = winreg.OpenKey(hive, keypath) - mykey = winreg.CreateKey(key, 'api') - winreg.SetValueEx(mykey, 'url', None, winreg.REG_SZ, url) + mykey = winreg.CreateKey(key, "api") + winreg.SetValueEx(mykey, "url", None, winreg.REG_SZ, url) winreg.CloseKey(mykey) winreg.CloseKey(key) except WindowsError: @@ -90,7 +90,7 @@ def del_connection_info(user=True): try: hive = winreg.ConnectRegistry(None, section) key = winreg.OpenKey(hive, keypath) - winreg.DeleteKey(key, 'api') + winreg.DeleteKey(key, "api") winreg.CloseKey(key) except WindowsError: if user: @@ -107,7 +107,7 @@ def get_install_lng(): key = winreg.OpenKey(hive, r"Software\SABnzbd") for i in range(0, winreg.QueryInfoKey(key)[1]): name, value, val_type = winreg.EnumValue(key, i) - if name == 'Installer Language': + if name == "Installer Language": lng = value winreg.CloseKey(key) except WindowsError: @@ -117,32 +117,32 @@ def get_install_lng(): if lng in LanguageMap: return LanguageMap[lng] - return 'en' + return "en" # Map from NSIS-codepage to our language-strings LanguageMap = { - '1033': 'en', - '1036': 'fr', - '1031': 'de', - '1043': 'nl', - '1035': 'fi', - '1045': 'pl', - '1053': 'sv', - '1030': 'da', - '2068': 'nb', - '1048': 'ro', - '1034': 'es', - '1046': 'pr_BR', - '3098': 'sr', - '1037': 'he', - '1049': 'ru', - '2052': 'zh_CN' + "1033": "en", + "1036": "fr", + "1031": "de", + "1043": "nl", + "1035": "fi", + "1045": "pl", + "1053": "sv", + "1030": "da", + "2068": "nb", + "1048": "ro", + "1034": "es", + "1046": "pr_BR", + "3098": "sr", + "1037": "he", + "1049": "ru", + "2052": "zh_CN", } -if __name__ == '__main__': - print(('URL = %s' % get_connection_info())) - print(('Language = %s' % get_install_lng())) +if __name__ == "__main__": + print("URL = %s" % get_connection_info()) + print("Language = %s" % get_install_lng()) # del_connection_info() # set_connection_info('localhost', '8080', 'blabla', user=False)