|
1 #!/usr/bin/python2.5 |
|
2 # |
|
3 # Copyright 2009 the Melange authors. |
|
4 # |
|
5 # Licensed under the Apache License, Version 2.0 (the "License"); |
|
6 # you may not use this file except in compliance with the License. |
|
7 # You may obtain a copy of the License at |
|
8 # |
|
9 # http://www.apache.org/licenses/LICENSE-2.0 |
|
10 # |
|
11 # Unless required by applicable law or agreed to in writing, software |
|
12 # distributed under the License is distributed on an "AS IS" BASIS, |
|
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 # See the License for the specific language governing permissions and |
|
15 # limitations under the License. |
|
16 |
|
17 |
|
18 __authors__ = [ |
|
19 '"Sverre Rabbelier" <sverre@rabbelier.nl>', |
|
20 ] |
|
21 |
|
22 |
|
23 import unittest |
|
24 |
|
25 from tests.test_utils import MockRequest |
|
26 from tests.pymox import stubout |
|
27 |
|
28 from tests.app.soc.logic.models.test_model import TestModelLogic |
|
29 |
|
30 from soc.views.helper import access |
|
31 from soc.views.helper import responses |
|
32 from soc.views.models import base |
|
33 |
|
34 |
|
35 def error_raw(error, request, template=None, context=None): |
|
36 """ |
|
37 """ |
|
38 |
|
39 return { |
|
40 'error': error, |
|
41 'request': request, |
|
42 'template': template, |
|
43 'context': context, |
|
44 } |
|
45 |
|
46 def respond_raw(request, template, context=None, args=None, headers=None): |
|
47 """ |
|
48 """ |
|
49 |
|
50 return { |
|
51 'request': request, |
|
52 'template': template, |
|
53 'context': context, |
|
54 'args': args, |
|
55 'headers': headers, |
|
56 } |
|
57 |
|
58 |
|
59 class TestView(base.View): |
|
60 """ |
|
61 """ |
|
62 |
|
63 def __init__(self): |
|
64 """ |
|
65 """ |
|
66 |
|
67 rights = access.Checker(None) |
|
68 rights['unspecified'] = ['deny'] |
|
69 rights['any_access'] = ['allow'] |
|
70 rights['show'] = ['allow'] |
|
71 |
|
72 params = {} |
|
73 params['name'] = "Test" |
|
74 params['logic'] = TestModelLogic() |
|
75 params['rights'] = rights |
|
76 |
|
77 super(TestView, self).__init__(params=params) |
|
78 |
|
79 |
|
80 class BaseTest(unittest.TestCase): |
|
81 """Tests related to the base view. |
|
82 """ |
|
83 |
|
84 def setUp(self): |
|
85 """Set up required for the view tests. |
|
86 """ |
|
87 |
|
88 self.view = TestView() |
|
89 self.stubout = stubout.StubOutForTesting() |
|
90 self.stubout.Set(responses, 'respond', respond_raw) |
|
91 self.stubout.Set(responses, 'errorResponse', error_raw) |
|
92 |
|
93 def testErrorOnNonExistantEntity(self): |
|
94 """ |
|
95 """ |
|
96 |
|
97 request = MockRequest("/test/public") |
|
98 access_type = "show" |
|
99 page_name = "Show Test" |
|
100 django_args = {'link_id': 'foo', 'scope_path': 'bar'} |
|
101 actual = self.view.public(request, access_type, page_name=page_name, **django_args) |
|
102 self.assertTrue('error' in actual) |