Commits

Andriy Kornatskyy committed 192812f

Refactoring module imports

Comments (0)

Files changed (16)

 	$(SPHINX) -a -b html doc/ doc/_build/
 
 test-demos:
+	$(PYTEST) -q -x --pep8 demos/hello
 	make clean test -sC demos/public VERSION=$(VERSION)

demos/hello/helloworld.py

 from datetime import datetime
 from datetime import timedelta
 
-from wheezy.caching.memory import MemoryCache
-from wheezy.http.application import WSGIApplication
-from wheezy.http.cache import httpcache
-from wheezy.http.cache import response_cache
-from wheezy.http.cacheprofile import CacheProfile
-from wheezy.http.response import HTTPResponse
+from wheezy.caching import MemoryCache
+from wheezy.http import CacheProfile
+from wheezy.http import HTTPResponse
+from wheezy.http import WSGIApplication
+from wheezy.http import httpcache
+from wheezy.http import response_cache
 from wheezy.routing import url
 from wheezy.web.caching import handler_cache
-from wheezy.web.handlers.base import BaseHandler
+from wheezy.web.handlers import BaseHandler
 from wheezy.web.middleware import bootstrap_defaults
 from wheezy.web.middleware import path_routing_middleware_factory
 
     return response
 
 
-all_urls=[
+all_urls = [
         url('', httpcache(WelcomeHandler, public_cache_profile, cache)),
         url('welcome2', Welcome2Handler),
         url('now', httpcache(now, public_cache_profile, cache)),

demos/hello/test_helloworld.py

+
+""" ``test_helloworld`` module.
+"""
+
+import unittest
+
+from wheezy.http.functional import WSGIClient
+
+from helloworld import main
+
+
+class HelloworldTestCase(unittest.TestCase):
+
+    def setUp(self):
+        self.client = WSGIClient(main)
+
+    def tearDown(self):
+        del self.client
+        self.client = None
+
+    def test_welcome(self):
+        """ Ensure welcome page is rendered.
+        """
+        assert 200 == self.client.get('/')
+        assert 'Hello' in self.client.content
+
+    def test_welcome2(self):
+        """ Ensure welcome2 page is rendered.
+        """
+        assert 200 == self.client.get('/welcome2')
+        assert 'Hello' in self.client.content
+
+    def test_now(self):
+        """ Ensure now page is rendered.
+        """
+        assert 200 == self.client.get('/now')
+        assert 'It is' in self.client.content
+
+    def test_now2(self):
+        """ Ensure welcome page is rendered.
+        """
+        assert 200 == self.client.get('/now2')
+        assert 'It is' in self.client.content

demos/public/src/app.py

 """
 """
 
-from wheezy.http.application import WSGIApplication
+from wheezy.http import WSGIApplication
 from wheezy.http.middleware import http_cache_middleware_factory
 from wheezy.web.middleware import bootstrap_defaults
 from wheezy.web.middleware import http_error_middleware_factory

demos/public/src/config.py

 
 from datetime import timedelta
 
-from wheezy.caching.memory import MemoryCache
+from wheezy.caching import MemoryCache
 from wheezy.core.collections import defaultdict
 from wheezy.core.i18n import TranslationsManager
-from wheezy.http.cacheprofile import CacheProfile
-from wheezy.http.cacheprofile import RequestVary
-from wheezy.security.crypto.ticket import Ticket
+from wheezy.http import CacheProfile
+from wheezy.http import RequestVary
+from wheezy.security.crypto import Ticket
 from wheezy.web.templates import MakoTemplate
 
 from membership.repository.mock import MockFactory
         }),
 })
 
