Anonymous avatar Anonymous committed 6d77642

[svn] o all tests now extend WebHelpersTestCase. It establishes a basic routes mapping and a test environ dict
under routes' request_config
o added full tests for cycle and some tests for counter

Comments (0)

Files changed (12)

tests/test_asset_tag.py

-from unittest import TestCase
+from util import WebHelpersTestCase
 import unittest
 
 from webhelpers.rails.asset_tag import *
 from webhelpers.rails.asset_tag import compute_public_path
 
-class TestAssetTagHelper(TestCase):
+class TestAssetTagHelper(WebHelpersTestCase):
     def test_auto_discovery_link_tag(self):
         self.assertEqual('<link href="http://feed.com/feed.xml" rel="alternate" title="RSS" type="application/rss+xml" />',
                          auto_discovery_link_tag('http://feed.com/feed.xml'))

tests/test_date.py

-from unittest import TestCase
+from util import WebHelpersTestCase
 import unittest
 from datetime import datetime
 from datetime import timedelta
 
 from webhelpers.rails.date import *
 
-class TestDateHelper(TestCase):
+class TestDateHelper(WebHelpersTestCase):
     
     def test_distance_of_time_in_words(self):
         from_time = datetime(2004, 3, 6, 21, 41, 18)

tests/test_form_options.py

-from unittest import TestCase
+from util import WebHelpersTestCase
 import unittest
 
 from webhelpers.rails.form_options import *
 
