def test_get_asset_category_attributes_with_valid_id(
            self, init_db, client, auth_header):
        """Should return attributes of an asset category"""

        asset_category = AssetCategory(name='HD Screen')
        asset_category.save()
        choices = ['red', 'blue']
        attributes = Attribute(label='color',
                               _key='color',
                               is_required=False,
                               input_control='text-area',
                               choices=','.join(choices),
                               asset_category_id=asset_category.id)
        attributes.save()

        response = client.get(
            f'{api_base_url_v1}/asset-categories/{asset_category.id}/'
            f'attributes',
            headers=auth_header)
        response_json = json.loads(response.data.decode(CHARSET))

        assert response.status_code == 200
        assert response_json['status'] == 'success'
        assert response_json['data']['name'] == 'HD Screen'
        assert type(response_json['data']['customAttributes']) == list
        assert len(response_json['data']['customAttributes']) == 1
        assert response_json['data']['customAttributes'][0]['label'] == 'color'
        assert response_json['data']['customAttributes'][0][
            'inputControl'] == 'text-area'
        assert response_json['data']['customAttributes'][0][
            'choices'] == choices
        assert response_json['data']['customAttributes'][0][
            'isRequired'] == False
Beispiel #2
0
def new_attribute(app, new_risk_type):
    params = dict(_key='model',
                  label='model',
                  is_required=True,
                  input_control='text',
                  choices=None,
                  risk_type_id=new_risk_type.id)
    attribute = Attribute(**params)
    return attribute.save()
Beispiel #3
0
    def test_update_asset_category_with_attribute(  #pylint: disable=R0201,C0103
            self,
            client,
            init_db,  #pylint: disable=W0613
            auth_header):
        """
        Test to Update an asset category with an attribute
        """
        asset_category = AssetCategory(name="TestLaptop")
        attribute_data = valid_asset_category_data["customAttributes"][0]
        attribute_data["_key"] = attribute_data["key"]
        attribute_data["is_required"] = attribute_data["isRequired"]
        attribute_data["input_control"] = attribute_data["inputControl"]
        attribute_data.__delitem__("key")
        attribute_data.__delitem__("isRequired")
        attribute_data.__delitem__("inputControl")
        attribute = Attribute(**attribute_data)
        asset_category.attributes.append(attribute)
        asset_category.save()

        attribute_data["id"] = attribute.id
        data = json.dumps({"attributes": [attribute_data]})

        response = client.patch(
            f'{api_v1_base_url}/asset-categories/{asset_category.id}',
            headers=auth_header,
            data=data)

        response_json = json.loads(response.data.decode(CHARSET))

        assert response.status_code == 200
        assert response_json["status"] == "success"
        assert len(response_json["data"]["customAttributes"]) > 0
Beispiel #4
0
 def test_save(self, init_db, new_risk_type):
     """Test for creating a new attribute
     
         Args:
             init_db(SQLAlchemy): fixture to initialize the test database
             new_risk_type (RiskType): Fixture to create a new risk type
     """
     attribute = Attribute(
         _key='serial_number',
         label='serial_number',
         is_required=False,
         input_control='text',
         choices=None)
     new_risk_type.attributes.append(attribute)
     new_risk_type.save()
     assert attribute == attribute.save()
Beispiel #5
0
 def test_get(self, init_db, new_attribute):
     """Test for get method
     
         Args:
             init_db(SQLAlchemy): fixture to initialize the test database
             new_attribute (RiskType): Fixture to create a new risk type
     """
     assert Attribute.get(new_attribute.id) == new_attribute
Beispiel #6
0
    def create_attribute(self, data):
        """Return attribute object after successful loading into schema"""

        # When updating, `label` may not be provided in request's body.
        if data.get('_key'):
            data['_key'] = case(data['_key'])

        if not data.get('id'):
            return Attribute(**data)
        return data
    def test_export_asset_category_as_csv_success(self, init_db, client,
                                                  auth_header):
        """
        Should return csv data file with asset categories names and the assets
        count in each category
        """

        asset_category = AssetCategory(name='HD Screen')
        asset_category.save()
        attributes = Attribute(label='color',
                               _key='color',
                               is_required=False,
                               input_control='text-area',
                               choices='multiple choices',
                               asset_category_id=asset_category.id)
        attributes.save()

        response = client.get(f'{api_base_url_v1}/asset-categories/export',
                              headers=auth_header)

        assert response.status_code == 200
        assert response.headers['Content-Type'] == 'text/csv'
        assert b'name,assets_count\r\nHD Screen,0\r\n' in response.data
Beispiel #8
0
    def create_attribute(self, data):
        """Return attribute object after successful loading into schema"""

        data['_key'] = case(data['_key'])

        return Attribute(**data)