# -*- coding: utf8 -*-
# This file is part of PyBossa.
#
# Copyright (C) 2014 SF Isle of Man Limited
#
# PyBossa is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyBossa is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with PyBossa.  If not, see <http://www.gnu.org/licenses/>.

from pybossa.jobs import notify_blog_users
from default import Test, with_context
from factories import BlogpostFactory
from factories import TaskRunFactory
from factories import ProjectFactory
from mock import patch, MagicMock

queue = MagicMock()
queue.enqueue.return_value = True


class TestNotifyBlogUsers(Test):


    @with_context
    @patch('pybossa.jobs.requests')
    def test_notify_blog_users(self, mock):
        """Test Notify Blog users works."""
        project = ProjectFactory.create()
        TaskRunFactory.create(project=project)
        blog = BlogpostFactory.create(project=project)
        res = notify_blog_users(blog.id, blog.project.id)
        msg = "1 users notified by email"
        assert res == msg, res

@@ -927,24 +927,58 @@
 jectFactory%0A
+from factories import UserFactory%0A
 from mock im
@@ -1233,16 +1233,68 @@
 rks.%22%22%22%0A
+        user = UserFactory.create(subscribed=False)%0A
         
@@ -1366,32 +1366,90 @@
 roject=project)%0A
+        TaskRunFactory.create(project=project, user=user)%0A
         blog = B

Test unsubscribed users are excluded.