예제 #1
0
    def test_update_a_risk_type_with_no_authorization_succeeds(
            self, client, init_db):
        """
        Args:
            client(FlaskClient): fixture to get flask test client
            init_db(SQLAlchemy): fixture to initialize the test database
        """
        payload = {
            'name' : fake.industry(),
            'customAttributes' : [
                {
                    "label": "brand",
                    "isRequired": True,
                    "inputControl": "text",
                    'key': 'brand',
                }, 
                {
                    "label": "color",
                    "isRequired": True,
                    "inputControl": "dropdown",
                    "choices": ["blue", "red", "black"],
                    'key': 'color'
                }
            ] 
        }

        response = client.put(
            f'{BASE_URL}/risk-types/29293', 
            data=json.dumps(payload),
            content_type='application/json')
        data = json.loads(response.data.decode())
        assert response.status_code == 401
        assert data['status'] == 'error'
        assert data['message'] == ERROR_MESSAGES['JWT_INVALID_TOKEN']
예제 #2
0
    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()
예제 #3
0
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()
예제 #4
0
    def test_create_risk_type_with_valid_data_succeeds(
            self, client, init_db, user_one):
        """
        Parameters:
            client(FlaskClient): fixture to get flask test client
            init_db(SQLAlchemy): fixture to initialize the test database
            user_one (User): Fixture to create a new user
        """
        payload = {
            'name' : fake.industry(),
            'customAttributes' : [
                {
                    "label": "brand",
                    "isRequired": True,
                    "inputControl": "text",
                    'key': 'brand',
                }, 
                {
                    "label": "color",
                    "isRequired": True,
                    "inputControl": "dropdown",
                    "choices": ["blue", "red", "black"],
                    'key': 'color'
                }
            ] 
        }

        response = client.post(
            f'{BASE_URL}/risk-types', 
            data=json.dumps(payload),
            headers=dict(
                Authorization=f'Bearer {user_one.token}'
            ),
            content_type='application/json')
            
        data = json.loads(response.data.decode())
        assert response.status_code == 201
        assert data['status'] == 'success'
        assert data['message'] == SUCCESS_MESSAGES['RISK_TYPE_CREATED']
예제 #5
0
def new_risk_type(app, new_company):
    params = {'name': fake.industry(), 'company_id': new_company.id}
    risk_type = RiskType(**params)
    return risk_type.save()
예제 #6
0
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())