def __init__(self, schema=None, status=None): if isinstance(schema, dict): schema = Structure(schema) if schema and not schema.name: schema.name = 'response' self.schema = schema self.status = status
def test_missing_schema_field(self, client): """Tests failure when provided schema is missing a field from layout""" schema = Structure({ 'test_field1': Text(required=True), 'test_field2': Integer(required=True), }) layout = [{ 'title': 'Test Section 1', 'elements': [ { 'type': 'textbox', 'field': 'test_field1', 'label': 'Test Field #1', 'options': { 'multiline': True }, }, { 'type': 'textbox', 'field': 'test_field2', 'label': 'Test Field #2', }, { 'type': 'checkbox', 'field': 'test_field3', 'label': 'Test Field #3', }, ], }] with self.assertRaises(OperationError): WorkflowElement._verify_layout(layout, schema)
def construct(cls, resource, declaration): bases = declaration.__bases__ if isinstance(declaration, (type, ClassType)) and bases: params = cls._pull_request(resource, bases[0]) else: params = {} params.update(pull_class_dict(declaration, cls.ATTRS)) if 'responses' not in params: params['responses'] = {} schema = getattr(declaration, 'schema', None) if schema is not None: if isinstance(schema, dict): schema = Structure(schema) if not schema.name: schema.name = 'request' params['schema'] = schema fields = getattr(declaration, 'fields', None) if fields: if isinstance(params['schema'], Structure): structure = params['schema'].structure for name, field in fields.iteritems(): if isinstance(field, Field): if not field.name: field.name = name structure[name] = field elif field is None and name in structure: del structure[name] else: raise SpecificationError() responses = getattr(declaration, 'responses', {}) for status, response in responses.iteritems(): if not isinstance(response, Response): response = Response(response) response.status = status params['responses'][status] = response description = params.get('description') if not description and declaration.__doc__: params['description'] = dedent(declaration.__doc__) return cls(resource=resource, name=declaration.__name__, **params)
def test_parse_valid_layout(self, client): """Tests verification of a valid layout""" schema = Structure({'test_field1': Text(required=True)}) layout = [{ 'title': 'Test Section 1', 'elements': [{ 'type': 'textbox', 'field': 'test_field1', 'label': 'Test Field #1', 'options': { 'multiline': True }, }], }] WorkflowElement._verify_layout(layout, schema)
def construct(cls, resource, declaration): bases = declaration.__bases__ if isinstance(declaration, (type, ClassType)) and bases: params = cls._pull_request(resource, bases[0], declaration) else: params = {} params.update(pull_class_dict(declaration, cls.ATTRS)) if "responses" not in params: params["responses"] = {} schema = getattr(declaration, "schema", None) if schema is not None: if isinstance(schema, dict): for name, field in schema.items(): if isinstance(field, basestring): field = resource.schema.get(field) if field: schema[name] = field schema = Structure(schema) if not schema.name: schema.name = "request" params["schema"] = schema fields = getattr(declaration, "fields", None) if fields: if isinstance(params["schema"], Structure): structure = params["schema"].structure for name, field in fields.iteritems(): if isinstance(field, Field): if not field.name: field.name = name structure[name] = field elif isinstance(field, basestring): field = resource.schema.get(field) if field: if field.name != name: field = field.clone(name=name) structure[name] = field else: raise SpecificationError() elif field is None and name in structure: del structure[name] else: raise SpecificationError() responses = getattr(declaration, "responses", {}) for status, response in responses.iteritems(): if not isinstance(response, Response): response = Response(response) response.status = status params["responses"][status] = response description = params.get("description") if not description and declaration.__doc__: params["description"] = dedent(declaration.__doc__) metadata = getattr(declaration, "metadata", None) if metadata: if "metadata" in params: params["metadata"].update(metadata) else: params["metadata"] = metadata return cls(resource=resource, name=declaration.__name__, **params)