-class TestFormOptionsHelper(TestCase):
+class TestFormOptionsHelper(WebHelpersTestCase):
     def test_array_options_for_select(self):
         self.assertEqual(
             "<option value=\"&lt;Denmark&gt;\">&lt;Denmark&gt;</option>\n<option value=\"USA\">USA</option>\n<option value=\"Sweden\">Sweden</option>",

tests/test_form_tag.py

-from unittest import TestCase
+from util import WebHelpersTestCase
 import unittest
 
 from webhelpers.rails.form_tag import *
+from webhelpers.rails.urls import url
 
-class TestFormTagHelper(TestCase):
+class TestFormTagHelper(WebHelpersTestCase):
     def test_check_box(self):
         self.assertEqual(
             check_box("admin"),

tests/test_javascript.py

-from unittest import TestCase
+from util import WebHelpersTestCase
 import unittest
 
 from webhelpers.rails.javascript import *
 
-class TestJavascriptHelper(TestCase):
+class TestJavascriptHelper(WebHelpersTestCase):
     def test_escape_javascript(self):
         self.assertEqual("""This \\"thing\\" is really\\n netos\\'""",
                escape_javascript("""This "thing" is really\n netos'"""))

tests/test_number.py

-from unittest import TestCase
+from util import WebHelpersTestCase
 import unittest
 
 from webhelpers.rails.number import *
 
-class TestTextHelper(TestCase):
+class TestTextHelper(WebHelpersTestCase):
     def test_number_to_phone(self):
         self.assertEqual("123-555-1234", number_to_phone(1235551234))
         self.assertEqual("(123) 555-1234", number_to_phone(1235551234, area_code=True))

tests/test_prototype.py

-from unittest import TestCase
+from util import WebHelpersTestCase
 import unittest
 
 from webhelpers.rails.urls import *
 from webhelpers.rails.prototype import *
 from routes import *
 
-class TestPrototypeHelper(TestCase):
+class TestPrototypeHelper(WebHelpersTestCase):
     def test_link_to_remote(self):
         self.assertEqual("""<a class="fine" href="#" onclick="new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true}); return false;">Remote outpost</a>""",
             link_to_remote("Remote outpost", dict(url='http://www.example.com/whatnot'), class_="fine"))

tests/test_scriptaculous.py

-from unittest import TestCase
+from util import WebHelpersTestCase
 import unittest
 
 from webhelpers.rails.scriptaculous import *
 
-class TestScriptaculousHelper(TestCase):
+class TestScriptaculousHelper(WebHelpersTestCase):
     def test_effect(self):
         self.assertEqual("new Effect.Highlight(\"posts\",{});", visual_effect('highlight', "posts"))
         self.assertEqual("new Effect.Fade(\"fademe\",{duration:4.0});", visual_effect('fade', "fademe", duration=4.0))

tests/test_tag.py

-from unittest import TestCase
+from util import WebHelpersTestCase
 import unittest
 
 from webhelpers.rails.tags import *
 
-class TestTagHelper(TestCase):
+class TestTagHelper(WebHelpersTestCase):
     def test_tag(self):
         self.assertEqual("<p class=\"show\" />", tag("p", class_='show'))
         self.assertEqual("<br>", tag("br", True))

tests/test_text.py

 # -*- coding: utf-8 -*-
-from unittest import TestCase
+from util import WebHelpersTestCase
 import unittest
 from string24 import Template
 
 from webhelpers.rails.text import *
 
-class TestTextHelper(TestCase):
+class TestTextHelper(WebHelpersTestCase):
     
     def test_simple_format(self):
         self.assertEqual("<p></p>", simple_format(None))
         self.assertEqual("", auto_link(None))
         self.assertEqual("", auto_link(""))
 
+    def test_cycle(self):
+        self.assertEqual("one", cycle("one", "2", "3"))
+        self.assertEqual("2", cycle("one", "2", "3"))
+        self.assertEqual("3", cycle("one", "2", "3"))
+        self.assertEqual("one", cycle("one", "2", "3"))
+        self.assertEqual("2", cycle("one", "2", "3"))
+        self.assertEqual("3", cycle("one", "2", "3"))
+
+        self.assertEqual("3", cycle("3", "2", "one", name='ordered'))
+        self.assertEqual("2", cycle("3", "2", "one", name='ordered'))
+        self.assertEqual("one", cycle("3", "2", "one", name='ordered'))
+        self.assertEqual("2", cycle("2", "3", "one", name='ordered'))
+        self.assertEqual("3", cycle("2", "3", "one", name='ordered'))
+        self.assertEqual("one", cycle("2", "3", "one", name='ordered'))
+
+    def test_named_cycles(self):
+        self.assertEqual(1, cycle(1, 2, 3, name="numbers"))
+        self.assertEqual("red", cycle("red", "blue", name="colors"))
+        self.assertEqual(2, cycle(1, 2, 3, name="numbers"))
+        self.assertEqual("blue", cycle("red", "blue", name="colors"))
+        self.assertEqual(3, cycle(1, 2, 3, name="numbers"))
+        self.assertEqual("red", cycle("red", "blue", name="colors"))
+  
+    def test_default_named_cycle(self):
+        self.assertEqual(1, cycle(1, 2, 3))
+        self.assertEqual(2, cycle(1, 2, 3, name="default"))
+        self.assertEqual(3, cycle(1, 2, 3))
+
+    def test_reset_cycle(self):
+        self.assertEqual(1, cycle(1, 2, 3))
+        self.assertEqual(2, cycle(1, 2, 3))
+        reset_cycle()
+        self.assertEqual(1, cycle(1, 2, 3))
+
+    def test_reset_unknown_cycle(self):
+        reset_cycle("colors")
+  
+    def test_recet_named_cycle(self):
+        self.assertEqual(1, cycle(1, 2, 3, name="numbers"))
+        self.assertEqual("red", cycle("red", "blue", name="colors"))
+        reset_cycle("numbers")
+        self.assertEqual(1, cycle(1, 2, 3, name="numbers"))
+        self.assertEqual("blue", cycle("red", "blue", name="colors"))
+        self.assertEqual(2, cycle(1, 2, 3, name="numbers"))
+        self.assertEqual("red", cycle("red", "blue", name="colors"))
+
+
+    def test_counters(self):
+        for i in range(1, 4):
+            self.assertEqual(i, counter())
+        reset_counter()
+        for i in range(3):
+            self.assertEqual(i, counter(start=0))
+        reset_counter()
+        for i in range(2, 5):
+            self.assertEqual(i, counter(start=2))
+        reset_counter()
+        for i in range(1, -2, -1):
+            self.assertEqual(i, counter(step=-1))
+
+    def test_named_counters(self):
+        for i in range(1, 4):
+            self.assertEqual(i, counter(name="a"))
+        for i in range(1, 4):
+            self.assertEqual(i, counter(name="b"))
+        for i in range(4, 7):
+            self.assertEqual(i, counter(name="a"))
+
     def test_excerpt(self):
         self.assertEqual("...lo my wo...",
                          excerpt("hello my world", "my", 3))

tests/test_url.py

-from unittest import TestCase
+from util import WebHelpersTestCase
 import unittest
 
 from webhelpers.rails.urls import *
 from routes import *
 
-class TestURLHelper(TestCase):
+class TestURLHelper(WebHelpersTestCase):
     def test_button_to_with_straight_url(self):
         self.assertEqual("<form method=\"POST\" action=\"http://www.example.com\" class=\"button-to\"><div><input type=\"submit\" value=\"Hello\" /></div></form>", 
                button_to("Hello", "http://www.example.com"))
+from unittest import TestCase
+
+import routes
+
+class WebHelpersTestCase(TestCase):
+    """Establishes a faux-environment for tests"""
+    def test_environ(self):
+        return {
+            'HTTP_HOST': 'bob.local:5000',
+            'PATH_INFO': '/test',
+            'SERVER_NAME': '0.0.0.0',
+            'SCRIPT_NAME': '',
+            'wsgi.multiprocess': False,
+            'wsgi.multithread': True,
+            'wsgi.run_once': False,
+            'wsgi.url_scheme': 'http'
+            }
+
+    def setUp(self):
+        self.routes_config = routes.request_config()
+        self.routes_config.environ = self.test_environ()
+        map = routes.Mapper()
+        map.connect(':controller/:action/:id')
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.