示例#1
0
    def test_add_bookmark_with_new_tag(self):
        data = {'url': 'google.com', 'tags': '#new_tag'}
        res = api_utils.post(url_for('library.add_ele'),
                             data=data,
                             headers={'Authentication-Token': self.token})

        bookmark = BookMark.query.first()

        self.assertIsNotNone(bookmark)
        self.assertIsNotNone(bookmark.img)
        self.assertEqual(1, len(bookmark.tags))

        tags = Tag.query.all()
        self.assertEqual(1, len(tags))
        self.assertEqual(tags[0], bookmark.tags[0])

        current_user = User.query.first()
        self.assertEqual(bookmark, current_user.bookmarks[0])

        result = api_utils.get(url_for('library.urls'),
                               headers={'Authentication-Token': self.token})

        content = api_utils.loads(result.data)

        self.assertEqual(1, len(content['tags']))

        assert Tag.query.filter_by(
            tag='new_tag').first().as_dict() in content['tags']

        self.assertEqual('Google', content['bookmarks'][0]['name'])
示例#2
0
    def test_search_thumbnail_by_tag(self):
        from bookMarkLibrary.database import db
        user = User.query.first()
        b1 = BookMark(url='http://localhost', name='test_thumbnail')
        b2 = BookMark(url='http://localhost2', name='test_thumbnail2')
        tag = Tag(tag='test_tag')

        b1.tags.append(tag)
        b2.tags.append(tag)

        user.bookmarks.extend([b1, b2])

        db.session.add_all([user, tag])
        db.session.commit()

        result = api_utils.get(url_for('library.urls', tag='test_tag'),
                               headers={'Authentication-Token': self.token})

        content = api_utils.loads(result.data.decode('utf-8'))
        self.assertEqual(1, len(content['tags']))

        self.assertEqual([{
            'id': tag.id.__str__(),
            'tag': tag.tag
        }], content['tags'])
        self.assertEqual([b1.as_dict(), b2.as_dict()], content['bookmarks'])
示例#3
0
    def test_add_bookMark(self):
        # add bookmark with out tag
        data = {'url': 'google.com'}
        res = api_utils.post(url_for('library.add_ele'),
                             data=data,
                             headers={'Authentication-Token': self.token})

        bookmark = BookMark.query.first()

        self.assertIsNotNone(bookmark)
        self.assertIsNotNone(bookmark.img)

        # use og:img as thumbnail
        data = {'url': 'http://ogp.me/'}
        res = api_utils.post(url_for('library.add_ele'),
                             data=data,
                             headers={'Authentication-Token': self.token})
        self.assertStatus(res, 204)

        og_bookmark = BookMark.query.filter_by(
            _url='http://www.ogp.me').order_by(desc(BookMark.id)).first()
        self.assertIsNotNone(og_bookmark)
        self.assertEqual('http://www.ogp.me/logo.png', og_bookmark.img)

        result = api_utils.get(url_for('library.urls'),
                               headers={'Authentication-Token': self.token})

        content = result.data.decode('utf-8')
        assert 'ogp.me' in content
        assert 'Google' in content

        data = api_utils.loads(result.data)
        self.assertEqual(2, len(data))
示例#4
0
    def test_add_bookmark_with_new_tag_and_existing_tag(self):
        t1 = Tag(id=uuid.uuid4().hex, tag='existing_1')
        db.session.add(t1)
        db.session.commit()

        data = {'url': 'google.com', 'tags': '#' + t1.tag + '#new2'}
        res = api_utils.post(url_for('library.add_ele'),
                             data=data,
                             headers={'Authentication-Token': self.token})

        bookmark = BookMark.query.first()
        self.assertIsNotNone(bookmark)
        self.assertIsNotNone(bookmark.img)
        self.assertEqual(2, len(bookmark.tags))

        tags = Tag.query.all()
        self.assertEqual(2, len(tags))

        for tag in bookmark.tags:
            assert tag in tags

        self.assertEqual(bookmark, self.current_user.bookmarks[0])

        result = api_utils.get(url_for('library.urls'),
                               headers={'Authentication-Token': self.token})

        content = api_utils.loads(result.data)

        self.assertEqual(2, len(content['tags']))

        assert t1.as_dict() in content['tags']
        assert Tag.query.filter_by(
            tag='new2').first().as_dict() in content['tags']

        self.assertEqual('Google', content['bookmarks'][0]['name'])
示例#5
0
    def test_show_thumbnails(self):
        from bookMarkLibrary.database import db
        user = User.query.first()
        b1 = BookMark(url='http://localhost', name='test_thumbnail')
        b2 = BookMark(url='http://localhost2', name='test_thumbnail2')

        user.bookmarks.extend([b1, b2])

        db.session.add_all([user])
        db.session.commit()

        result = api_utils.get(url_for('library.urls'),
                               headers={'Authentication-Token': self.token})

        content = api_utils.loads(result.data.decode('utf-8'))

        assert 'bookmarks' in content
        assert 'tags' in content
        self.assertEqual([b1.as_dict(), b2.as_dict()], content['bookmarks'])