Exemplo n.º 1
0
class System(Base):
    """ System """

    _name = 'system'

    id = Attribute(types=str)
    data = Attribute()
Exemplo n.º 2
0
class Action(Base):
    """ Action """

    _name = None

    id = Attribute(types=str)
    data = Attribute(types=dict)
Exemplo n.º 3
0
class Socket(Base):
    """ Socket """

    _name = 'sockets'

    id = Attribute(types=str)
    token = Attribute(types=str)
Exemplo n.º 4
0
class Track(Base):
    """ Track """

    _name = 'tracking'

    data = Attribute(types=dict)
    user = Attribute(default=0)
    context = Attribute(default=dict)
Exemplo n.º 5
0
class Job(Base):
    """ Job """

    _name = 'jobs'

    method = Attribute(types=str)
    users = Attribute(types=list)
    data = Attribute()
Exemplo n.º 6
0
 def test_new_attribute(self, new_asset_category, init_db):
     attribute = Attribute(
         _key='assignee',
         label='assignee',
         is_required=False,
         input_control='text-area',
         choices='choice'
     )
     new_asset_category.attributes.append(attribute)
     new_asset_category.save()
     assert attribute == attribute.save()
Exemplo n.º 7
0
 def test_get(self, new_asset_category):
     attribute = Attribute(
         _key='description',
         label='description',
         is_required=False,
         input_control='text-area',
         choices='choice'
     )
     new_asset_category.attributes.append(attribute)
     new_asset_category.save()
     attribute.save()
     assert Attribute.get(attribute.id) == attribute
    def test_attributes(self, new_asset_category):
        attribute = Attribute(
            _key='warranty',
            label='warranty',
            is_required=False,
            input_control='text-area',
            choices='choice'
        )

        new_asset_category.attributes.append(attribute)
        attribute.save()
        new_asset_category.save()
        assert new_asset_category.attributes[0] == attribute
Exemplo n.º 9
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
Exemplo n.º 10
0
class Post(Base):
    """ Post """

    _name = 'posts'
    _search_fields = {'title', 'data', 'tags'}

    reactions = Attribute(
        types=dict,
        default={
            'views': [],  # TODO: + UTM
            'likes': [],
            'reposts': [],
            'comments': [],
        })  # TODO: attributes
    cover = Attribute(types=str)
    tags = Attribute(types=list)
Exemplo n.º 11
0
class Review(Base):
    """ Review """

    _name = 'reviews'
    _search_fields = {'title', 'data'}

    network = Attribute(types=int, default=0)
Exemplo n.º 12
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()
Exemplo n.º 13
0
    def test_attributes(self, init_db, new_risk_type):
        """
            Test that a new risk-type gets associated with an 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='first_name',
                              label='first_name',
                              is_required=True,
                              input_control='text',
                              choices=None)

        new_risk_type.attributes.append(attribute)
        attribute.save()
        new_risk_type.save()
        assert new_risk_type.attributes[0] == attribute
Exemplo n.º 14
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()
Exemplo n.º 15
0
class Payment(Base):
    """ Payments data """

    _name = None

    id = Attribute(types=str)
    type = Attribute(types=str)
    card = Attribute(types=dict)
    frequency = Attribute(types=int, default=30)  # Days
    value = Attribute(types=int)
    currency = Attribute(types=str)
    discount = Attribute(types=float)
Exemplo n.º 16
0
    def setUpTestData(cls):
        cls.product1 = Product(name="iWatch",
                               price=399.99,
                               manufacturer="Apple",
                               product_type="Smartwatch")
        cls.product1.save()
        cls.product2 = Product(name="Logitech MX Mouse",
                               price=99.99,
                               manufacturer="Logitech",
                               product_type="Mouse")
        cls.product2.save()
        cls.product3 = Product(name="HP Laptop",
                               price=1299.99,
                               manufacturer="HP",
                               product_type="Laptop")
        cls.product3.save()

        cls.attribute1 = Attribute(type="Color", value="Red")
        cls.attribute1.save()
        cls.attribute2 = Attribute(type="Number Of Wheels", value="4")
        cls.attribute2.save()
        cls.attribute3 = Attribute(type="Backup camera", value="false")
        cls.attribute3.save()
        pass
Exemplo n.º 17
0
 def test_count(self):
     assert Attribute.count() == 1
Exemplo n.º 18
0
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()
Exemplo n.º 19
0
 def test_query(self):
     attribute_query = Attribute._query()
     assert attribute_query.count() == 1
     assert isinstance(attribute_query.all(), list)
Exemplo n.º 20
0
class User(Base):
    """ User """

    _name = 'users'
    _search_fields = {
        'login',
        'name',
        'surname',
        'title',
        'phone',
        'mail',
        'description',
        # 'actions',
    }

    # status:
    # 0 - deleted
    # 1 - blocked
    # 2 - unauthorized
    # 3 - authorized
    # 4 - has access to platform resources
    # 5 - supervisor
    # 6 - moderator
    # 7 - admin
    # 8 - owner

    login = Attribute(
        types=str,
        default=default_login,
        checking=check_login_uniq,
        pre_processing=process_lower,
    )
    password = Attribute(
        types=str,
        checking=check_password,
        processing=process_password,
    )
    # Personal info
    avatar = Attribute(types=str)
    name = Attribute(
        types=str,
        checking=check_name,
        processing=process_title,
    )
    surname = Attribute(
        types=str,
        checking=check_surname,
        processing=process_title,
    )
    title = Attribute(
        types=str,
        default=default_title,
    )
    phone = Attribute(
        types=int,
        checking=check_phone_uniq,
        pre_processing=pre_process_phone,
    )
    phone_verified = Attribute(types=bool, default=True)
    mail = Attribute(
        types=str,
        checking=check_mail_uniq,
        pre_processing=process_lower,
    )
    mail_verified = Attribute(types=bool, default=True)
    social = Attribute(types=list) # TODO: list[{}] # TODO: checking
    #
    description = Attribute(types=str)
    language = Attribute(
        types=int,
        default=0,
        pre_processing=get_language,
    )
    status = Attribute(types=int, default=default_status)
    actions = Attribute(types=list) # TODO: list[dict]
    rating = Attribute(types=float)
    # global_channel = Attribute(types=int, default=1)
    # channels = Attribute(types=list)
    discount = Attribute(types=float)
    balance = Attribute(types=int, default=0)
    subscription = Attribute(types=int, default=0)
    utm = Attribute(types=str) # Source
    pay = Attribute(types=list) # Saved data for payment
    # Permissions
    mailing = Attribute(types=dict)
    # Cache
    last_online = Attribute(types=int)
Exemplo n.º 21
0
    def setUpClass(cls):
        super(WhenAddingNewAttributeTests, cls).setUpTestData()

        cls.attribute = Attribute(type="Color", value="Red")
        cls.before_save_attribute_count = Attribute.objects.count()
        cls.attribute.save()