| # 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. |
| |
| """Unit tests for duplicated related views.""" |
| |
| from seeder import profile as profile_seeder |
| from seeder import user as user_seeder |
| |
| from tests import profile_utils |
| from tests import test_utils |
| from tests.utils import proposal_utils |
| |
| |
| def _getDuplicatesUrl(program): |
| """Returns URL to 'Duplicates' page for the specified program. |
| |
| Args: |
| program: Program entity. |
| |
| Returns: |
| The URL to 'Duplicates' page. |
| """ |
| return '/gsoc/duplicates/%s' % program.key().name() |
| |
| |
| _TEST_NUMBER_OF_PROPOSALS = 2 |
| |
| class DuplicatesPageTest(test_utils.GSoCDjangoTestCase): |
| """Unit tests for DuplicatesPage class.""" |
| |
| def setUp(self): |
| """See unittest.TestCase.setUp for specification.""" |
| self.init() |
| |
| # seed a couple to-be-accepted proposals from the same student |
| self.student = profile_seeder.seedStudent(self.program) |
| to_be_accepted_proposals = [] |
| for _ in range(_TEST_NUMBER_OF_PROPOSALS): |
| to_be_accepted_proposals.append( |
| proposal_utils.seedNDBProposal( |
| self.student.key, self.program.key(), org_key=self.org.key, |
| accept_as_project=True).key) |
| self.student.student_data.to_be_accepted_proposals = ( |
| to_be_accepted_proposals) |
| self.student.put() |
| |
| # seed a couple proposals not to-be-accepted for the same student |
| for _ in range(_TEST_NUMBER_OF_PROPOSALS): |
| to_be_accepted_proposals.append( |
| proposal_utils.seedNDBProposal( |
| self.student.key, self.program.key(), org_key=self.org.key).key) |
| |
| def testPageLoads(self): |
| """Tests that the page loads properly.""" |
| user = user_seeder.seedUser(host_for=[self.program]) |
| profile_utils.loginNDB(user) |
| |
| response = self.get(_getDuplicatesUrl(self.program)) |
| self.assertResponseOK(response) |
| |
| def testPageContext(self): |
| """Tests content of the page context.""" |
| user = user_seeder.seedUser(host_for=[self.program]) |
| profile_utils.loginNDB(user) |
| |
| response = self.get(_getDuplicatesUrl(self.program)) |
| |
| duplicates = response.context['duplicates'] |
| self.assertEqual(len(duplicates), 1) |
| |
| duplicate = duplicates[0] |
| self.assertEqual(duplicate._profile.key, self.student.key) |
| |
| # check that duplicate proposals for the students are present |
| context = duplicate.context() |
| self.assertIn(self.org.key, context['org_details']) |
| self.assertEqual( |
| len(context['org_details'][self.org.key]['proposals']), |
| _TEST_NUMBER_OF_PROPOSALS) |