mirror of
https://github.com/beetbox/beets.git
synced 2025-12-15 21:14:19 +01:00
Improve handling of paths for Windows tests
Signed-off-by: Graham R. Cobb <g+beets@cobb.uk.net>
This commit is contained in:
parent
ab2e858bce
commit
45cf9d00c7
1 changed files with 34 additions and 10 deletions
|
|
@ -13,11 +13,22 @@ from test import _common
|
|||
from beets.library import Item, Album
|
||||
from beetsplug import web
|
||||
|
||||
import platform
|
||||
|
||||
from beets import logging
|
||||
|
||||
|
||||
class WebPluginTest(_common.LibTestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
||||
super(WebPluginTest, self).setUp()
|
||||
self.log = logging.getLogger('beets.web')
|
||||
|
||||
if platform.system() == 'Windows':
|
||||
self.path_prefix = u'C:'
|
||||
else:
|
||||
self.path_prefix = u''
|
||||
|
||||
# Add fixtures
|
||||
for track in self.lib.items():
|
||||
|
|
@ -26,23 +37,30 @@ class WebPluginTest(_common.LibTestCase):
|
|||
# Add library elements. Note that self.lib.add overrides any "id=<n>"
|
||||
# and assigns the next free id number.
|
||||
# The following adds will create items #1, #2 and #3
|
||||
path1 = self.path_prefix + os.sep + \
|
||||
os.path.join(b'path_1').decode('utf-8')
|
||||
self.lib.add(Item(title=u'title',
|
||||
path=os.sep + os.path.join('path_1'),
|
||||
path=path1,
|
||||
album_id=2,
|
||||
artist='AAA Singers'))
|
||||
path2 = self.path_prefix + os.sep + \
|
||||
os.path.join(b'somewhere', b'a').decode('utf-8')
|
||||
self.lib.add(Item(title=u'another title',
|
||||
path=os.sep + os.path.join('somewhere', 'a'),
|
||||
path=path2,
|
||||
artist='AAA Singers'))
|
||||
path3 = self.path_prefix + os.sep + \
|
||||
os.path.join(b'somewhere', b'abc').decode('utf-8')
|
||||
self.lib.add(Item(title=u'and a third',
|
||||
testattr='ABC',
|
||||
path=os.sep + os.path.join('somewhere', 'abc'),
|
||||
path=path3,
|
||||
album_id=2))
|
||||
# The following adds will create albums #1 and #2
|
||||
self.lib.add(Album(album=u'album',
|
||||
albumtest='xyz'))
|
||||
path4 = self.path_prefix + os.sep + \
|
||||
os.path.join(b'somewhere2', b'art_path_2').decode('utf-8')
|
||||
self.lib.add(Album(album=u'other album',
|
||||
artpath=os.sep
|
||||
+ os.path.join('somewhere2', 'art_path_2')))
|
||||
artpath=path4))
|
||||
|
||||
web.app.config['TESTING'] = True
|
||||
web.app.config['lib'] = self.lib
|
||||
|
|
@ -53,9 +71,11 @@ class WebPluginTest(_common.LibTestCase):
|
|||
web.app.config['INCLUDE_PATHS'] = True
|
||||
response = self.client.get('/item/1')
|
||||
res_json = json.loads(response.data.decode('utf-8'))
|
||||
expected_path = self.path_prefix + os.sep \
|
||||
+ os.path.join(b'path_1').decode('utf-8')
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(res_json['path'], os.path.join(os.sep, u'path_1'))
|
||||
self.assertEqual(res_json['path'], expected_path)
|
||||
|
||||
web.app.config['INCLUDE_PATHS'] = False
|
||||
|
||||
|
|
@ -63,10 +83,11 @@ class WebPluginTest(_common.LibTestCase):
|
|||
web.app.config['INCLUDE_PATHS'] = True
|
||||
response = self.client.get('/album/2')
|
||||
res_json = json.loads(response.data.decode('utf-8'))
|
||||
expected_path = self.path_prefix + os.sep \
|
||||
+ os.path.join(b'somewhere2', b'art_path_2').decode('utf-8')
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(res_json['artpath'],
|
||||
os.path.join(os.sep, u'somewhere2', u'art_path_2'))
|
||||
self.assertEqual(res_json['artpath'], expected_path)
|
||||
|
||||
web.app.config['INCLUDE_PATHS'] = False
|
||||
|
||||
|
|
@ -180,11 +201,14 @@ class WebPluginTest(_common.LibTestCase):
|
|||
u'and a third')
|
||||
|
||||
def test_query_item_path(self):
|
||||
# """ testing item query: path:\somewhere """
|
||||
# """ testing item query: path:\somewhere\a """
|
||||
""" Note: path queries are special: the query item must match the path
|
||||
from the root all the way to a directory, so this matches 1 item """
|
||||
""" Note: filesystem separators in the query must be '\' """
|
||||
response = self.client.get('/item/query/path:\\somewhere\\a')
|
||||
|
||||
response = self.client.get('/item/query/path:'
|
||||
+ self.path_prefix
|
||||
+ '\\somewhere\\a')
|
||||
res_json = json.loads(response.data.decode('utf-8'))
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
|
|
|||
Loading…
Reference in a new issue