Files
whipper-gui/whipper/test/test_common_config.py
JoeLametta 1206552bd2 Use https and http appropriately when connecting to MusicBrainz
Fixed some bugs:
- MusicBrainz submit URL always has https as protocol: hardcoded, even when
inappropriate. It's just a graphical issue.
- Whipper appears to always communicate with MusicBrainz using musicbrainzngs
over http. The musicbrainzngs.set_hostname(server).
- `musicbrainzngs.set_hostname(server)` always defaults to http. Since musicbrainzngs
version 0.7 the method `set_hostname` takes an optional argument named `use_https`
(defaults to False) which whipper never passes.

Changed behaviour of `server` option (`musicbrainz` section of whipper's configuration file).
Now it expects an URL with a valid scheme (scheme must be `http` or `http`, empty scheme isn't allowed anymore).
Only the scheme and netloc parts of the URL are taken into account.

Fixes #437.

Signed-off-by: JoeLametta <JoeLametta@users.noreply.github.com>
2020-01-17 15:12:40 +00:00

95 lines
3.5 KiB
Python

# -*- Mode: Python; test-case-name: whipper.test.test_common_config -*-
# vi:si:et:sw=4:sts=4:ts=4
import os
import tempfile
from whipper.common import config
from whipper.test import common as tcommon
class ConfigTestCase(tcommon.TestCase):
def setUp(self):
fd, self._path = tempfile.mkstemp(suffix='.whipper.test.config')
os.close(fd)
self._config = config.Config(self._path)
def tearDown(self):
os.unlink(self._path)
def testAddReadOffset(self):
self.assertRaises(KeyError, self._config.getReadOffset,
'PLEXTOR ', 'DVDR PX-L890SA', '1.05')
self._config.setReadOffset('PLEXTOR ', 'DVDR PX-L890SA', '1.05', 6)
# getting it from memory should work
offset = self._config.getReadOffset(
'PLEXTOR ', 'DVDR PX-L890SA', '1.05')
self.assertEqual(offset, 6)
# and so should getting it after reading it again
self._config.open()
offset = self._config.getReadOffset(
'PLEXTOR ', 'DVDR PX-L890SA', '1.05')
self.assertEqual(offset, 6)
def testAddReadOffsetSpaced(self):
self.assertRaises(KeyError, self._config.getReadOffset,
'Slimtype', 'eSAU208 2 ', 'ML03')
self._config.setReadOffset('Slimtype', 'eSAU208 2 ', 'ML03', 6)
# getting it from memory should work
offset = self._config.getReadOffset(
'Slimtype', 'eSAU208 2 ', 'ML03')
self.assertEqual(offset, 6)
# and so should getting it after reading it again
self._config.open()
offset = self._config.getReadOffset(
'Slimtype', 'eSAU208 2 ', 'ML03')
self.assertEqual(offset, 6)
def testDefeatsCache(self):
self.assertRaises(KeyError, self._config.getDefeatsCache,
'PLEXTOR ', 'DVDR PX-L890SA', '1.05')
self._config.setDefeatsCache(
'PLEXTOR ', 'DVDR PX-L890SA', '1.05', False)
defeats = self._config.getDefeatsCache(
'PLEXTOR ', 'DVDR PX-L890SA', '1.05')
self.assertEqual(defeats, False)
self._config.setDefeatsCache(
'PLEXTOR ', 'DVDR PX-L890SA', '1.05', True)
defeats = self._config.getDefeatsCache(
'PLEXTOR ', 'DVDR PX-L890SA', '1.05')
self.assertEqual(defeats, True)
def test_get_musicbrainz_server(self):
self.assertEqual(self._config.get_musicbrainz_server(),
{'scheme': 'https', 'netloc': 'musicbrainz.org'},
msg='Default value is correct')
self._config._parser.add_section('musicbrainz')
self._config._parser.set('musicbrainz', 'server',
'http://192.168.2.141:5000')
self._config.write()
self.assertEqual(self._config.get_musicbrainz_server(),
{'scheme': 'http', 'netloc': '192.168.2.141:5000'},
msg='Correctly returns user-set value')
# Test for unsupported scheme
self._config._parser.set('musicbrainz', 'server', 'ftp://example.com')
self._config.write()
self.assertRaises(KeyError, self._config.get_musicbrainz_server)
# Test for absent scheme
self._config._parser.set('musicbrainz', 'server', 'example.com')
self._config.write()
self.assertRaises(KeyError, self._config.get_musicbrainz_server)
self._config._parser.remove_section('musicbrainz')