Skip to content
This repository has been archived by the owner on May 28, 2022. It is now read-only.

Commit

Permalink
Updates HTTPError calls to changes on master
Browse files Browse the repository at this point in the history
  • Loading branch information
FranciscoCanas committed Nov 30, 2014
1 parent ee2e704 commit 6911125
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ def create_profile():
pattern = '^\w+$'
profile_name = request.form['name']
if not re.match(pattern, profile_name):
raise HTTPError('Invalid Profile Name: {}'.format(profile_name), 400)
raise HTTPError(400, 'Invalid Profile Name: {}'.format(profile_name))

try:
settings.profile_manager.create(profile_name)
except ProfileAlreadyExists:
raise HTTPError('Profile Already Exists', 400)
raise HTTPError(400, 'Profile Already Exists')
return ''


Expand All @@ -119,7 +119,7 @@ def delete_profile(profile):
try:
settings.profile_manager.delete(profile)
except ProfileDoesNotExist:
HTTPError('Profile Does Not Exist', 400)
HTTPError(400, 'Profile Does Not Exist')
return ''


Expand Down
14 changes: 7 additions & 7 deletions src/freeseer/frontend/controller/configuration/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def map_plugin_name(plugin):
try:
name = plugin_names_map[plugin]
except KeyError:
raise HTTPError('Invalid Plugin Name: {}'.format(plugin), 400)
raise HTTPError(400, 'Invalid Plugin Name: {}'.format(plugin))
return name


Expand All @@ -67,7 +67,7 @@ def map_plugin_category(category):
try:
category = plugin_types_map[category]
except KeyError:
raise HTTPError('Invalid Plugin Category: {}'.format(category), 400)
raise HTTPError(400, 'Invalid Plugin Category: {}'.format(category))
return category


Expand All @@ -89,9 +89,9 @@ def update_config(config, data):
value = opt_instance.decode(value)
setattr(config, key, value)
except KeyError:
raise HTTPError('Invalid Option: {}'.format(key), 400)
raise HTTPError(400, 'Invalid Option: {}'.format(key))
except InvalidOptionValueError:
raise HTTPError('Invalid Value {} for option {}'.format(value, key), 400)
raise HTTPError(400, 'Invalid Value {} for option {}'.format(value, key))
config.save()


Expand Down Expand Up @@ -148,7 +148,7 @@ def load_profile(profile):
try:
profile = settings.profile_manager.get(profile, create_if_needed=False)
except ProfileDoesNotExist:
raise HTTPError('Profile Does Not Exist', 404)
raise HTTPError(404, 'Profile Does Not Exist')
return profile


Expand All @@ -170,7 +170,7 @@ def get_plugin_config(profile, category, plugin, id):
plugin_class = plugin_manager.get_plugin_by_name(map_plugin_name(plugin),
map_plugin_category(category))
if not plugin_class:
raise HTTPError('No plugin {} of type {}'.format(plugin, category), 400)
raise HTTPError(400, 'No plugin {} of type {}'.format(plugin, category))

plugin_object = plugin_class.plugin_object
plugin_class.plugin_object.set_instance(id)
Expand Down Expand Up @@ -201,7 +201,7 @@ def get_plugin_instance_uids(profile, category, plugin):
plugin_class = plugin_manager.get_plugin_by_name(map_plugin_name(plugin),
map_plugin_category(category))
if not plugin_class:
raise HTTPError('No plugin {} of type {}'.format(plugin, category), 400)
raise HTTPError(400, 'No plugin {} of type {}'.format(plugin, category))

storage = profile_instance.get_storage('plugin.conf')
parser = ConfigParser.ConfigParser()
Expand Down
14 changes: 6 additions & 8 deletions src/freeseer/tests/frontend/controller/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ def test_create_profile(self, test_client):
assert new_profile

def test_create_profile_invalid_args(self, test_client):
response = test_client.post('/profiles', data={'name': '$%@DN@'})
response = test_client.post('/profiles', data={'name': '12@345'})
data = json.loads(response.data)
assert response.status_code == 400
assert data['error_message'] == 'Invalid Profile Name: $%@DN@'
assert data['description'] == 'Invalid Profile Name: 12@345'

def test_create_profile_already_exists(self, test_client):
response = test_client.post('/profiles',
Expand Down Expand Up @@ -142,10 +142,8 @@ def test_modify_profile_invalid_option(self, test_client):
'not_a_real_option': True
})
response_data = json.loads(response.data)
assert response_data == {
'error_message': 'Invalid Option: not_a_real_option',
'error_code': 400
}
assert response_data['description'] == 'Invalid Option: not_a_real_option'
assert response_data['error_code'] == 400

def test_view_general_configuration(self, test_client, configuration):
response = test_client.get('/profiles/testing/general')
Expand Down Expand Up @@ -244,13 +242,13 @@ def test_view_plugin_instance(self, test_client, configuration):
def test_view_invalid_plugin_name(self, test_client, configuration):
response = test_client.get('/profiles/testing/recording/audioinput/fakeaudiosource/0')
data = json.loads(response.data)
assert data['error_message'] == 'Invalid Plugin Name: fakeaudiosource'
assert data['description'] == 'Invalid Plugin Name: fakeaudiosource'
assert response.status_code == 400

def test_view_invalid_plugin_category(self, test_client, configuration):
response = test_client.get('/profiles/testing/recording/fakeinput/jackaudiosource/0')
data = json.loads(response.data)
assert data['error_message'] == 'Invalid Plugin Category: fakeinput'
assert data['description'] == 'Invalid Plugin Category: fakeinput'
assert response.status_code == 400

def test_create_plugin_instance(self, test_client, configuration):
Expand Down

0 comments on commit 6911125

Please sign in to comment.