Beispiel #1
0
def asset_with_attrs():  #pylint: disable=C0103
    """Test asset with no custom attributes."""
    category = AssetCategory(name="Test Category")
    category = category.save()

    attributes = [{
        '_key': 'waranty',
        'label': 'waranty',
        'is_required': True,
        'asset_category_id': category.id,
        'input_control': 'Text'
    }, {
        '_key': 'length',
        'label': 'length',
        'input_control': 'Text',
        'asset_category_id': category.id,
        'is_required': False
    }]

    for attribute in attributes:
        db.session.add(Attribute(**attribute))  #pylint: disable=E1101
    db.session.commit()  #pylint: disable=E1101

    ASSET_VALID_CUSTOM_ATTRS['asset_category_id'] = category.id
    asset = Asset(**ASSET_VALID_CUSTOM_ATTRS)
    return asset.save()
Beispiel #2
0
def new_asset_category_with_deleted_asset(app, request_ctx,
                                          mock_request_obj_decoded_token):
    """Fixture for asset category with a deleted child asset."""
    asset_category = AssetCategory(name='Laptop1')
    asset_category = asset_category.save()

    asset = Asset(tag='abd', serial='def', asset_category_id=asset_category.id)

    asset = asset.save()
    asset.delete()

    return asset_category
Beispiel #3
0
def test_asset_category(app):
    asset_category = AssetCategory(name='Laptop100')
    asset_category = asset_category.save()
    attribute_one = Attribute(_key='waranty',
                              label='waranty',
                              is_required=True,
                              input_control='Text')
    attribute_two = Attribute(_key='length',
                              label='length',
                              is_required=False,
                              input_control='Text')
    asset_category.attributes.append(attribute_one)
    asset_category.attributes.append(attribute_two)

    return asset_category
Beispiel #4
0
def new_asset_category_with_non_deleted_asset(app):
    """
    The module scope is used here to prevent a test module data leaking into
    another.

    Fixture for asset category with a non deleted child asset.
    """

    asset_category = AssetCategory(name='Laptop0')
    asset_category = asset_category.save()

    asset = Asset(tag='abc', serial='def', asset_category_id=asset_category.id)

    asset = asset.save()

    return asset_category
def seed_asset_category():
    # Create apple tv asset category and its attributes
    apple_tv = AssetCategory(name='Apple TV')
    apple_tv_attributes_data = [{
        '_key': 'warranty',
        'label': 'Warranty',
        'is_required': False,
        'input_control': 'text'
    }, {
        '_key': 'size',
        'label': 'Size',
        'is_required': False,
        'input_control': 'dropdown',
        'choices': 'multiple choices'
    }]

    apple_tv_attributes = [
        Attribute(_key=data['_key'],
                  label=data['label'],
                  is_required=data['is_required'],
                  input_control=data['input_control'],
                  choices=data.get('choices'))
        for data in apple_tv_attributes_data
    ]

    for attribute in apple_tv_attributes:
        apple_tv.attributes.append(attribute)

    apple_tv.save()

    # Create laptops asset category and its attributes
    laptops = AssetCategory(name='Laptops')
    laptops_attribute_data = [{
        '_key': 'color',
        'label': 'Color',
        'is_required': False,
        'input_control': 'dropdown',
        'choices': 'multiple choices'
    }, {
        '_key': 'length',
        'label': 'Length',
        'is_required': False,
        'input_control': 'text'
    }]

    laptops_attribute = [
        Attribute(_key=data['_key'],
                  label=data['label'],
                  is_required=data['is_required'],
                  input_control=data['input_control'],
                  choices=data.get('choices'))
        for data in laptops_attribute_data
    ]

    for attribute in laptops_attribute:
        laptops.attributes.append(attribute)

    laptops.save()

    # Create USB dongles asset category and its attributes
    usb_dongles = AssetCategory(name='USB Dongles')
    usb_dongles_attributes_data = [{
        '_key': 'color',
        'label': 'Color',
        'is_required': False,
        'input_control': 'dropdown',
        'choices': 'multiple choices'
    }, {
        '_key': 'length',
        'label': 'Length',
        'is_required': False,
        'input_control': 'text-area'
    }]

    usb_dongles_attributes = [
        Attribute(_key=data['_key'],
                  label=data['label'],
                  is_required=data['is_required'],
                  input_control=data['input_control'],
                  choices=data.get('choices'))
        for data in usb_dongles_attributes_data
    ]

    for attribute in usb_dongles_attributes:
        usb_dongles.attributes.append(attribute)

    usb_dongles.save()

    # Create chromebooks asset category and its attributes
    chromebooks = AssetCategory(name='ChromeBooks')
    chromebooks_attributes_data = [{
        '_key': 'color',
        'label': 'Color',
        'is_required': True,
        'input_control': 'text-area',
        'choices': 'multiple choices'
    }, {
        '_key': 'screenSize',
        'label': 'Screen size',
        'is_required': True,
        'input_control': 'text'
    }]

    chromebooks_attributes = [
        Attribute(_key=data['_key'],
                  label=data['label'],
                  is_required=data['is_required'],
                  input_control=data['input_control'],
                  choices=data.get('choices'))
        for data in chromebooks_attributes_data
    ]

    for attribute in chromebooks_attributes:
        chromebooks.attributes.append(attribute)

    chromebooks.save()

    # Create chairs asset category and its attributes
    chairs = AssetCategory(name='Chairs')
    chairs_attributes_data = [{
        '_key': 'type',
        'label': 'Type',
        'is_required': True,
        'input_control': 'radio button',
        'choices': 'multiple choices'
    }]

    chairs_attributes = [
        Attribute(_key=data['_key'],
                  label=data['label'],
                  is_required=data['is_required'],
                  input_control=data['input_control'],
                  choices=data.get('choices'))
        for data in chairs_attributes_data
    ]

    for attribute in chairs_attributes:
        chairs.attributes.append(attribute)

    chairs.save()