tests/app/soc/views/helper/test_access.py
author Lennard de Rijk <ljvderijk@gmail.com>
Sat, 28 Feb 2009 13:06:04 +0000
changeset 1559 283046e54c01
parent 1308 35b75ffcbb37
child 2266 4e2d1334a362
permissions -rw-r--r--
Fixed issue 205. Registered students can't apply to become an organization. If for some reason the org sign up period and student sign up period are run in parallel and a student has applied to become an org, the application will still go through the normal system. Although the student won't be able to become an org admin until he has been invalidated as a student. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1009
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
#
1308
35b75ffcbb37 Partially reverted "Update the copyright notice for 2009."
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1009
diff changeset
     3
# Copyright 2009 the Melange authors.
1009
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
#
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     8
#
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    10
#
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    16
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    17
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    18
__authors__ = [
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    19
  '"Sverre Rabbelier" <sverre@rabbelier.nl>',
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    20
  ]
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    21
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    22
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    23
import unittest
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    24
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    25
from soc.views import out_of_band
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    26
from soc.views.helper import access
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    27
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    28
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
class AccessTest(unittest.TestCase):
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    30
  def setUp(self):
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    31
    self.test_context = {'TEST_KEY': 'TEST_VALUE'}
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    32
    self.rights = access.Checker(None)
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    33
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    34
  def testAllow(self):
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    35
    try:
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    36
      self.rights.allow(self.test_context)
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    37
    except out_of_band.Error:
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    38
      self.fail("allow should not raise on any request")
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    39
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    40
  def testDeny(self):
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    41
    kwargs = {}
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    42
    kwargs['context'] = self.test_context
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    43
    try:
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    44
      self.rights.deny(kwargs)
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    45
      self.fail("deny should raise out_of_band.Error")
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    46
    except out_of_band.Error, e:
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    47
      self.assertEqual(e.context, self.test_context,
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    48
                       "context should pass through context")