Commits

Andriy Kornatskyy committed 2804db3

Added ajax test cases, refactored benchmark tests; updated version dependency.

Comments (0)

Files changed (6)

demos/quickstart-empty/setup.py

 README = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read()
 
 install_requires = [
-    'wheezy.core>=0.1.101',
+    'wheezy.core>=0.1.104',
     'wheezy.caching>=0.1.83',
     'wheezy.html>=0.1.125',
-    'wheezy.http>=0.1.262',
+    'wheezy.http>=0.1.285',
     'wheezy.routing>=0.1.145',
     'wheezy.security>=0.1.46',
     'wheezy.template>=0.1.132',
     'wheezy.validation>=0.1.84',
-    'wheezy.web>=0.1.340',
+    'wheezy.web>=0.1.365',
 ]
 
 install_optional = [

demos/quickstart-i18n/setup.py

 README = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read()
 
 install_requires = [
-    'wheezy.core>=0.1.101',
+    'wheezy.core>=0.1.104',
     'wheezy.caching>=0.1.83',
     'wheezy.html>=0.1.125',
-    'wheezy.http>=0.1.262',
+    'wheezy.http>=0.1.285',
     'wheezy.routing>=0.1.145',
     'wheezy.security>=0.1.46',
     'wheezy.template>=0.1.132',
     'wheezy.validation>=0.1.84',
-    'wheezy.web>=0.1.340',
+    'wheezy.web>=0.1.365',
 ]
 
 install_optional = [

demos/template/setup.py

 README = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read()
 
 install_requires = [
-    'wheezy.core>=0.1.87',
+    'wheezy.core>=0.1.104',
     'wheezy.caching>=0.1.80',
     'wheezy.html>=0.1.109',
-    'wheezy.http>=0.1.259',
+    'wheezy.http>=0.1.285',
     'wheezy.routing>=0.1.124',
     'wheezy.security>=0.1.44',
     'wheezy.validation>=0.1.74',
-    'wheezy.web>=0.1.315',
+    'wheezy.web>=0.1.365',
 ]
 
 install_optional = [

demos/template/src/membership/web/tests/benchmark_views.py

 """ ``benchmark_views`` module.
 """
 
+from wheezy.core.json import json_encode
 from wheezy.http.functional import BenchmarkMixin
 
 from membership.web.tests.test_views import MembershipTestCase
 from membership.web.tests.test_views import SignUpTestCase
 
 
+try:
+    json_encode({})
+    has_json = True
+except NotImplementedError:
+    has_json = False
+
+
 class MembershipBenchmarkTestCase(MembershipTestCase, BenchmarkMixin):
 
     def runTest(self):
     def runTest(self):
         """ Perform benchmark and print results.
         """
-        b = self.benchmark((
-            self.test_validation_error,
+        b = self.benchmark([
+            self.test_validation_errors,
             self.test_unknown_user,
             self.test_xrsf_token_invalid
-        ), 200)
+        ], 200)
         b.report('signin', baselines={
-            'test_validation_error': 1.0,
+            'test_validation_errors': 1.0,
             'test_unknown_user': 1.0,
             'test_xrsf_token_invalid': 0.94
         })
     def runTest(self):
         """ Perform benchmark and print results.
         """
-        b = self.benchmark((
-            self.test_validation_error,
+        b = self.benchmark([
+            self.test_validation_errors,
             self.test_already_registered,
-            self.test_resubmission_token_invalid,
-        ), 100)
+            self.test_resubmission_token_invalid
+        ], 100)
         b.report('signup', baselines={
             'test_validation_error': 1.0,
             'test_already_registered': 1.0,
             'test_resubmission_token_invalid': 1.05
         })
+
+try:
+    from membership.web.tests.test_views import SignInAJAXTestCase
+    from membership.web.tests.test_views import SignUpAJAXTestCase
+
+    class SigninAJAXBenchmarkTestCase(SignInAJAXTestCase, BenchmarkMixin):
+
+        def runTest(self):
+            """ Perform benchmark and print results.
+            """
+            b = self.benchmark([
+                self.test_ajax_validation_errors,
+                self.test_ajax_unknown_user,
+                self.test_ajax_xrsf_token_invalid
+            ], 200)
+            b.report('ajax-signin', baselines={
+                'test_ajax_validation_errors': 1.0,
+                'test_ajax_unknown_user': 1.0,
+                'test_ajax_xrsf_token_invalid': 0.94
+            })
+
+    class SignupAJAXBenchmarkTestCase(SignUpAJAXTestCase, BenchmarkMixin):
+
+        def runTest(self):
+            """ Perform benchmark and print results.
+            """
+            b = self.benchmark([
+                self.test_ajax_validation_errors
+            ], 100)
+            b.report('ajax-signup', baselines={
+                'test_ajax_validation_error': 1.0
+            })
+
+except ImportError:
+    pass

demos/template/src/membership/web/tests/test_views.py

 
 import unittest
 
+from wheezy.core.json import json_encode
+from wheezy.http.functional import PageMixin
 from wheezy.http.functional import WSGIClient
 
 from app import main
 
 # region: pages
 
-class SignInPage(object):
+class SignInPage(PageMixin):
 
     def __init__(self, client):
         assert '- Sign In</title>' in client.content
         assert AUTH_COOKIE not in client.cookies
         assert XSRF_NAME in client.cookies
         self.client = client
-        self.form = client.form
 
-    def signin(self, username, password):
-        form = self.form
-        form.username = username
-        form.password = password
-        self.client.submit(form)
-        return self.client.form.errors()
+    def form(self):
+        return self.client.form_by(action='/en/signin')
 
 
-class SignUpPage(object):
+class SignUpPage(PageMixin):
 
     def __init__(self, client):
         assert '- Sign Up</title>' in client.content
         assert AUTH_COOKIE not in client.cookies
         assert RESUBMISSION_NAME in client.cookies
         self.client = client
-        self.form = client.form
 
-    def signup(self, **kwargs):
-        form = self.form
-        form.update(kwargs)
-        self.client.submit(form)
-        return self.client.form.errors()
+    def form(self):
+        return self.client.form_by(lambda attrs:
+                                   'signup' in attrs.get('action', ''))
 
 
 # region: mixins
         client = self.client
         assert 200 == client.get('/en/signin')
         page = SignInPage(client)
-        return page.signin(username, password)
+        return page.submit(username=username, password=password)
+
+    def ajax_signin(self, username, password):
+        client = self.client
+        assert 200 == client.get('/en/signin')
+        page = SignInPage(client)
+        return page.ajax_submit(username=username, password=password)
 
 
 class SignUpMixin(object):
         client = self.client
         assert 200 == client.get('/en/signup')
         page = SignUpPage(client)
-        return page.signup(**kwargs)
+        return page.submit(**kwargs)
+
+    def ajax_signup(self, **kwargs):
+        client = self.client
+        assert 200 == client.get('/en/signup')
+        page = SignUpPage(client)
+        return page.ajax_submit(**kwargs)
 
 
 class SignOutMixin(object):
         del self.client
         self.client = None
 
-    def test_validation_error(self):
+    def test_validation_errors(self):
         """ Ensure sigin page displays field validation errors.
         """
         errors = self.signin('', '')
         assert 200 == client.get('/en/signin')
         page = SignInPage(client)
         client.cookies.clear()
-        page.signin('', '')
+        page.submit()
         assert 200 == client.follow()
         SignInPage(client)
 
 
+try:
+    json_encode({})
+
+    class SignInAJAXTestCase(unittest.TestCase, SignInMixin):
+
+        def setUp(self):
+            self.client = WSGIClient(main)
+
+        def tearDown(self):
+            del self.client
+            self.client = None
+
+        def test_ajax_validation_errors(self):
+            """ Ensure sigin page displays field validation errors
+                on AJAX call.
+            """
+            assert 200 == self.ajax_signin('', '')
+            errors = self.client.json.errors
+            assert 2 == len(errors)
+            assert AUTH_COOKIE not in self.client.cookies
+
+        def test_ajax_unknown_user(self):
+            """ Ensure sigin page displays general error message
+                on AJAX call.
+            """
+            assert 200 == self.ajax_signin('test', 'password')
+            errors = self.client.json.errors
+            assert '__ERROR__' in errors
+            assert AUTH_COOKIE not in self.client.cookies
+
+        def test_ajax_valid_user(self):
+            """ Ensure sigin is successful.
+            """
+            assert 207 == self.ajax_signin('demo', 'P@ssw0rd')
+            assert 200 == self.client.follow()
+            assert AUTH_COOKIE in self.client.cookies
+            assert XSRF_NAME not in self.client.cookies
+            assert 'Welcome <b>demo' in self.client.content
+
+        def test_ajax_xrsf_token_invalid(self):
+            client = self.client
+            assert 200 == client.get('/en/signin')
+            page = SignInPage(client)
+            client.cookies.clear()
+            assert 207 == page.ajax_submit()
+            assert 200 == client.follow()
+            SignInPage(client)
+
+except NotImplementedError:
+    pass
+
+
 class SignOutTestCase(unittest.TestCase, SignInMixin, SignOutMixin):
 
     def setUp(self):
         del self.client
         self.client = None
 
-    def test_validation_error(self):
+    def test_validation_errors(self):
         """ Ensure signup page displays field validation errors.
         """
         errors = self.signup()
         assert 200 == client.get('/en/signup')
         page = SignUpPage(client)
         client.cookies[RESUBMISSION_NAME] = '100'
-        page.signup()
+        page.submit()
         SignUpPage(client)
+
+
+try:
+    json_encode({})
+
+    class SignUpAJAXTestCase(unittest.TestCase, SignInMixin, SignUpMixin):
+
+        def setUp(self):
+            self.client = WSGIClient(main)
+
+        def tearDown(self):
+            del self.client
+            self.client = None
+
+        def test_ajax_validation_errors(self):
+            """ Ensure signup page displays field validation errors
+                on AJAX call.
+            """
+            assert 200 == self.ajax_signup()
+            errors = self.client.json.errors
+            assert 6 == len(errors)
+            assert AUTH_COOKIE not in self.client.cookies
+
+except NotImplementedError:
+    pass
 README = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read()
 
 install_requires = [
-    'wheezy.core>=0.1.87',
+    'wheezy.core>=0.1.104',
     'wheezy.caching>=0.1.65',
     'wheezy.html>=0.1.109',
-    'wheezy.http>=0.1.257',
+    'wheezy.http>=0.1.285',
     'wheezy.routing>=0.1.124',
     'wheezy.security>=0.1.44',
     'wheezy.validation>=0.1.74',
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.