blob: 85a4cb7b686a09495eaac1697426f466728de8e4 [file] [log] [blame]
# Copyright 2014 the Melange authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests for MapReduce job to send student acceptance/rejection emails."""
from mapreduce import test_support
from soc.mapreduce.helper import control as mapreduce_control
from summerofcode.logic import profile as profile_logic
from summerofcode.logic import proposal as proposal_logic
from summerofcode.models import proposal as proposal_model
from tests import profile_utils
from tests import test_utils
from tests.utils import proposal_utils
class TestStudentAdmissionEmail(
test_utils.GSoCDjangoTestCase, test_utils.TaskQueueTestCase):
"""Unit tests for StudentAdmissionEmail MapReduce job."""
def setUp(self):
"""See unittest.TestCase.setUp for specification."""
self.init()
# set parameters of the MapReduce job
self.params = {
'entity_kind': 'melange.models.profile.Profile',
'program_key': str(self.program.key())
}
def testEmailsAreSent(self):
"""Tests that emails are sent successfully."""
accepted_student = profile_utils.seedNDBStudent(self.program)
accepted_proposal = proposal_utils.seedNDBProposal(
accepted_student.key, self.program.key(),
org_key=self.org.key, status=proposal_model.Status.ACCEPTED)
proposal_utils.seedNDBProposal(
accepted_student.key, self.program.key(),
org_key=self.org.key, status=proposal_model.Status.REJECTED)
rejected_student = profile_utils.seedNDBStudent(self.program)
proposal_utils.seedNDBProposal(
rejected_student.key, self.program.key(),
org_key=self.org.key, status=proposal_model.Status.REJECTED)
first_admin = profile_utils.seedNDBProfile(
self.program.key(), admin_for=[self.org.key])
other_admin = profile_utils.seedNDBProfile(
self.program.key(), admin_for=[self.org.key])
mapreduce_control.start_map(
'StudentAdmissionEmail', params=self.params)
test_support.execute_until_empty(self.get_task_queue_stub())
# check that acceptance email is sent
self.assertEmailSent(
to=accepted_student.contact.email,
subject=proposal_logic._DEF_PROPOSAL_ACCEPTED_STUDENT_MAIL_SUBJECT
% self.program.name)
# check that accepted student welcome email is sent
self.assertEmailSent(
to=accepted_student.contact.email,
subject=profile_logic._DEF_ACCEPTED_STUDENT_WELCOME_EMAIL_SUBJECT
% self.program.name)
# check that rejection email is sent
self.assertEmailSent(
to=rejected_student.contact.email,
subject=proposal_logic._DEF_PROPOSAL_REJECTED_MAIL_SUBJECT
% self.program.name)
# check that acceptance email is sent to admins.
self.assertEmailSent(
to=first_admin.contact.email,
subject=proposal_logic._DEF_PROPOSAL_ACCEPTED_ADMIN_MAIL_SUBJECT
% accepted_proposal.title)
self.assertEmailSent(
to=other_admin.contact.email,
subject=proposal_logic._DEF_PROPOSAL_ACCEPTED_ADMIN_MAIL_SUBJECT
% accepted_proposal.title)