|
1 #!/usr/bin/python2.5 |
|
2 # |
|
3 # Copyright 2008 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 """Unit tests for the Page class and its kin. |
|
17 """ |
|
18 |
|
19 __authors__ = [ |
|
20 '"Augie Fackler" <durin42@gmail.com>', |
|
21 ] |
|
22 |
|
23 import unittest |
|
24 |
|
25 from django.core import urlresolvers |
|
26 from nose import tools |
|
27 |
|
28 from soc.logic.site import page |
|
29 |
|
30 class UrlTests(unittest.TestCase): |
|
31 def testSimpleUrl(self): |
|
32 # TODO(durin42) I think this is actually a bug - I gave a callable, |
|
33 # shouldn't this require a name argument to have been provided? |
|
34 url = page.Url(r'/', lambda r: None) |
|
35 tools.eq_(type(url.makeDjangoUrl()), urlresolvers.RegexURLPattern) |
|
36 url = page.Url(r'/', None) |
|
37 tools.eq_(url.makeDjangoUrl(), None) |
|
38 |
|
39 class PageTests(unittest.TestCase): |
|
40 def setUp(self): |
|
41 self.home_page = page.Page(page.Url('/', lambda r: None, name='Home'), |
|
42 'Home!', 'Home') |
|
43 self.child_page = page.Page(page.Url('/child', lambda r: None, |
|
44 name='Child'), |
|
45 'Child!', 'Child', parent=self.home_page) |
|
46 self.child_page_2 = page.Page(page.Url('/foo', None, name='None'), 'Bogus', |
|
47 'Bogus', parent=self.home_page, |
|
48 link_url='/bar') |
|
49 |
|
50 def testMenuItems(self): |
|
51 tools.eq_(list(self.home_page.getChildren()), [self.child_page, |
|
52 self.child_page_2, |
|
53 ]) |
|
54 menu = self.home_page.makeMenuItem() |
|
55 tools.eq_(menu.name, 'Home') |
|
56 tools.eq_([i.name for i in menu.sub_menu.items], ['Child', 'Bogus', ]) |
|
57 |
|
58 def testLinkUrl(self): |
|
59 tools.eq_(self.home_page.makeLinkUrl(), '/') |
|
60 tools.eq_(self.child_page.makeLinkUrl(), '/child') |
|
61 tools.eq_(self.child_page_2.makeLinkUrl(), '/bar') |
|
62 |
|
63 |
|
64 if __name__ == '__main__': |
|
65 print 'This is not a standalone script. Please run it using tests/run.py.' |