# -*- 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 get_inactive_users_jobs
from default import Test, with_context
from factories import TaskRunFactory
from pybossa.core import user_repo
# from mock import patch, MagicMock


class TestEngageUsers(Test):

    @with_context
    def test_get_inactive_users_jobs(self):
        """Test JOB get inactive users returns empty list."""
        jobs = get_inactive_users_jobs()
        msg = "There should not be any job."
        assert len(jobs) == 0,  msg

    @with_context
    def test_get_inactive_users_returns_jobs(self):
        """Test JOB get inactive users returns a list of jobs."""

        tr = TaskRunFactory.create(finish_time="2010-07-07T17:23:45.714210")
        user = user_repo.get(tr.user_id)

        jobs = get_inactive_users_jobs()
        msg = "There should not be one job."
        assert len(jobs) == 1,  msg
        job = jobs[0]
        args = job['args'][0]
        assert job['queue'] == 'quaterly', job['queue']
        assert len(args['recipients']) == 1
        assert args['recipients'][0] == user.email_addr, args['recipients'][0]

@@ -1015,24 +1015,33 @@
 e_users_jobs
+_no_users
 (self):%0A    
@@ -1064,45 +1064,330 @@
 get 
-inactive users returns empty list.%22%22%22
+without users returns empty list.%22%22%22%0A        jobs = get_inactive_users_jobs()%0A        msg = %22There should not be any job.%22%0A        assert len(jobs) == 0,  msg%0A%0A    @with_context%0A    def test_get_inactive_users_jobs_with_users(self):%0A        %22%22%22Test JOB get with users returns empty list.%22%22%22%0A        TaskRunFactory.create()
 %0A   
@@ -2111,12 +2111,949 @@
 pients'%5D%5B0%5D%0A
+%0A%0A# class TestNonContributors(Test):%0A#%0A#     @with_context%0A#     def test_get_non_contributors_users_jobs(self):%0A#         %22%22%22Test JOB get returns empty list.%22%22%22%0A#         jobs = get_non_contributors_users_jobs()%0A#         msg = %22There should not be any job.%22%0A#         assert len(jobs) == 0,  msg%0A#%0A#     @with_context%0A#     def test_get_inactive_users_returns_jobs(self):%0A#         %22%22%22Test JOB get inactive users returns a list of jobs.%22%22%22%0A#%0A#         tr = TaskRunFactory.create(finish_time=%222010-07-07T17:23:45.714210%22)%0A#         user = user_repo.get(tr.user_id)%0A#%0A#         jobs = get_inactive_users_jobs()%0A#         msg = %22There should not be one job.%22%0A#         assert len(jobs) == 1,  msg%0A#         job = jobs%5B0%5D%0A#         args = job%5B'args'%5D%5B0%5D%0A#         assert job%5B'queue'%5D == 'quaterly', job%5B'queue'%5D%0A#         assert len(args%5B'recipients'%5D) == 1%0A#         assert args%5B'recipients'%5D%5B0%5D == user.email_addr, args%5B'recipients'%5D%5B0%5D%0A

Test that returns also empty list with users.