Commits

megamahi committed a8db88f

Adding Tests

Comments (0)

Files changed (4)

     zip_safe=False,
     include_package_data=True,
     test_suite = 'nose.collector',
+    tests_require = [
+        'nose',
+        'BeautifulSoup',
+        'Genshi',
+        'mako',
+        # formencode isn't actually needed, but is just here to patch up
+        # tw2.forms,
+        'formencode',
+        'strainer',
+        'WebTest'
+    ],
     entry_points="""
         [tw2.widgets]
         # Register your widgets so they can be listed in the WidgetBrowser

tests/test_exceptions.py

+import tw2.core as twc
+import tw2.jqplugins.tagify
+
+def request_local_tst():
+    global _request_local, _request_id
+# if _request_id is None:
+# raise KeyError('must be in a request')
+    if _request_local == None:
+        _request_local = {}
+    try:
+        return _request_local[_request_id]
+    except KeyError:
+        rl_data = {}
+        _request_local[_request_id] = rl_data
+        return rl_data
+
+twc.core.request_local = request_local_tst
+_request_local = {}
+_request_id = 'whatever'
+
+def setup():
+    twc.core.request_local = request_local_tst
+    twc.core.request_local()['middleware'] = twc.make_middleware()
+
+
+def test_exception_no_id():
+    w = tw2.jqplugins.tagify.TagifyWidget
+    try:
+        w.display()
+        assert(False)
+    except ValueError as e:
+        print str(e)
+        assert(str(e) == 'JQueryWidget must be supplied an id')
+
+def test_exception_bad_options_dict():
+    w = tw2.jqplugins.tagify.TagifyWidget(id="testtagify", options=[])
+    try:
+        w.display()
+        assert(False)
+    except ValueError as e:
+        assert(str(e) == 'Options parameter must be a dict')
+import tw2.core as twc
+import tw2.jqplugins.tagify
+
+def request_local_tst():
+    global _request_local, _request_id
+# if _request_id is None:
+# raise KeyError('must be in a request')
+    if _request_local == None:
+        _request_local = {}
+    try:
+        return _request_local[_request_id]
+    except KeyError:
+        rl_data = {}
+        _request_local[_request_id] = rl_data
+        return rl_data
+
+twc.core.request_local = request_local_tst
+_request_local = {}
+_request_id = 'whatever'
+
+def setup():
+    twc.core.request_local = request_local_tst
+    twc.core.request_local()['middleware'] = twc.make_middleware()
+
+def test_js_call():
+    w = tw2.jqplugins.tagify.TagifyWidget(id='foobar')
+    w.display()
+
+    js_calls = filter(lambda x: "JSFuncCall" in str(x), w.resources)
+
+    assert(len(js_calls) == 1)
+
+    for js_call in js_calls:
+        print js_call.src
+        assert(js_call.src == "$('#foobar').tagify({})")

tests/test_widget.py

-from tw.core.testutil import WidgetTestCase
-from tw.jqplugins import *
+from tw2.core.testbase import WidgetTest
+import tw2.jqplugins.tagify
 
-class TestWidget(WidgetTestCase):
+class TestWidget(WidgetTest):
     # place your widget at the TestWidget attribute
-    TestWidget = Jqplugins
-    # Initilization args. go here 
-    widget_kw = {}
-
-    def test_render(self):
-        # Asserts 'foo' and 'test' (the test widget's id) appear in rendered 
-        # string when 'foo' is passed as value to render
-        self.assertInOutput(['foo', 'test'], "foo")
-        # Asserts 'ohlalala' does not appear in rendered string when render 
-        # is called without args
-        self.assertNotInOutput(['ohlalala'])
+    widget = tw2.jqplugins.tagify.TagifyWidget
+    # Initilization args. go here
+    attrs={'id':'tagifytest'}
+    params={}
+    expected = """<textarea id="tagifytest" name="tagifytest"></textarea>"""