コード例 #1
0
    def test_warn_project_owner(self, mail, clean_mock):
        """Test JOB email is sent to warn project owner."""
        # Mock for the send method
        send_mock = MagicMock()
        send_mock.send.return_value = True
        # Mock for the connection method
        connection = MagicMock()
        connection.__enter__.return_value = send_mock
        # Join them
        mail.connect.return_value = connection

        date = '2010-10-22T11:02:00.000000'
        project = ProjectFactory.create(updated=date)
        project_id = project.id
        warn_old_project_owners()
        project = project_repo.get(project_id)
        err_msg = "mail.connect() should be called"
        assert mail.connect.called, err_msg
        err_msg = "conn.send() should be called"
        assert send_mock.send.called, err_msg
        err_msg = "project.contacted field should be True"
        assert project.contacted, err_msg
        err_msg = "project.published field should be False"
        assert project.published is False, err_msg
        err_msg = "cache of project should be cleaned"
        clean_mock.assert_called_with(project_id), err_msg
        err_msg = "The update date should be different"
        assert project.updated != date, err_msg
コード例 #2
0
    def test_warn_project_excludes_completed_projects(self, clean_mock):
        """Test JOB email excludes completed projects."""
        from pybossa.core import mail
        with mail.record_messages() as outbox:
            date = '2010-10-22T11:02:00.000000'

            project = ProjectFactory.create(updated=date, contacted=False)
            TaskFactory.create(created=date,
                               project=project,
                               state='completed')
            project_id = project.id
            project = project_repo.get(project_id)
            project.updated = date
            project_repo.update(project)

            project = ProjectFactory.create(updated=date, contacted=False)
            TaskFactory.create(created=date, project=project, state='ongoing')
            project_id = project.id
            project = project_repo.get(project_id)
            project.updated = date
            project_repo.update(project)

            warn_old_project_owners()
            assert len(outbox) == 1, outbox
            subject = 'Your PyBossa project: %s has been inactive' % project.name
            assert outbox[0].subject == subject
            err_msg = "project.contacted field should be True"
            assert project.contacted, err_msg
            err_msg = "project.published field should be False"
            assert project.published is False, err_msg
            err_msg = "cache of project should be cleaned"
            clean_mock.assert_called_with(project_id), err_msg
            err_msg = "The update date should be different"
            assert project.updated != date, err_msg
コード例 #3
0
ファイル: test_old_projects.py プロジェクト: PyBossa/pybossa
    def test_warn_project_owner(self, mail, clean_mock):
        """Test JOB email is sent to warn project owner."""
        # Mock for the send method
        send_mock = MagicMock()
        send_mock.send.return_value = True
        # Mock for the connection method
        connection = MagicMock()
        connection.__enter__.return_value = send_mock
        # Join them
        mail.connect.return_value = connection

        date = '2010-10-22T11:02:00.000000'
        owner = UserFactory.create(consent=True, subscribed=True)
        project = ProjectFactory.create(updated=date, owner=owner)
        project_id = project.id
        warn_old_project_owners()
        project = project_repo.get(project_id)
        err_msg = "mail.connect() should be called"
        assert mail.connect.called, err_msg
        err_msg = "conn.send() should be called"
        assert send_mock.send.called, err_msg
        err_msg = "project.contacted field should be True"
        assert project.contacted, err_msg
        err_msg = "project.published field should be False"
        assert project.published is False, err_msg
        err_msg = "cache of project should be cleaned"
        clean_mock.assert_called_with(project_id), err_msg
        err_msg = "The update date should be different"
        assert project.updated != date, err_msg
コード例 #4
0
ファイル: test_old_projects.py プロジェクト: PyBossa/pybossa
    def test_warn_project_excludes_completed_projects(self, clean_mock):
        """Test JOB email excludes completed projects."""
        from pybossa.core import mail
        with mail.record_messages() as outbox:
            date = '2010-10-22T11:02:00.000000'

            owner = UserFactory.create(consent=True, subscribed=True)
            project = ProjectFactory.create(updated=date, contacted=False,
                                            owner=owner)
            TaskFactory.create(created=date, project=project, state='completed')
            project_id = project.id
            project = project_repo.get(project_id)
            project.updated = date
            project_repo.update(project)

            project = ProjectFactory.create(updated=date, contacted=False,
                                            owner=owner)
            TaskFactory.create(created=date, project=project, state='ongoing')
            project_id = project.id
            project = project_repo.get(project_id)
            project.updated = date
            project_repo.update(project)

            warn_old_project_owners()
            assert len(outbox) == 1, outbox
            subject = 'Your PYBOSSA project: %s has been inactive' % project.name
            assert outbox[0].subject == subject
            err_msg = "project.contacted field should be True"
            assert project.contacted, err_msg
            err_msg = "project.published field should be False"
            assert project.published is False, err_msg
            err_msg = "cache of project should be cleaned"
            clean_mock.assert_called_with(project_id), err_msg
            err_msg = "The update date should be different"
            assert project.updated != date, err_msg
