def add_field(endpoint_id, label, field_type, required='no', default=None, description=None): if field_type not in Globals.ACCEPTED_FIELD_TYPES: return { 'status': 'error', 'message': '%s is not accepted as a field type. Must be one of these: %s' % (field_type, Globals.ACCEPTED_FIELD_TYPES) } if required not in Globals.ACCEPTED_FIELD_REQUIRED: return { 'status': 'error', 'message': '%s is not accepted as a required parameter. Must be one of these: %s' % (required, Globals.ACCEPTED_FIELD_REQUIRED) } required = True if required == 'yes' else False new_id = CRUD.addEndpointField(endpoint_id, label, field_type, description=description, default=default, required=required, commit=True) if new_id: return { 'status': 'ok', 'message': 'Field %s was added' % label, 'id': new_id } else: return { 'status': 'error', 'message': 'Ooops! Something went wrong while adding Field %s' % label }
def context_field(mock_crud, context_endpoint): context = context_endpoint endpoint_id = context.get('endpoint_id') label = generate_random_string() type_field = generate_random_string() description = ' '.join([generate_random_string() for _ in range(5)]) default = generate_random_string() required = random.choice([True, False]) id = CRUD.addEndpointField( endpoint_id, label, type_field, description=description, default=default, required=required, commit=False ) context['field_id'] = id return context