Browse files

More Tests. Now checks to make sure the js_call is properly formed.

  • Loading branch information...
1 parent 4d7a9c2 commit b99cb35d0170ffef3abc5140f1602caad5499fd3 @gregjurman gregjurman committed Feb 22, 2012
Showing with 36 additions and 2 deletions.
  1. +34 −0 tests/test_js.py
  2. +2 −2 tests/test_widget.py
View
34 tests/test_js.py
@@ -0,0 +1,34 @@
+import tw2.core as twc
+import tw2.dyntext
+
+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.dyntext.DynamicTextWidget(id='foobar', data_url="/herp/derp")
+ w.display()
+
+ js_calls = filter(lambda x: "JSFuncCall" in str(x), w.resources)
+
+ assert(len(js_calls) > 0)
+
+ for js_call in js_calls:
+ assert(js_call.src == """setupPollingDynText("foobar", "/herp/derp", 5000)""")
View
4 tests/test_widget.py
@@ -1,9 +1,9 @@
from tw2.core.testbase import WidgetTest
-from tw2.dyntext import DynamicTextWidget
+import tw2.dyntext
class TestDemoWidget(WidgetTest):
# place your widget at the TestWidget attribute
- widget = DynamicTextWidget
+ widget = tw2.dyntext.DynamicTextWidget
# Initilization args. go here
attrs = {'id' : 'affected_count'}

0 comments on commit b99cb35

Please sign in to comment.