mirror of
https://github.com/beetbox/beets.git
synced 2026-02-22 07:14:24 +01:00
Rename and invert new config option
This commit is contained in:
parent
a994df6aa6
commit
05bc4996a8
3 changed files with 19 additions and 11 deletions
|
|
@ -37,10 +37,10 @@ def _rep(obj, expand=False):
|
|||
out = dict(obj)
|
||||
|
||||
if isinstance(obj, beets.library.Item):
|
||||
if app.config.get('EXCLUDE_PATHS_FROM_ITEMS', True):
|
||||
del out['path']
|
||||
else:
|
||||
if app.config.get('INCLUDE_PATHS', False):
|
||||
out['path'] = out['path'].decode('utf-8')
|
||||
else:
|
||||
del out['path']
|
||||
|
||||
# Get the size (in bytes) of the backing file. This is useful
|
||||
# for the Tomahawk resolver API.
|
||||
|
|
@ -320,7 +320,7 @@ class WebPlugin(BeetsPlugin):
|
|||
'host': u'127.0.0.1',
|
||||
'port': 8337,
|
||||
'cors': '',
|
||||
'exclude_paths_from_items': True,
|
||||
'include_paths': False,
|
||||
})
|
||||
|
||||
def commands(self):
|
||||
|
|
@ -339,8 +339,8 @@ class WebPlugin(BeetsPlugin):
|
|||
# Normalizes json output
|
||||
app.config['JSONIFY_PRETTYPRINT_REGULAR'] = False
|
||||
|
||||
app.config['EXCLUDE_PATHS_FROM_ITEMS'] = (
|
||||
self.config.get('exclude_paths_from_items', True))
|
||||
app.config['INCLUDE_PATHS'] = (
|
||||
self.config.get('include_paths', False))
|
||||
|
||||
# Enable CORS if required.
|
||||
if self.config['cors']:
|
||||
|
|
|
|||
|
|
@ -63,8 +63,8 @@ configuration file. The available options are:
|
|||
Default: 8337.
|
||||
- **cors**: The CORS allowed origin (see :ref:`web-cors`, below).
|
||||
Default: CORS is disabled.
|
||||
- **exclude_paths_from_items**: The 'path' key of items is filtered out of JSON
|
||||
responses for security reasons. Default: true.
|
||||
- **include_paths**: If true, includes paths in item objects.
|
||||
Default: false.
|
||||
|
||||
Implementation
|
||||
--------------
|
||||
|
|
|
|||
|
|
@ -28,17 +28,25 @@ class WebPluginTest(_common.LibTestCase):
|
|||
|
||||
web.app.config['TESTING'] = True
|
||||
web.app.config['lib'] = self.lib
|
||||
web.app.config['EXCLUDE_PATHS_FROM_ITEMS'] = True
|
||||
web.app.config['INCLUDE_PATHS'] = False
|
||||
self.client = web.app.test_client()
|
||||
|
||||
def test_config_exclude_paths_from_items(self):
|
||||
web.app.config['EXCLUDE_PATHS_FROM_ITEMS'] = False
|
||||
def test_config_include_paths_true(self):
|
||||
web.app.config['INCLUDE_PATHS'] = True
|
||||
response = self.client.get('/item/1')
|
||||
response.json = json.loads(response.data.decode('utf-8'))
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.json['path'], u'/path_1')
|
||||
|
||||
def test_config_include_paths_false(self):
|
||||
web.app.config['INCLUDE_PATHS'] = False
|
||||
response = self.client.get('/item/1')
|
||||
response.json = json.loads(response.data.decode('utf-8'))
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertNotIn('path', response.json)
|
||||
|
||||
def test_get_all_items(self):
|
||||
response = self.client.get('/item/')
|
||||
response.json = json.loads(response.data.decode('utf-8'))
|
||||
|
|
|
|||
Loading…
Reference in a new issue