Anonymous avatar Anonymous committed abd0de3

[svn] o more test environ vars
o url tests: for current_page, current_url, link_to_unless and link_to_if

Comments (0)

Files changed (2)

tests/test_url.py

     def test_link_tag_using_post_javascript_and_confirm(self):
         self.assertEqual("<a href=\"http://www.example.com\" onclick=\"if (confirm('Are you serious?')) { var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;f.submit(); };return false;\">Hello</a>",
                link_to("Hello", "http://www.example.com", post=True, confirm="Are you serious?"))
+        self.assertRaises(ValueError, lambda: \
+                          link_to("Hello", "http://www.example.com", post=True, popup=True, confirm="Are you serious?"))
+
+    def test_link_to_unless_current(self):
+        self.assertEqual('Click Here',
+                         link_to_unless_current('Click Here',
+                                                '/test?test=webhelpers&framework=pylons'))
+        self.assertEqual('<a href="/test?test=routes&amp;framework=pylons">Click Here</a>',
+                         link_to_unless_current('Click Here',
+                                                '/test?test=routes&framework=pylons'))
+        self.assertEqual('<a href="/test2?test=webhelpers&amp;framework=pylons">Click Here</a>',
+                         link_to_unless_current('Click Here',
+                                                '/test2?test=webhelpers&framework=pylons'))
     
+    def test_link_to_unless(self, func=link_to_unless):
+        condition = func == link_to_unless and True or False
+        self.assertEqual('Click Here',
+                         func(condition, 'Click Here',
+                                        '/test?test=webhelpers&framework=pylons'))
+        self.assertEqual('<a href="/test?test=webhelpers&amp;framework=pylons">Click Here</a>',
+                         func(not condition, 'Click Here',
+                                        '/test?test=webhelpers&framework=pylons'))
+        self.assertEqual('<a href="/test?test=routes&amp;framework=pylons">Click Here</a>',
+                         func(not condition, 'Click Here',
+                                        '/test?test=routes&framework=pylons'))
+        self.assertEqual('Click Here',
+                         func(condition, 'Click Here',
+                                        '/test2?test=webhelpers&framework=pylons'))
+
+    def test_link_to_if(self):
+        self.test_link_to_unless(func=link_to_if)
+
     def test_mail_to(self):
         self.assertEqual('<a href="mailto:justin@example.com">justin@example.com</a>', mail_to("justin@example.com"))
         self.assertEqual('<a href="mailto:justin@example.com">Justin Example</a>', mail_to("justin@example.com", "Justin Example"))
         self.assertEqual("<script type=\"text/javascript\">\n//<![CDATA[\neval(unescape('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%22%3e%4d%79%20%65%6d%61%69%6c%3c%2f%61%3e%27%29%3b'))\n//]]>\n</script>",
                          mail_to("me@domain.com", "My email", encode = "javascript", replace_at = "(at)", replace_dot = "(dot)"))
 
+    def test_current_page(self):
+        self.assertTrue(current_page('/test?test=webhelpers&framework=pylons'))
+        self.assertTrue(current_page(url('/test?test=webhelpers&framework=pylons')))
+
+    def test_current_url(self):
+        self.assertEquals('/test?test=webhelpers&framework=pylons', current_url())
+        self.assertTrue(isinstance(current_url(), str))
+
 if __name__ == '__main__':
     suite = [unittest.makeSuite(TestURLHelper)]
     for testsuite in suite:
         return {
             'HTTP_HOST': 'bob.local:5000',
             'PATH_INFO': '/test',
+            'QUERY_STRING': 'test=webhelpers&framework=pylons',
+            'REQUEST_METHOD': 'GET',
             'SERVER_NAME': '0.0.0.0',
             'SCRIPT_NAME': '',
             'wsgi.multiprocess': False,
             }
 
     def setUp(self):
+        map = routes.Mapper()
+        map.connect('test')
+        map.connect(':controller/:action/:id')
+
         self.routes_config = routes.request_config()
+        self.routes_config.mapper = map
         self.routes_config.environ = self.test_environ()
-        map = routes.Mapper()
-        map.connect(':controller/:action/:id')
+        assert self.routes_config.mapper_dict
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.