Commits

megamahi committed 720c96c

Added tests

Comments (0)

Files changed (2)

tests/test_exceptions.py

+import tw2.core as twc
+import tw2.qrcode
+
+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.qrcode.QRCodeWidget(data="I am the cheese", qr_type=4)
+    try:
+        w.display()
+        assert(False)
+    except ValueError as e:
+        assert(str(e) == 'QRCodeWidget must be supplied an id')
+
+def test_exception_nodata():
+    w = tw2.qrcode.QRCodeWidget(id='foobar', qr_type=1)
+    try:
+        w.display()
+        assert(False)
+    except ValueError as e:
+        assert(str(e) == 'QRCodeWidget data parameter must be a string')
+
+def test_exception_bad_qr_type():
+    w = tw2.qrcode.QRCodeWidget(id='foobar', data="I am the cheese")
+    try:
+        w.display()
+        assert(False)
+    except ValueError as e:
+        assert(str(e) == 'QRCodeWidget qr_type must be between 1 and 40 inclusive')
+
+
+def test_exception_bad_correction_level():
+    w = tw2.qrcode.QRCodeWidget(id='foobar', data="I am the cheese", qr_type=4, correction_level=None)
+    try:
+        w.display()
+        assert(False)
+    except ValueError as e:
+        assert(str(e) == 'QRCodeWidget correction_level must be a string containing one of the following options: H, Q, M, L')

tests/test_widget.py

-from tw.core.testutil import WidgetTestCase
-from tw.qrcode import *
+from tw2.core.testbase import WidgetTest
+import tw2.qrcode
 
-class TestWidget(WidgetTestCase):
+class TestWidget(WidgetTest):
     # place your widget at the TestWidget attribute
-    TestWidget = Qrcode
-    # 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.qrcode.QRCodeWidget
+    # Initilization args. go here
+    attrs={'id':'qrcodetest'}
+    params={'data': 'This is a test of the emergency awesome system.', 'qr_type': 9}
+    expected = """<div id="qrcodetest" class="qr-code" style="width:160; height:160;"></div>"""