示例#1
0
    def test_must_raise_http_405_using_controller_without_get_method(self):
        self.config_module.urls.url_patterns = (
            (
                url(
                    '/exp1',
                    'tests.mocks.controllers.GetControllerMock',
                    'exp1'
                ),
                url(
                    '/exp2',
                    'tests.mocks.controllers.PutControllerMock',
                    'exp2'
                ),
            )
        )

        handler = Handler()

        request = HttpRequestMock()
        request.method = 'GET'
        request.path_info = '/exp2'

        with self.assertRaises(http.Http405,
            msg="Must be raise a InvalidConfigModuleException"):

            handler.dispatch(request)
    def test_config_must_load_url_patterns(self):
        self.config_module.urls.url_patterns = (
            (
                url(
                    '/exp1',
                    'tests.mocks.controllers.CompleteControllerMock',
                    'exp1'
                ),
                url('/exp2', GetControllerMock, 'exp2'),
            )
        )

        config = ConfigRunner()

        self.assertEqual(
            config.urls,
            (
                (
                    re.compile('^/exp1$'),
                    CompleteControllerMock(),
                    (),
                    'exp1',
                    None
                ),
                (
                    re.compile('^/exp2$'),
                    GetControllerMock(),
                    (),
                    'exp2',
                    None
                ),
            ),
            "ConfigRunner does not load url patterns"
        )
示例#3
0
    def test_create_url_with_multiple_layouts_with_context_processors(self):
        created_url = url(
            "",
            "blog.controller.home",
            name="one",
            layouts={
                "default":{
                    "url_prefix":None,
                    "context_processors":[],
                },
                "android":{
                    "url_prefix":"android/",
                    "context_processors":[],
                }
            },
            context_processors=["menu", "users"],
        )

        self.assertEqual(
            set(created_url[0][2]),
            set(["menu", "users"]),
            msg="URL do not add common context processors to the first URL"
        )

        self.assertEqual(
            set(created_url[1][2]),
            set(["menu", "users"]),
            msg="URL do not add common context processors to the second URL"
        )
示例#4
0
    def test_from_include_with_multiple_layouts_with_common_and_custom_context_processors(self):
        created_url = url(
            "blog/",
            [
                ("^$", "blog.controller.home", [],  "home", None),
                ("^post/$", "blog.controller.post", [], "post", None),
            ],
            layouts={
                "default":{
                "url_prefix":"myweb/",
                "context_processors":["menu", "users"],
                },
                "android":{
                "url_prefix":"android/",
                "context_processors":[],
                }
            },
            context_processors=["common", "context"],
        )

        for url_i in created_url:
            if url_i[4] is "default":
                self.assertEqual(
                    set(url_i[2]),
                    set(["menu", "users", "common", "context"]),
                    msg="URL do not add common context processors to all URL"
                )
            else:
                self.assertEqual(
                    set(url_i[2]),
                    set(["common", "context"]),
                    msg="URL do not add common context processors to all URL"
                )
示例#5
0
    def test_from_include_with_multiple_layouts(self):
        created_url = url(
            "blog/",
            [
                ("^$", "blog.controller.home", [],  "home", None),
                ("^post/$", "blog.controller.post", [], "post", None),
            ],
            layouts={
                "default":{
                    "url_prefix":"myweb/",
                    "context_processors":["users", "menu"],
                },
                "android":{
                    "url_prefix":"android/",
                    "context_processors":["mobile"],
                }
            }

                        )

        self.assertEqual(
            sorted(created_url),
            sorted([
                ("^myweb/blog/$", "blog.controller.home", ["users", "menu"], "home", "default"),
                ("^myweb/blog/post/$", "blog.controller.post", ["users", "menu"], "post", "default"),
                ("^android/blog/$", "blog.controller.home", ["mobile"], "home", "android"),
                ("^android/blog/post/$", "blog.controller.post", ["mobile"], "post", "android"),
            ]),
            msg="URL do not create good urls from include with several layouts"
        )
示例#6
0
    def test_create_url_with_multiple_layouts_without_context_processors(self):
        created_url = url(
            "",
            "blog.controller.home",
            name="one",
            layouts={
                "default":{
                    "url_prefix":None,
                    "context_processors":[],
                },
                "android":{
                    "url_prefix":"android/",
                    "context_processors":[],
                }
            }
        )

        self.assertEqual(
            sorted(created_url),
            sorted([
                ("^$", "blog.controller.home", [], "one", "default"),
                ("^android/$", "blog.controller.home", [], "one", "android")
            ]),
            msg="URL do not create a url with multiple layouts without \
                context_processors"
        )
