blob: a79a5da112075912fec8e9bab38bbc668b36a2b7 [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 Summer Of Code-specific access checker implementations."""
import httplib
import unittest
from codein.request import access
from melange.request import exception
from seeder import program as program_seeder
from seeder import sponsor as sponsor_seeder
from soc.modules.gci.views.helper import request_data
from tests import timeline_utils
class WorkReviewedAccessCheckerTest(unittest.TestCase):
"""Unit tests for WorkReviewedAccessChecker class."""
def setUp(self):
"""See unittest.TestCase.setUp for specification."""
sponsor = sponsor_seeder.seedSponsor()
self.program = program_seeder.seedGCIProgram(sponsor_key=sponsor.key())
self.timeline_helper = timeline_utils.GCITimelineHelper(
self.program.timeline, None)
kwargs = {
'sponsor': sponsor.key().name(),
'program': self.program.program_id
}
self.data = request_data.RequestData(None, None, kwargs)
def testWorkReviewedAccessDenied(self):
"""Tests that access is denied before work review deadline has passed."""
self.timeline_helper.pencilDown()
access_checker = access.WorkReviewedAccessChecker()
with self.assertRaises(exception.UserError) as context:
access_checker.checkAccess(self.data, None)
self.assertEqual(context.exception.status, httplib.FORBIDDEN)
def testWorkReviewedAccessGranted(self):
"""Tests that access is granted after work review deadline has passed."""
self.timeline_helper.allWorkReviewed()
access_checker = access.WorkReviewedAccessChecker()
access_checker.checkAccess(self.data, None)