Example #1
0
    def test_aspect(self):

        DataHelper.create_data_items(self, db)

        from cloud_on_film.files.picture import Picture

        file_test = Item.secure_query( self.user_id ) \
            .filter( Picture.aspect == 4 ) \
            .first()

        self.assertEqual(4, file_test.aspect)
        self.assertEqual('random320x240.png', file_test.name)

        file_test = Item.secure_query( self.user_id ) \
            .filter( Picture.width == 100 ) \
            .first()

        self.assertEqual(1, file_test.aspect)
        self.assertEqual('random100x100.png', file_test.name)

        file_test = Item.secure_query( self.user_id ) \
            .filter( Picture.aspect == 10 ) \
            .first()

        self.assertEqual(10, file_test.aspect)
        self.assertEqual('random640x400.png', file_test.name)
Example #2
0
    def test_nsfw(self):

        DataHelper.create_data_items(self, db)

        from cloud_on_film.files.picture import Picture

        file_test = Item.secure_query( self.user_id ) \
            .filter( Picture.nsfw == 1 ) \
            .first()

        self.assertTrue(file_test.nsfw)
Example #3
0
    def test_rating(self):

        DataHelper.create_data_items(self, db)

        from cloud_on_film.files.picture import Picture

        files_test = Item.secure_query( self.user_id ) \
            .filter( Picture.rating > 1 ) \
            .all()

        self.assertEqual(1, len(files_test))
        self.assertEqual(4, files_test[0].rating)
        self.assertEqual('random100x100.png', files_test[0].name)

        files_test = Item.secure_query( self.user_id ) \
            .filter( Picture.rating == 1 ) \
            .all()

        self.assertEqual(1, len(files_test))
        self.assertEqual(1, files_test[0].rating)
        self.assertEqual('random500x500.png', files_test[0].name)
Example #4
0
    def test_query_width(self):

        DataHelper.create_data_items(self, db)

        from cloud_on_film.files.picture import Picture

        files_test = Item.secure_query( self.user_id ) \
            .filter( Picture.width == 100 ) \
            .all()

        self.assertEqual(1, len(files_test))
        self.assertEqual('random100x100.png', files_test[0].name)
        self.assertEqual(100, files_test[0].width)
Example #5
0
    def test_item_tags(self):

        DataHelper.create_data_items(self, db)

        from cloud_on_film.files.picture import Picture

        tag = Tag.from_path('IFDY/Test Tag 1/Sub Test Tag 3')

        files_test = Item.secure_query( self.user_id ) \
            .filter( Picture.width == 100 ) \
            .all()

        self.assertEqual(1, len(files_test))
        self.assertIn(tag, files_test[0].tags)
Example #6
0
    def test_import(self):

        # Perform the import.
        pics_json = None
        with open('testdata/test_import.json', 'r') as import_file:
            pics_json = json.loads(import_file.read())
        for pic_json in pics_json:
            pic_json['filename'] = os.path.join(self.nsfw_lib_path,
                                                pic_json['filename'])
            picture(pic_json)

        # Test the results.
        tag_testing_img = Tag.from_path('Testing Imports/Testing Image')

        from cloud_on_film.files.picture import Picture

        file_test = Item.secure_query( self.user_id ) \
            .filter( Picture.width == 500 ) \
            .first()

        self.assertIn(tag_testing_img, file_test.tags)
        self.assertEqual(500, file_test.width)
        self.assertEqual(500, file_test.height)
        self.assertEqual(1, file_test.aspect)
        self.assertTrue(file_test.nsfw)
        self.assertEqual(3, file_test.rating)

        file_test = Item.secure_query( self.user_id ) \
            .filter( Picture.aspect == 10 ) \
            .first()

        self.assertNotIn(tag_testing_img, file_test.tags)
        self.assertEqual(640, file_test.width)
        self.assertEqual(400, file_test.height)
        self.assertEqual(10, file_test.aspect)
        self.assertTrue(file_test.nsfw)
        self.assertEqual(0, file_test.rating)
Example #7
0
    def search(self, user_id, _tree_start=None, _query=None):

        if not _query:
            _query = Item.secure_query(user_id)

        if not _tree_start:
            _tree_start = self.lexer.root

        if isinstance(_tree_start, SearchLexerParser.Group):
            child_filter_list = []
            for c in _tree_start.children:
                child_filter_list.append(self.search(user_id, c, _query))

            filter_out = None
            if isinstance(_tree_start, SearchLexerParser.Or):
                filter_out = db.or_(*child_filter_list)

            elif isinstance(_tree_start, SearchLexerParser.Not):
                filter_out = db.not_(*child_filter_list)

            else:
                # If it's not an or then it's an and.
                filter_out = db.and_(*child_filter_list)

            if _tree_start.parent:
                return filter_out
            else:
                return _query.filter(filter_out)

        elif isinstance(_tree_start, SearchLexerParser.Compare):

            # TODO: Get plugin model or something.
            from cloud_on_film.files.picture import Picture

            if SearchLexerParser.Op.in_ == _tree_start.op:
                # Special ops that use the attrib postfix.
                if not hasattr(Picture, _tree_start.children[1]):
                    raise SearchExecuteException(
                        'invalid attribute "{}" specified'.format(
                            _tree_start.children[1]))

            elif not hasattr(Picture, _tree_start.children[0]):
                raise SearchExecuteException(
                    'invalid attribute "{}" specified'.format(
                        _tree_start.children[0]))

            if SearchLexerParser.Op.eq == _tree_start.op:
                return (getattr(
                    Picture,
                    _tree_start.children[0]) == _tree_start.children[1])
            elif SearchLexerParser.Op.gt == _tree_start.op:
                return (getattr(Picture, _tree_start.children[0]) >
                        _tree_start.children[1])
            elif SearchLexerParser.Op.lt == _tree_start.op:
                return (getattr(Picture, _tree_start.children[0]) <
                        _tree_start.children[1])
            elif SearchLexerParser.Op.gte == _tree_start.op:
                return (getattr(Picture, _tree_start.children[0]) >=
                        _tree_start.children[1])
            elif SearchLexerParser.Op.lte == _tree_start.op:
                return (getattr(Picture, _tree_start.children[0]) <=
                        _tree_start.children[1])
            elif SearchLexerParser.Op.neq == _tree_start.op:
                return (getattr(Picture, _tree_start.children[0]) !=
                        _tree_start.children[1])
            elif SearchLexerParser.Op.like == _tree_start.op:
                return (getattr(Picture, _tree_start.children[0]).like(
                    _tree_start.children[1]))
            elif SearchLexerParser.Op.in_ == _tree_start.op:
                #if 'tags' == _tree_start.children[1]:
                #    _tree_start.children = (Tag.from_path(_tree_start.children[1] ), 'tag_ids')
                return getattr(
                    Picture,
                    _tree_start.children[1]).any(name=_tree_start.children[0])

        return _query