示例#7
0
    def test_middleware_level0_must_add_mw_field_to_request_and_response(self):
        GetControllerMock.get = lambda self, *args, **kwargs: \
            http.Http200()

        self.config_module.urls.url_patterns = (
            (
                url('/exp1', GetControllerMock, 'exp1'),
            )
        )

        CompleteMiddlewareLevel0Mock.process_request = lambda self, request: \
            setattr(request, 'mw', True)

        CompleteMiddlewareLevel0Mock.process_response = \
            lambda self, request, response: \
                setattr(response, 'mw', True)

        self.config_module.middleware_level0.append(
            CompleteMiddlewareLevel0Mock
        )

        handler = Handler()

        request = HttpRequestMock()
        request.method = 'GET'
        request.path_info = '/exp1'
        request.accept['text/html'] = 1.0

        response = handler.dispatch(request)

        self.assertTrue(
            getattr(request, 'mw', False) and getattr(response, 'mw', False),
            "Middleware level0 does not add 'mw' field to request and response"
        )
示例#8
0
    def test_create_url_with_none_name(self):

        with self.assertRaises(
            UrlNoneNameException,
            msg="URL without a include method as target can not have a \
                None name or empty Name"
        ):
            created_url = url("", "blog.controller.home",)
示例#9
0
    def test_create_url(self):
        created_url = url("", "blog.controller.home", name="one" )

        self.assertEqual(
            created_url,
            [("^$", "blog.controller.home", [], "one", None),],
            msg="URL do not create a simple url tuple"
        )
示例#10
0
    def test_create_url_with_context_processors(self):
        created_url = url(
            "",
            "blog.controller.home",
            name="one",
            context_processors=["menu", "users"]
        )

        self.assertEqual(
            set(created_url[0][2]),
            set(["menu", "users"]),
            msg="URL do not create a url with context_processors"
        )
    def test_config_must_raise_on_bad_re(self):
        self.config_module.urls.url_patterns = (
            (
                url(
                    '/exp[\w-\b]',
                    'tests.mocks.controllers.CompleteControllerMock',
                    'exp1'
                ),
            )
        )

        with self.assertRaises(URLBadformedException,
            msg="Error on regular expression"):

            ConfigRunner()
    def test_config_must_raise_on_bad_import(self):
        self.config_module.urls.url_patterns = (
            (
                url(
                    '/exp1',
                    'tests.mocks.controllers.NoReallyMock',
                    'exp1'
                ),
            )
        )

        with self.assertRaises(ControllerNotFoundException,
            msg="Controller not found"):

            ConfigRunner()
示例#13
0
    def test_from_include_with_names(self):
        created_url = url(
            "blog/",
            [
                ("^$", "blog.controller.home", [],  "get", None),
                ("^post/$", "blog.controller.post", [], "post", None),
            ]
        )

        self.assertEqual(
            sorted(created_url),
            sorted([
                ("^blog/$", "blog.controller.home", [], "get", None),
                ("^blog/post/$", "blog.controller.post", [], "post", None),
            ]),
            msg="URL do not create good urls from include with names"
        )
    def test_config_must_raise_on_bad_context_processor(self):
        self.config_module.urls.url_patterns = (
            (
                url(
                    '/exp1',
                    'tests.mocks.controllers.CompleteControllerMock',
                    'exp1',
                    context_processors=(
                        'tests.mocks.context_processors.bad_context_processor',
                    )
                ),
            )
        )

        with self.assertRaises(ContextProcessorNotFoundException,
            msg="Context processor not found"):

            ConfigRunner()
示例#15
0
    def test_must_not_launch_exception_with_200_response(self):
        GetControllerMock.get = lambda self, *args, **kwargs: \
            http.Http200()

        self.config_module.urls.url_patterns = (
            (
                url('/exp1', GetControllerMock, 'exp1'),
            )
        )

        handler = Handler()

        request = HttpRequestMock()
        request.method = 'GET'
        request.path_info = '/exp1'
        request.accept['text/html'] = 1.0

        response = handler.dispatch(request)
示例#16
0
    def test_create_url_with_one_layout(self):
        created_url = url(
            "",
            "blog.controller.home",
            name="one",
            layouts={
                "default":{
                    "url_prefix":"blog/",
                    "context_processors":["menu", "users"],
                },
            }
        )

        self.assertEqual(
            set(created_url[0][2]),
            set(["menu", "users"]),
            msg="URL do not create a url with full layout"
        )