コード例 #5
0
    def test_warn_project_owner_not_consent(self, mail, clean_mock):
        """Test JOB email is not sent to warn project owner as not consent."""
        # Mock for the send method
        send_mock = MagicMock()
        send_mock.send.return_value = True
        # Mock for the connection method
        connection = MagicMock()
        connection.__enter__.return_value = send_mock
        # Join them
        mail.connect.return_value = connection

        date = '2010-10-22T11:02:00.000000'
        owner = UserFactory.create(consent=False, subscribed=True)
        project = ProjectFactory.create(updated=date, owner=owner)
        project_id = project.id
        warn_old_project_owners()
        project = project_repo.get(project_id)
        err_msg = "mail.connect() should be called"
        assert mail.connect.called, err_msg
        err_msg = "conn.send() should not be called"
        assert send_mock.send.called is False, err_msg
        err_msg = "project.contacted field should be False"
        assert project.contacted is False, err_msg
        err_msg = "project.published field should be True"
        assert project.published is True, err_msg
        err_msg = "The update date should be different"
        assert project.updated == date, err_msg
コード例 #6
0
 def test_warn_project_owner_two(self):
     """Test JOB email is sent to warn project owner."""
     from pybossa.core import mail
     with mail.record_messages() as outbox:
         date = '2010-10-22T11:02:00.000000'
         app = AppFactory.create(updated=date)
         app_id = app.id
         warn_old_project_owners()
         assert len(outbox) == 1, outbox
         subject = 'Your PyBossa project: %s has been inactive' % app.name
         assert outbox[0].subject == subject
         err_msg = "app.contacted field should be True"
         assert app.contacted, err_msg
         err_msg = "The update date should be different"
         assert app.updated != date, err_msg
コード例 #7
0
ファイル: test_old_projects.py プロジェクト: idahoan/pybossa
 def test_warn_project_owner_two(self):
     """Test JOB email is sent to warn project owner."""
     from pybossa.core import mail
     with mail.record_messages() as outbox:
         date = '2010-10-22T11:02:00.000000'
         app = AppFactory.create(updated=date)
         app_id = app.id
         warn_old_project_owners()
         assert len(outbox) == 1, outbox
         subject = 'Your PyBossa project: %s has been inactive' % app.name
         assert outbox[0].subject == subject
         err_msg = "app.contacted field should be True"
         assert app.contacted, err_msg
         err_msg = "The update date should be different"
         assert app.updated != date, err_msg
コード例 #8
0
    def test_warn_project_owner(self, mail, clean_mock):
        """Test JOB email is sent to warn project owner."""
        from smtplib import SMTPRecipientsRefused
        from nose.tools import assert_raises
        # Mock for the send method
        send_mock = MagicMock()
        send_mock.send.side_effect = SMTPRecipientsRefused('wrong')
        # Mock for the connection method
        connection = MagicMock()
        connection.__enter__.return_value = send_mock
        # Join them
        mail.connect.return_value = connection

        date = '2010-10-22T11:02:00.000000'
        owner = UserFactory.create(consent=True, subscribed=True,
                                   email_addr="wrong")
        project = ProjectFactory.create(updated=date, owner=owner)
        project_id = project.id
        assert warn_old_project_owners() is False
        assert_raises(SMTPRecipientsRefused, send_mock.send, 'msg')
        project = project_repo.get(project_id)
        err_msg = "mail.connect() should be called"
        assert mail.connect.called, err_msg
        err_msg = "conn.send() should be called"
        assert send_mock.send.called, err_msg
        err_msg = "project.contacted field should be False"
        assert project.contacted is False, err_msg
        err_msg = "project.published field should be True"
        assert project.published, err_msg
        err_msg = "The update date should be the same"
        assert project.updated == date, err_msg
コード例 #9
0
 def test_warn_project_owner_two(self, clean_mock):
     """Test JOB email is sent to warn project owner."""
     from pybossa.core import mail
     with mail.record_messages() as outbox:
         date = '2010-10-22T11:02:00.000000'
         project = ProjectFactory.create(updated=date)
         project_id = project.id
         warn_old_project_owners()
         project = project_repo.get(project_id)
         assert len(outbox) == 1, outbox
         subject = 'Your PYBOSSA project: %s has been inactive' % project.name
         assert outbox[0].subject == subject
         err_msg = "project.contacted field should be True"
         assert project.contacted, err_msg
         err_msg = "project.published field should be False"
         assert project.published is False, err_msg
         err_msg = "cache of project should be cleaned"
         clean_mock.assert_called_with(project_id), err_msg
         err_msg = "The update date should be different"
         assert project.updated != date, err_msg
