Пример #1
0
    def test_log(self):
        log = Log('fireflash', 'test')
        db_session.add(log)
        db_session.commit()

        log = Log.query.filter(Log.name=='fireflash').one()
        assert log.message == 'test'
Пример #2
0
    def test_log_on_item_insert(self):
        item = Item('fireflash')
        db_session.add(item)
        db_session.commit()

        logs = Log.find_all()
        assert len(logs) == 1
        assert logs[0].name == 'fireflash'
Пример #3
0
    def create_simple_setup(self):
        item = Item('firefly')
        db_session.add(item)
        db_session.commit()

        tag = Tag('laptop')
        db_session.add(tag)
        db_session.commit()
Пример #4
0
    def test_log_on_variable(self):
        item = Item('fireflash')
        item.set_variable('hello', 'world')
        db_session.add(item)
        db_session.commit()

        logs = Log.find_all()
        assert len(logs) == 2
        assert 'hello' in logs[0].message or 'hello' in logs[1].message
Пример #5
0
    def test_user(self):
        admin = User('admin')
        admin.password = '******'
        db_session.add(admin)
        db_session.commit()

        admin = User.query.filter(User.name=='admin').one()
        assert admin.authenticate('123456')
        assert admin.authenticate('12345') == False
Пример #6
0
    def test_remove_tag_from_item(self):
        self.test_add_tag_to_item()

        item = Item.query.filter(Item.name=='firefly').one()
        tag = Tag.query.filter(Tag.name=='laptop').one()
        item.tags.remove(tag)
        db_session.add(item)
        db_session.commit()

        assert item not in tag.items
Пример #7
0
    def test_add_tag_to_item(self):
        self.create_simple_setup()
        item = Item.query.filter(Item.name=='firefly').one()
        tag = Tag.query.filter(Tag.name=='laptop').one()

        item.tags.append(tag)
        db_session.add(item)
        db_session.commit()

        assert item in tag.items
Пример #8
0
    def test_log_order(self):
        now = datetime.utcnow()
        earlier = now - timedelta(1)
        log2 = Log('firefly', 'test2', earlier)
        log1 = Log('fireflash', 'test1', now)
        db_session.add(log1)
        db_session.add(log2)
        db_session.commit()

        logs = Log.find_all()
        assert logs[0].message == 'test1'
Пример #9
0
    def test_tag_variable(self):
        self.create_simple_setup()

        item = Item.query.filter(Item.name=='firefly').one()
        tag = Tag.query.filter(Tag.name=='laptop').one()
        tag.set_variable('hello', 'world')
        tag.items.append(item)
        db_session.add(tag)
        db_session.commit()

        assert 'hello' not in item.variables
        assert 'hello' in item.get_all_variables()
Пример #10
0
    def test_remove_item_variables(self):
        self.create_simple_setup()
        item = Item.query.filter(Item.name=='firefly').one()
        item.set_variable('hello', 'world')
        db_session.add(item)
        db_session.commit()

        item.remove_variable('hello')
        db_session.add(item)
        db_session.commit()

        assert 'hello' not in item.variables
Пример #11
0
    def test_item_variable(self):
        self.create_simple_setup()

        item = Item.query.filter(Item.name=='firefly').one()
        item.set_variable('hello', 'world')
        item.set_variable('mylist', ['a', 'b'])
        item.set_variable('mydict', {'hello': 'world'})
        db_session.add(item)
        db_session.commit()

        vars = item.variables
        assert vars['hello'] == 'world'
        assert vars['mylist'] == ['a', 'b']
        assert vars['mydict'] == {'hello': 'world'}
Пример #12
0
    def test_avoid_duplicate_tag(self):
        self.create_simple_setup()

        item = Item.query.filter(Item.name=='firefly').one()
        tag = Tag.query.filter(Tag.name=='laptop').one()
        tag.items.append(item)
        db_session.add(tag)
        db_session.commit()

        tag.items.append(item)
        db_session.add(tag)
        db_session.commit()

        assert len(tag.items) == 1
Пример #13
0
    def test_parent_child(self):
        i1 = Item('firefly')
        i2 = Item('fireflash')
        i3 = Item('home')
        db_session.add(i1)
        db_session.add(i2)
        db_session.add(i3)
        db_session.commit()

        i3.children.append(i1)
        i3.children.append(i2)
        db_session.add(i3)
        db_session.commit()

        assert i3.children == [i1, i2]
        assert i1.parents == [i3]