Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 3
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
Exemplo n.º 4
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'

            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
Exemplo n.º 5
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
Exemplo n.º 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
Exemplo n.º 7
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
Exemplo n.º 8
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