Maybe fix code and tests for Windows

This commit is contained in:
Steve Johnson 2017-01-14 20:40:30 -08:00
parent e2be6ba781
commit e3707e45f3
2 changed files with 9 additions and 4 deletions

View file

@ -176,11 +176,16 @@ class QueryConverter(PathConverter):
return ','.join(value)
class EverythingConverter(PathConverter):
regex = '.*?'
# Flask setup.
app = flask.Flask(__name__)
app.url_map.converters['idlist'] = IdListConverter
app.url_map.converters['query'] = QueryConverter
app.url_map.converters['everything'] = EverythingConverter
@app.before_request
@ -221,9 +226,9 @@ def item_query(queries):
return g.lib.items(queries)
@app.route('/item/path/<path:path>')
@app.route('/item/path/<everything:path>')
def item_at_path(path):
query = beets.library.PathQuery('path', b'/' + path.encode('utf-8'))
query = beets.library.PathQuery('path', path.encode('utf-8'))
item = g.lib.items(query).get()
if item:
return flask.jsonify(_rep(item))

View file

@ -79,7 +79,7 @@ class WebPluginTest(_common.LibTestCase):
def test_get_single_item_by_path(self):
data_path = os.path.join(_common.RSRC, b'full.mp3')
self.lib.add(Item.from_path(data_path))
response = self.client.get('/item/path' + data_path.decode('utf-8'))
response = self.client.get('/item/path/' + data_path.decode('utf-8'))
response.json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
@ -89,7 +89,7 @@ class WebPluginTest(_common.LibTestCase):
data_path = os.path.join(_common.RSRC, b'full.mp3')
# data_path points to a valid file, but we have not added the file
# to the library.
response = self.client.get('/item/path' + data_path.decode('utf-8'))
response = self.client.get('/item/path/' + data_path.decode('utf-8'))
self.assertEqual(response.status_code, 404)