def new_risk_type_with_attribute1(app, new_company): params = {'name': fake.industry(), 'company_id': new_company.id} risk_type = RiskType(**params) risk_type = risk_type.save() attribute = Attribute(_key='branch', label='branch', is_required=False, input_control='text', choices='choice') risk_type.attributes.append(attribute) return risk_type.save()
def test_save(self, init_db, new_company): """ Test for creating a new risk-type Args: init_db(SQLAlchemy): fixture to initialize the test database new_company (Company): Fixture to create a new company """ params = {'name': fake.industry(), 'company_id': new_company.id} risk_type = RiskType(**params) assert risk_type == risk_type.save()
def post(self): """ POST method for creating risk-types. Payload should have the following parameters: name(str): name of the risk-type """ request_data = request.get_json() request_data['companyId'] = request.decoded_token.get('sub').get( 'company')['id'] risk_type_schema = RiskTypeSchema() risk_type_data = risk_type_schema.load_object_into_schema(request_data) risk_type = RiskType(**risk_type_data) attributes_data = request_data.get('customAttributes') if attributes_data: attributes_schema = AttributeSchema(many=True, exclude=['id']) attributes = attributes_schema.load_object_into_schema( attributes_data) risk_type.attributes = attributes attributes = attributes_schema.dump(attributes).data else: raise ValidationError( {'message': ERROR_MESSAGES['PROVIDE_CUSTOM_ATTRIBUTES']}) risk_type = risk_type.save() return { 'status': 'success', 'message': SUCCESS_MESSAGES['RISK_TYPE_CREATED'], 'data': risk_type_schema.dump(risk_type).data }, 201
def new_risk_type(app, new_company): params = {'name': fake.industry(), 'company_id': new_company.id} risk_type = RiskType(**params) return risk_type.save()
def new_multiple_risk_types(app, new_company): risk_types = [] for each in range(2): params = {'name': fake.industry(), 'company_id': new_company.id} risk_type = RiskType(**params) risk_types.append(risk_type.save())