Example #1
0
 def test_thumbnail_return_img_path_when_exist(self):
     with patch('library.models.os') as mock_os:
         mock_os.path.exists.return_value = True
         bookmark = BookMark()
         bookmark.url = 'https://google.com'
         bookmark.makeup()
         bookmark.img = 'test'
         self.assertEqual('/storage/test', bookmark.thumbnail)
Example #2
0
def change_thumbnail(bookmark: BookMark, file):
    if file and __allowed_file(file.filename):
        ts = time.time()
        img_name = str(int(ts)) + file.filename
        path = os.path.join(app.config['STORAGE_PATH'], img_name)
        file.save(path)
        resize_img(path)

        try:

            bookmark.img = img_name
            db.session.add(bookmark)
            db.session.commit()

        except Exception:
            os.remove(path)
            db.session.rollback()
Example #3
0
 def test_thumbnail_return_img_value_on_default(self):
     bookmark = BookMark()
     bookmark.url = 'https://google.com'
     bookmark.makeup()
     bookmark.img = 'test'
     self.assertEqual('test', bookmark.thumbnail)
Example #4
0
 def test_blank_page_thumbnail(self):
     bookmark = BookMark()
     bookmark.url = 'https://google.com'
     bookmark.makeup()
     bookmark.img = None
     self.assertEqual('/static/img/blank.png', bookmark.thumbnail)