示例#17
0
    def test_from_include_with_context_processors(self):
        created_url = url(
            "blog/",
            [
                ("^$", "blog.controller.home", [],  "home", None),
                ("^post/$", "blog.controller.post", [], "post", None),
            ],
            context_processors=["menu", "users"],
        )

        self.assertEqual(
            sorted(created_url),
            sorted([
                ("^blog/$", "blog.controller.home", ["menu", "users"], "home", None),
                ("^blog/post/$", "blog.controller.post", ["menu", "users"], "post", None),
            ]),
            msg="URL do not create good urls with common context processors"
        )
示例#18
0
    def test_create_url_with_one_layout_without_context_processors(self):
        created_url = url(
            "",
            "blog.controller.home",
            name="one",
            layouts={
                "default":{
                    "url_prefix":"blog/",
                    "context_processors":[],
                },
            }
        )

        self.assertEqual(
            created_url,
            [("^blog/$", "blog.controller.home", [], "one", "default")],
            msg="URL do not create a url with one layout without \
                context_processors"
        )
示例#19
0
    def test_must_not_launch_exception_with_context_data_response(self):
        GetControllerMock.get = lambda self, *args, **kwargs: \
            { 'title': 'Just now' }

        self.config_module.urls.url_patterns = (
            (
                url('/exp1', GetControllerMock, 'exp1'),
            )
        )

        handler = Handler()

        request = HttpRequestMock()
        request.method = 'GET'
        request.path_info = '/exp1'
        request.accept['text/html'] = 1.0

        with self.assertRaises(http.Http415,
            msg="Must be raise a Http415"):
            handler.dispatch(request)
    def test_config_must_not_load_an_not_callable_controller(self):
        test_module = types.ModuleType('test_module')
        test_module.NotCallableController = 'fake'

        sys.modules.setdefault('test_module', test_module)

        self.config_module.urls.url_patterns = (
            (
                url(
                    '/exp1',
                    'test_module.NotCallableController',
                    'exp1'
                ),
            )
        )

        with self.assertRaises(ControllerNotFoundException,
            msg="Controller not callable"):

            ConfigRunner()

        sys.modules.pop('test_module')
示例#21
0
    def test_must_render_a_response(self):
        self.config_module.templates['directory'] = \
            os.path.join(os.getcwd(), 'tests/data/templates/')

        GetControllerMock.get = lambda self, *args, **kwargs: \
            { 'title': 'Just now' }

        self.config_module.urls.url_patterns = (
            (
                url('/home', GetControllerMock, 'home'),
            )
        )

        handler = Handler()

        request = HttpRequestMock()
        request.method = 'GET'
        request.path_info = '/home'
        request.accept['text/html'] = 1.0

        response = handler.dispatch(request)

        self.assertTrue(response.status_code, 200)
示例#22
0
    def test_from_include_with_one_layout(self):
        created_url = url(
            "blog/",
            [
                ("^$", "blog.controller.home", [],  "home", None),
                ("^post/$", "blog.controller.post", [], "post", None),
            ],
            layouts={
                "default":{
                    "url_prefix":"myweb/",
                    "context_processors":["menu", "users"],
                },
            }
        )

        self.assertEqual(
            sorted(created_url),
            sorted([
                ("^myweb/blog/$", "blog.controller.home", ["menu", "users"], "home", "default"),
                ("^myweb/blog/post/$", "blog.controller.post", ["menu", "users"], "post", "default"),
            ]),
            msg="URL do not create good urls from include with layout"
        )
示例#23
0
from agiliza.config.urls import url, include


url_patterns = (
    #url("app/", include("app.config.url")),
    url("/book/(?P<book_slug>[-\w_]+)/", "looleo.controllers.Book",
        name="book_reviews",
        context_processors=["looleo.context_processors.book.import_dumps"],),
    url("/book/", "looleo.controllers.BookCreator", name="book"),
    
    url("/user/login/", "looleo.controllers.UserLogin", name="user_login"),
    url("/user/logout/", "looleo.controllers.UserLogout", name="user_logout"),
    url("/user/(?P<username>[-\w_]+)/", "looleo.controllers.User", name="user_reviews"),
    url("/user/", "looleo.controllers.UserCreator", name="user"),
    
    url("/", "looleo.controllers.Home",
        name="home",
        context_processors=[
        "looleo.context_processors.book.ultimos_12_libros",
        "looleo.context_processors.book.import_dumps",
        ],
    ),
)