blob: ab1c151514388a16b2f8ac7ad73e208577f218d7 [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.
"""Unit tests for project 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 project_utils
def _getProjectDetailsUrl(project):
"""Returns URL to 'Project Details' page for the specified project.
Args:
project: Project entity.
Returns:
The URL to 'Project Details' page.
"""
return '/gsoc/project/details/%s/%s' % (
project.key.parent().id(), project.key.id())
def _getProjectEditUrl(project):
"""Returns URL to 'Project Edit' page for the specified project.
Args:
project: Project entity.
Returns:
The URL to 'Project Edit' page.
"""
return '/gsoc/project/edit/%s/%s' % (
project.key.parent().id(), project.key.id())
def _getListProjectPublicUrl(program):
"""Returns URL to 'Project List Public' page for the specified program.
Args:
program: Program entity.
Returns:
The URL to 'Project List Public' page.
"""
return '/gsoc/projects/list/%s' % program.key().name()
class ProjectEditPageTest(test_utils.GSoCDjangoTestCase):
"""Unit tests for ProjectEditPage class."""
def setUp(self):
"""See unittest.TestCase.setUp for specification."""
self.init()
self.timeline_helper.studentsAnnounced()
user = user_seeder.seedUser()
profile_utils.loginNDB(user)
student = profile_seeder.seedStudent(self.program, user=user)
self.project = project_utils.seedNDBProject(
student, self.program.key(), org_key=self.org.key)
def testPageLoads(self):
"""Tests that the page loads properly."""
response = self.get(_getProjectEditUrl(self.project))
self.assertResponseOkAndGSoCTemplatesUsed(response)
class ProjectDetailsPageTest(test_utils.GSoCDjangoTestCase):
"""Unit tests for ProjectDetailsPage class."""
def setUp(self):
"""See unittest.TestCase.setUp for specification."""
self.init()
self.timeline_helper.studentsAnnounced()
student = profile_seeder.seedStudent(self.program)
self.project = project_utils.seedNDBProject(
student, self.program.key(), org_key=self.org.key)
def testPageLoads(self):
"""Tests that the page loads properly."""
response = self.get(_getProjectDetailsUrl(self.project))
self.assertResponseOkAndGSoCTemplatesUsed(response)
# TODO(daniel): text context
_TEST_NUMBER_OF_PROJECTS = 3
class ListProjectPublicTest(test_utils.GSoCDjangoTestCase):
"""Unit tests for ListProjectPublic class."""
def setUp(self):
"""See unittest.TestCase.setUp for specification."""
self.init()
self.timeline_helper.studentsAnnounced()
for _ in range(_TEST_NUMBER_OF_PROJECTS):
student = profile_seeder.seedStudent(self.program)
project_utils.seedNDBProject(
student, self.program.key(), org_key=self.org.key)
def testPageLoads(self):
"""Tests that the page loads properly."""
response = self.get(_getListProjectPublicUrl(self.program))
self.assertResponseOkAndGSoCTemplatesUsed(response)
def testListData(self):
"""Tests that correct list data is loaded."""
list_data = self.getListData(_getListProjectPublicUrl(self.program), 0)
# check that accepted projects are listed
self.assertEqual(len(list_data), _TEST_NUMBER_OF_PROJECTS)