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

Commit

Permalink
Merge pull request #96 from oleduc/develop
Browse files Browse the repository at this point in the history
Fix config.registry.auth_model missing properties crashing the server on startup
  • Loading branch information
postatum committed Nov 18, 2015
2 parents 97e78ca + 82ebdd3 commit 9f4abc9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
7 changes: 4 additions & 3 deletions ramses/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,14 @@ def setup_data_model(config, raml_resource, model_name):
:param model_name: String representing model name.
"""
model_cls = get_existing_model(model_name)
if model_cls is not None:
return model_cls, False

schema = resource_schema(raml_resource)

if not schema:
raise Exception('Missing schema for model `{}`'.format(model_name))

if model_cls is not None:
return model_cls, schema.get('_auth_model', False)

log.info('Generating model class `{}`'.format(model_name))
return generate_model_cls(
config,
Expand Down
16 changes: 15 additions & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,30 @@ def test_prepare_relationship_resource_found(
models.prepare_relationship(config, 'Story', resource)
mock_set.assert_called_once_with(config, matching_res, 'Story')

@patch('ramses.models.resource_schema')
@patch('ramses.models.get_existing_model')
def test_setup_data_model_existing_model(self, mock_get):
def test_setup_data_model_existing_model(self, mock_get, mock_schema):
from ramses import models
config = Mock()
mock_get.return_value = 1
mock_schema.return_value = {"foo": "bar"}
model, auth_model = models.setup_data_model(config, 'foo', 'Bar')
assert not auth_model
assert model == 1
mock_get.assert_called_once_with('Bar')

@patch('ramses.models.resource_schema')
@patch('ramses.models.get_existing_model')
def test_setup_data_model_existing_auth_model(self, mock_get, mock_schema):
from ramses import models
config = Mock()
mock_get.return_value = 1
mock_schema.return_value = {"_auth_model": True}
model, auth_model = models.setup_data_model(config, 'foo', 'Bar')
assert auth_model
assert model == 1
mock_get.assert_called_once_with('Bar')

@patch('ramses.models.resource_schema')
@patch('ramses.models.get_existing_model')
def test_setup_data_model_no_schema(self, mock_get, mock_schema):
Expand Down

0 comments on commit 9f4abc9

Please sign in to comment.