コード例 #10
0
 def test_warn_project_owner_two(self, clean_mock):
     """Test JOB email is sent to warn project owner."""
     from pybossa.core import mail
     with mail.record_messages() as outbox:
         date = '2010-10-22T11:02:00.000000'
         project = ProjectFactory.create(updated=date)
         project_id = project.id
         warn_old_project_owners()
         project = project_repo.get(project_id)
         assert len(outbox) == 1, outbox
         subject = 'Your PyBossa project: %s has been inactive' % project.name
         assert outbox[0].subject == subject
         err_msg = "project.contacted field should be True"
         assert project.contacted, err_msg
         err_msg = "project.published field should be False"
         assert project.published is False, err_msg
         err_msg = "cache of project should be cleaned"
         clean_mock.assert_called_with(project_id), err_msg
         err_msg = "The update date should be different"
         assert project.updated != date, err_msg
コード例 #11
0
 def test_warn_project_owner_limits(self):
     """Test JOB email gets at most 25 projects."""
     from pybossa.core import mail
     # Create 50 projects with old updated dates
     date = '2010-10-22T11:02:00.000000'
     apps = []
     for i in range(0, 50):
         apps.append(AppFactory.create(updated=date))
     # The first day that we run the job only 25 emails should be sent
     with mail.record_messages() as outbox:
         warn_old_project_owners()
         err_msg = "There should be only 25 emails."
         assert len(outbox) == 25, err_msg
     # The second day that we run the job only 25 emails should be sent
     with mail.record_messages() as outbox:
         warn_old_project_owners()
         err_msg = ("There should be only 25 emails, but there are %s."
                    % len(outbox))
         assert len(outbox) == 25, err_msg
     # The third day that we run the job only 0 emails should be sent
     # as the previous projects have been already contacted.
     with mail.record_messages() as outbox:
         warn_old_project_owners()
         err_msg = "There should be only 0 emails."
         assert len(outbox) == 0, err_msg
コード例 #12
0
ファイル: test_old_projects.py プロジェクト: idahoan/pybossa
 def test_warn_project_owner_limits(self):
     """Test JOB email gets at most 25 projects."""
     from pybossa.core import mail
     # Create 50 projects with old updated dates
     date = '2010-10-22T11:02:00.000000'
     apps = []
     for i in range(0, 50):
         apps.append(AppFactory.create(updated=date))
     # The first day that we run the job only 25 emails should be sent
     with mail.record_messages() as outbox:
         warn_old_project_owners()
         err_msg = "There should be only 25 emails."
         assert len(outbox) == 25, err_msg
     # The second day that we run the job only 25 emails should be sent
     with mail.record_messages() as outbox:
         warn_old_project_owners()
         err_msg = ("There should be only 25 emails, but there are %s."
                    % len(outbox))
         assert len(outbox) == 25, err_msg
     # The third day that we run the job only 0 emails should be sent
     # as the previous projects have been already contacted.
     with mail.record_messages() as outbox:
         warn_old_project_owners()
         err_msg = "There should be only 0 emails."
         assert len(outbox) == 0, err_msg
コード例 #13
0
    def test_warn_project_owner(self, mail):
        """Test JOB email is sent to warn project owner."""
        # Mock for the send method
        send_mock = MagicMock()
        send_mock.send.return_value = True
        # Mock for the connection method
        connection = MagicMock()
        connection.__enter__.return_value = send_mock
        # Join them
        mail.connect.return_value = connection

        date = '2010-10-22T11:02:00.000000'
        app = AppFactory.create(updated=date)
        app_id = app.id
        warn_old_project_owners()
        err_msg = "mail.connect() should be called"
        assert mail.connect.called, err_msg
        err_msg = "conn.send() should be called"
        assert send_mock.send.called, err_msg
        err_msg = "app.contacted field should be True"
        assert app.contacted, err_msg
        err_msg = "The update date should be different"
        assert app.updated != date, err_msg
コード例 #14
0
ファイル: test_old_projects.py プロジェクト: idahoan/pybossa
    def test_warn_project_owner(self, mail):
        """Test JOB email is sent to warn project owner."""
        # Mock for the send method
        send_mock = MagicMock()
        send_mock.send.return_value = True
        # Mock for the connection method
        connection = MagicMock()
        connection.__enter__.return_value = send_mock
        # Join them
        mail.connect.return_value = connection

        date = '2010-10-22T11:02:00.000000'
        app = AppFactory.create(updated=date)
        app_id = app.id
        warn_old_project_owners()
        err_msg = "mail.connect() should be called"
        assert mail.connect.called, err_msg
        err_msg = "conn.send() should be called"
        assert send_mock.send.called, err_msg
        err_msg = "app.contacted field should be True"
        assert app.contacted, err_msg
        err_msg = "The update date should be different"
        assert app.updated != date, err_msg