Example #1
0
def new_risk(app, new_company, new_risk_type):
    params = {
        'data': {
            'firstName' : fake.first_name()
        },
        'company_id' : new_company.id,
        'risk_type_id' : new_risk_type.id
    }
    risk = Risk(**params)
    return risk.save()
Example #2
0
def new_multiple_risks(app, new_company, new_risk_type1):
    risks = []
    for each in range(3):
        params = {
            'data': {
                'firstName' : fake.first_name()
            },
            'company_id' : new_company.id,
            'risk_type_id' : new_risk_type1.id
        }
        risk = Risk(**params)
        risks.append(risk.save())
    return risks
Example #3
0
 def test_save(self, init_db, new_company, new_risk_type):
     """Test for creating a new risk
     
         Args:
             init_db(SQLAlchemy): fixture to initialize the test database
             new_company (Company): Fixture to create a new company
             new_risk_type (RiskType): Fixture to create a new risk type
     """
     params = {
         'data': {},
         'risk_type_id': new_risk_type.id,
         'company_id': new_company.id
     }
     risk = Risk(**params)
     assert risk == risk.save()
Example #4
0
 def test_get(self, init_db, new_risk):
     """Test for get method
     
         Args:
             init_db(SQLAlchemy): fixture to initialize the test database
             new_risk (Risk): Fixture to create a new risk
     """
     assert Risk.get(new_risk.id) == new_risk
Example #5
0
    def post(self):
        """
        POST method for creating risks.

        """
        request_data = request.get_json()

        request_data['companyId'] = request.decoded_token.get('sub').get(
            'company')['id']

        risk_schema = RiskSchema()
        risk_data = risk_schema.load_object_into_schema(request_data)

        risk = Risk(**risk_data)

        risk = risk.save()

        return {
            'status': 'success',
            'message': SUCCESS_MESSAGES['CREATED'].format('Risk'),
            'data': risk_schema.dump(risk).data
        }, 201
Example #6
0
    def get(self):
        """
        Gets risks list
        """
        risks = Risk.filter()

        risk_schema = RiskSchema(many=True)

        return (
            {
                "data": risk_schema.dump(risks).data,
                "message": SUCCESS_MESSAGES["FETCHED"].format("Risks"),
                "status": "success",
            },
            200,
        )