Пример #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()
Пример #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
Пример #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
Пример #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
Пример #5
0
def multiple_categories():
    """
    Create the asset category records for testing
    """
    categories = ['Laptop', 'Chromebook', 'Apple']

    for category in categories:
        db.session.add(AssetCategory(name=category))

    db.session.commit()
Пример #6
0
def new_asset_category(app):
    params = {'name': 'Laptop'}
    asset_category = AssetCategory(**params)
    return asset_category
 def test_get(self, new_asset_category):
     assert AssetCategory.get(new_asset_category.id) == new_asset_category
Пример #8
0
def seed_asset():
    # Apple tv assets
    apple_tv_category = AssetCategory._query().filter_by(
        name='Apple TV').first()
    custom_attributes = {
        'color': 'red',
        'warranty': '2019-02-08',
        'size': '13.3inches'
    }
    apple_tv_assets_data = [{
        'tag': 'AND/345/EWRD',
        'serial': 'GRGR334TGD',
        'asset_category_id': apple_tv_category.id,
        'custom_attributes': custom_attributes
    }, {
        'tag': 'AND/654/FWED',
        'serial': 'SDW435OOJD',
        'asset_category_id': apple_tv_category.id,
        'custom_attributes': custom_attributes
    }, {
        'tag': 'AND/234/FJAD',
        'serial': 'JHDHG23JJD',
        'asset_category_id': apple_tv_category.id,
        'custom_attributes': custom_attributes
    }, {
        'tag': 'AND/345/AFWD',
        'serial': 'AFWEF34OFD',
        'asset_category_id': apple_tv_category.id,
        'custom_attributes': custom_attributes
    }]

    apple_tv_assets = [
        Asset(tag=data['tag'],
              serial=data.get('serial'),
              asset_category_id=data['asset_category_id'],
              custom_attributes=data['custom_attributes'])
        for data in apple_tv_assets_data
    ]

    for asset in apple_tv_assets:
        asset.save()

    # Chromebooks assets
    chromebooks_category = AssetCategory._query().filter_by(
        name='ChromeBooks').first()
    chromebooks_assets_data = [{
        'tag': 'AND/3235/ERR',
        'serial': 'NBA220FWE',
        'asset_category_id': chromebooks_category.id,
        'custom_attributes': {
            'warranty': '2019-02-08'
        }
    }, {
        'tag': 'AND/634/FHE',
        'serial': 'NTW456RGR',
        'asset_category_id': chromebooks_category.id,
        'custom_attributes': {
            'warranty': '2019-02-08'
        }
    }, {
        'tag': 'AND/246/TRA',
        'serial': 'JAA556EGR',
        'asset_category_id': chromebooks_category.id,
        'custom_attributes': {
            'warranty': '2019-02-08'
        }
    }, {
        'tag': 'AND/875/HJR',
        'serial': 'AWF232EGG',
        'asset_category_id': chromebooks_category.id,
        'custom_attributes': {
            'warranty': '2019-02-08'
        }
    }]

    chromebooks_assets = [
        Asset(tag=data['tag'],
              serial=data.get('serial'),
              custom_attributes=data['custom_attributes'],
              asset_category_id=data['asset_category_id'])
        for data in chromebooks_assets_data
    ]

    for asset in chromebooks_assets:
        asset.save()

    # Laptops assets
    laptops_category = AssetCategory._query().filter_by(name='Laptops').first()
    laptops_asset_data = [{
        'tag': 'AND/K32/001',
        'serial': 'KDJS43JN432LP',
        'asset_category_id': laptops_category.id,
        'custom_attributes': {
            'warranty': '2019-02-08'
        }
    }, {
        'tag': 'AND/K32/002',
        'serial': 'KDJS43JN432LP',
        'asset_category_id': laptops_category.id,
        'custom_attributes': {
            'warranty': '2019-02-08'
        }
    }, {
        'tag': 'AND/K32/003',
        'serial': 'KDJS43JN432LP',
        'asset_category_id': laptops_category.id,
        'custom_attributes': {
            'warranty': '2019-02-08'
        }
    }, {
        'tag': 'AND/K32/004',
        'serial': 'KDJS43JN432LP',
        'asset_category_id': laptops_category.id,
        'custom_attributes': {
            'warranty': '2019-02-08'
        }
    }, {
        'tag': 'AND/K32/005',
        'serial': 'KDJS43JN432LP',
        'asset_category_id': laptops_category.id,
        'custom_attributes': {
            'warranty': '2019-02-08'
        }
    }]

    laptops_asset = [
        Asset(tag=data['tag'],
              serial=data.get('serial'),
              custom_attributes=data['custom_attributes'],
              asset_category_id=data['asset_category_id'])
        for data in laptops_asset_data
    ]

    for asset in laptops_asset:
        asset.save()
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()