+# wheezy.security.crypto.Ticket
+options.update({
+        'CRYPTO_ENCRYPTION_KEY': '4oqiKhW3qzP2EiattMt7',
+        'CRYPTO_VALIDATION_KEY': 'A7GfjxIBCBA3vNqvafWf'
+})
+
 # BaseHandler
 options.update({
         'translations_manager': TranslationsManager(
         'ticket': Ticket(
             max_age=1200,
             salt='JNbCog95cDTo1NRb7inP',
-            options={
-                'CRYPTO_ENCRYPTION_KEY': '4oqiKhW3qzP2EiattMt7',
-                'CRYPTO_VALIDATION_KEY': 'A7GfjxIBCBA3vNqvafWf'
-            }),
+            options=options),
 
         'AUTH_COOKIE': '_a',
         'AUTH_COOKIE_DOMAIN': None,

demos/public/src/error/web/views.py

 """
 """
 
-from wheezy.http.response import bad_request
-from wheezy.http.response import forbidden
-from wheezy.http.response import not_found
-from wheezy.web.handlers.template import template_handler
+from wheezy.http import bad_request
+from wheezy.http import forbidden
+from wheezy.http import not_found
+from wheezy.web.handlers import template_handler
 
 
 http400 = template_handler('error/http400.html', status_code=400)

demos/public/src/membership/validation.py

 """
 """
 
+from wheezy.validation import Validator
 from wheezy.validation.rules import compare
 from wheezy.validation.rules import length
 from wheezy.validation.rules import required
-from wheezy.validation.validator import Validator
 
 
 _ = lambda s: s

demos/public/src/membership/web/views.py

 from wheezy.core.collections import attrdict
 from wheezy.core.comp import u
 from wheezy.core.descriptors import attribute
-from wheezy.http.response import bad_request
-from wheezy.security.principal import Principal
+from wheezy.http import bad_request
+from wheezy.security import Principal
 from wheezy.web.caching import handler_cache
-from wheezy.web.handlers.base import BaseHandler
+from wheezy.web.handlers import BaseHandler
 
 from config import none_cache_profile
 from membership.models import Credential

demos/public/src/public/web/urls.py

 """
 
 from wheezy.routing import url
-from wheezy.web.handlers.template import template_handler
+from wheezy.web.handlers import template_handler
 
 from public.web.views import about
 from public.web.views import home

demos/public/src/public/web/views.py

 """
 """
 
-from wheezy.web.handlers.template import template_handler
+from wheezy.web.handlers import template_handler
 
 
 home = template_handler('public/home.html')

demos/public/src/urls.py

 
 from datetime import timedelta
 
-from wheezy.http.cache import httpcache
+from wheezy.http import httpcache
 from wheezy.http.transforms import gzip_transform
 from wheezy.http.transforms import response_transforms
 from wheezy.routing import url
-from wheezy.web.handlers.file import file_handler
-from wheezy.web.handlers.template import template_handler
+from wheezy.web.handlers import file_handler
+from wheezy.web.handlers import template_handler
 
 from config import http_cache as cache
 from config import static_cache_profile

src/wheezy/web/handlers/__init__.py

+
+""" ``handlers`` package.
+"""
+
+from wheezy.web.handlers.base import BaseHandler
+from wheezy.web.handlers.base import RedirectRouteHandler
+from wheezy.web.handlers.base import redirect_handler
+from wheezy.web.handlers.file import FileHandler
+from wheezy.web.handlers.file import file_handler
+from wheezy.web.handlers.method import MethodHandler
+from wheezy.web.handlers.template import TemplateHandler
+from wheezy.web.handlers.template import template_handler

src/wheezy/web/handlers/base.py

 from wheezy.core.uuid import UUID_EMPTY
 from wheezy.core.uuid import parse_uuid
 from wheezy.core.uuid import shrink_uuid
-from wheezy.html.factory import widget
-from wheezy.http.cookie import HTTPCookie
-from wheezy.http.response import HTTPResponse
-from wheezy.http.response import redirect
-from wheezy.security.principal import Principal
-from wheezy.validation.mixin import ValidationMixin
-from wheezy.validation.model import try_update_model
+from wheezy.html import widget
+from wheezy.http import HTTPCookie
+from wheezy.http import HTTPResponse
+from wheezy.http import redirect
+from wheezy.security import Principal
+from wheezy.validation import ValidationMixin
+from wheezy.validation import try_update_model
 from wheezy.web.comp import iteritems
 from wheezy.web.handlers.method import MethodHandler
 

src/wheezy/web/handlers/file.py

 from datetime import timedelta
 
 from wheezy.core.datetime import parse_http_datetime
-from wheezy.http.cachepolicy import HTTPCachePolicy
-from wheezy.http.response import HTTPResponse
+from wheezy.http import HTTPResponse
+from wheezy.http import HTTPCachePolicy
 from wheezy.web.handlers.method import MethodHandler
 
 

src/wheezy/web/handlers/method.py

 """
 """
 
-from wheezy.http.response import method_not_allowed
-from wheezy.http.response import HTTPResponse
+from wheezy.http import method_not_allowed
+from wheezy.http import HTTPResponse
 
 
 class MethodHandler(object):

src/wheezy/web/middleware/__init__.py

 
 from wheezy.core.collections import defaultdict
 from wheezy.core.i18n import TranslationsManager
-from wheezy.routing import Router
-from wheezy.security.crypto.ticket import Ticket
+from wheezy.routing import PathRouter
+from wheezy.security.crypto import Ticket
 from wheezy.web.middleware.errors import HTTPErrorMiddleware
 from wheezy.web.middleware.routing import PathRoutingMiddleware
 from wheezy.web.templates import MakoTemplate
 def bootstrap_defaults(url_mapping=None):
     def load(options):
         if 'path_router' not in options:
-            options['path_router'] = path_router = Router()
+            options['path_router'] = path_router = PathRouter()
         else:
             path_router = options['path_router']
         if url_mapping: