blob: 0a150c8d3ba22303a525fcfe8a250c0caa95c34f [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 create proposal revision model."""
from mapreduce import test_support
from soc.mapreduce.helper import control as mapreduce_control
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 TestCreateProposalRevisionsForProposal(
test_utils.GSoCDjangoTestCase, test_utils.TaskQueueTestCase):
"""Unit tests for CreateProposalRevisionsForProposal MapReduce job."""
def setUp(self):
"""See unittest.TestCase.setUp for specification."""
self.init()
def testProposalRevisionIsCreated(self):
"""Tests that ProposalRevision entities are created correctly."""
student1 = profile_utils.seedNDBStudent(self.program)
proposal1 = proposal_utils.seedNDBProposal(
student1.key, self.program.key(), org_key=self.org.key,
status=proposal_model.Status.PENDING, is_ignored=True)
proposal2 = proposal_utils.seedNDBProposal(
student1.key, self.program.key(), org_key=self.org.key,
status=proposal_model.Status.REJECTED,
visibility=proposal_model.Visibility.ORG_MEMBER)
student2 = profile_utils.seedNDBStudent(self.program)
proposal3 = proposal_utils.seedNDBProposal(
student2.key, self.program.key(), org_key=self.org.key,
status=proposal_model.Status.WITHDRAWN,
visibility=proposal_model.Visibility.STUDENT,
is_editable_post_deadline=True)
proposal4 = proposal_utils.seedNDBProposal(
student2.key, self.program.key(), org_key=self.org.key,
status=proposal_model.Status.IGNORED,
visibility=proposal_model.Visibility.ORG_MEMBER)
student3 = profile_utils.seedNDBStudent(self.program)
proposal5 = proposal_utils.seedNDBProposal(
student3.key, self.program.key(), org_key=self.org.key,
status=proposal_model.Status.ACCEPTED,
visibility=proposal_model.Visibility.ORG_MEMBER)
mapreduce_control.start_map('CreateProposalRevisionsForProposal')
test_support.execute_until_empty(self.get_task_queue_stub())
revision1 = proposal_model.ProposalRevision.query(
ancestor=proposal1.key).fetch()
revision2 = proposal_model.ProposalRevision.query(
ancestor=proposal2.key).fetch()
revision3 = proposal_model.ProposalRevision.query(
ancestor=proposal3.key).fetch()
revision4 = proposal_model.ProposalRevision.query(
ancestor=proposal4.key).fetch()
revision5 = proposal_model.ProposalRevision.query(
ancestor=proposal5.key).fetch()
# check that only one ProposalRevision entity is created per proposal
self.assertEqual(len(revision1), 1)
self.assertEqual(len(revision2), 1)
self.assertEqual(len(revision3), 1)
self.assertEqual(len(revision4), 1)
self.assertEqual(len(revision5), 1)
# check that revision number of ProposalRevision entities are set
# correctly
self.assertEqual(0, revision1[0].revision)
self.assertEqual(0, revision2[0].revision)
self.assertEqual(0, revision3[0].revision)
self.assertEqual(0, revision4[0].revision)
self.assertEqual(0, revision5[0].revision)
# check that content of ProposalRevision entities are set
# correctly
self.assertEqual(proposal1.content, revision1[0].content)
self.assertEqual(proposal2.content, revision2[0].content)
self.assertEqual(proposal3.content, revision3[0].content)
self.assertEqual(proposal4.content, revision4[0].content)
self.assertEqual(proposal5.content, revision5[0].content)