def test_process_img_queue(is_img_queue_empty):
    """test method."""
    with mock.patch('tumblr_ids.tumblr.Tumblr.__init__', return_value=None), \
            mock.patch('tumblr_ids.tumblr.threading') as m_threading:
        from tumblr_ids.tumblr import Tumblr
        obj = Tumblr(blog=mock.Mock())
        obj.threads_num = 1
        obj.img_queue = mock.Mock()
        obj.img_queue.empty.return_value = is_img_queue_empty
        obj._download_imgs = mock.Mock()
        # run
        obj._process_img_queue(consumer=[])
        # test
        if not is_img_queue_empty:
            m_threading.assert_has_calls([
                mock.call.Thread(target=obj._download_imgs),
                mock.call.Thread().start()
            ])
示例#2
0
def test_process_img_queue(is_img_queue_empty):
    """test method."""
    with mock.patch('tumblr_ids.tumblr.Tumblr.__init__', return_value=None), \
            mock.patch('tumblr_ids.tumblr.threading') as m_threading:
        from tumblr_ids.tumblr import Tumblr
        obj = Tumblr(blog=mock.Mock())
        obj.threads_num = 1
        obj.img_queue = mock.Mock()
        obj.img_queue.empty.return_value = is_img_queue_empty
        obj._download_imgs = mock.Mock()
        # run
        obj._process_img_queue(consumer=[])
        # test
        if not is_img_queue_empty:
            m_threading.assert_has_calls([
                mock.call.Thread(target=obj._download_imgs),
                mock.call.Thread().start()
            ])
def test_get_imgs_using_threading(total_posts_default, get_total_posts_retval, need_save):
    """test method."""
    with mock.patch('tumblr_ids.tumblr.Tumblr.__init__', return_value=None):
        from tumblr_ids.tumblr import Tumblr
        obj = Tumblr(blog=mock.Mock())
        obj.need_save = need_save
        obj.tags = [mock.Mock()]
        obj.total_posts = total_posts_default
        obj._get_total_posts = mock.Mock(return_value=get_total_posts_retval)
        obj._process_img_queue = mock.Mock()
        obj._run_threads = mock.Mock()
        # run
        obj.get_imgs_using_threading()
        # test
        assert obj.tag == obj.tags[0]
        assert obj.total_posts == 0
        if total_posts_default or get_total_posts_retval:
            obj._run_threads.assert_called_once_with()
        if get_total_posts_retval:
            obj._run_threads.assert_called_once_with()
        if need_save:
            obj._process_img_queue.assert_called_once_with([])
示例#4
0
def test_get_imgs_using_threading(total_posts_default, get_total_posts_retval,
                                  need_save):
    """test method."""
    with mock.patch('tumblr_ids.tumblr.Tumblr.__init__', return_value=None):
        from tumblr_ids.tumblr import Tumblr
        obj = Tumblr(blog=mock.Mock())
        obj.need_save = need_save
        obj.tags = [mock.Mock()]
        obj.total_posts = total_posts_default
        obj._get_total_posts = mock.Mock(return_value=get_total_posts_retval)
        obj._process_img_queue = mock.Mock()
        obj._run_threads = mock.Mock()
        # run
        obj.get_imgs_using_threading()
        # test
        assert obj.tag == obj.tags[0]
        assert obj.total_posts == 0
        if total_posts_default or get_total_posts_retval:
            obj._run_threads.assert_called_once_with()
        if get_total_posts_retval:
            obj._run_threads.assert_called_once_with()
        if need_save:
            obj._process_img_queue.assert_called_once_with([])