Esempio n. 1
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))
Esempio n. 2
0
    def test_change_thumbnail(self):
        file = (io.BytesIO(b"abcdef"), 'test.jpg')

        api_utils.post(url_for_security('login'),
                       data={
                           'email': '*****@*****.**',
                           'password': '******'
                       },
                       headers={'Authentication-Token': self.token})

        bookmark = BookMark(url='dummy.url', img='dummy.png')

        past_img = bookmark.img

        self.current_user.bookmarks.append(bookmark)

        db.session.add(self.current_user)
        db.session.commit()

        data = {'img': file, 'id': BookMark.query.first().id}
        res = self.client.patch(url_for('library.change_thumbnail'),
                                data=data,
                                headers={
                                    'Authentication-Token': self.token,
                                    'Content-Type': 'multipart/form-data'
                                })

        self.assertNotEqual(past_img, bookmark.img)

        path = Path(app.config['STORAGE_PATH'] + '/' + bookmark.img)
        self.assertTrue(path.is_file())
        self.assertStatus(res, 204)
Esempio n. 3
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'])
Esempio n. 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'])
Esempio n. 5
0
    def test_invalid_url(self):
        api_utils.post(url_for_security('login'),
                       data={
                           'email': '*****@*****.**',
                           'password': '******'
                       },
                       headers={'Authentication-Token': self.token})

        data = {'url': 'yahoo.invalid'}
        res = api_utils.post(url_for('library.add_ele'), data=data)

        self.assert500(res)
        self.assertRaises(InvalidURLException)

        bookmark_cnt = BookMark.query.count()

        self.assertEqual(0, bookmark_cnt)
Esempio n. 6
0
    def setUp(self):
        super().setUp()

        login = api_utils.post(url_for_security('register'),
                               data={
                                   'email': '*****@*****.**',
                                   'password': '******',
                                   'password_confirm': 'test123'
                               })

        user = api_utils.loads(login.data)['response']['user']
        self.token = user['authentication_token']