Example #1
0
    def test_with_variables_name_and_handler(self):
        router = webapp2.Router([
            PathPrefixRoute('/user/<username:\w+>', [
                HandlerPrefixRoute('apps.users.', [
                    NamePrefixRoute('user-', [
                        webapp2.Route('/', 'UserOverviewHandler', 'overview'),
                        webapp2.Route('/profile', 'UserProfileHandler',
                                      'profile'),
                        webapp2.Route('/projects', 'UserProjectsHandler',
                                      'projects'),
                    ]),
                ]),
            ])
        ])

        path = '/user/calvin/'
        match = ((), {'username': '******'})
        self.assertEqual(router.match(webapp2.Request.blank(path))[1:], match)
        self.assertEqual(
            router.build(webapp2.Request.blank('/'), 'user-overview', match[0],
                         match[1]), path)

        path = '/user/calvin/profile'
        match = ((), {'username': '******'})
        self.assertEqual(router.match(webapp2.Request.blank(path))[1:], match)
        self.assertEqual(
            router.build(webapp2.Request.blank('/'), 'user-profile', match[0],
                         match[1]), path)

        path = '/user/calvin/projects'
        match = ((), {'username': '******'})
        self.assertEqual(router.match(webapp2.Request.blank(path))[1:], match)
        self.assertEqual(
            router.build(webapp2.Request.blank('/'), 'user-projects', match[0],
                         match[1]), path)
Example #2
0
    def test_with_variables_name_and_handler(self):
        router = webapp2.Router([
            DomainRoute('<subdomain>.<:.*>', [
                PathPrefixRoute(r'/user/<username:\w+>', [
                    HandlerPrefixRoute('apps.users.', [
                        NamePrefixRoute('user-', [
                            webapp2.Route(
                                '/',
                                'UserOverviewHandler',
                                'overview'
                            ),
                            webapp2.Route(
                                '/profile',
                                'UserProfileHandler',
                                'profile'
                            ),
                            webapp2.Route(
                                '/projects',
                                'UserProjectsHandler',
                                'projects'
                            ),
                        ]),
                    ]),
                ])
            ]),
        ])

        path = 'http://my-subdomain.app-id.appspot.com/user/calvin/'
        match = ((), {'username': '******', 'subdomain': 'my-subdomain'})
        self.assertEqual(router.match(webapp2.Request.blank(path))[1:], match)
        match[1].pop('subdomain')
        match[1]['_netloc'] = 'my-subdomain.app-id.appspot.com'
        self.assertEqual(
            router.build(webapp2.Request.blank('/'),
                         'user-overview', match[0], match[1]),
            path
        )

        path = 'http://my-subdomain.app-id.appspot.com/user/calvin/profile'
        match = ((), {'username': '******', 'subdomain': 'my-subdomain'})
        self.assertEqual(router.match(webapp2.Request.blank(path))[1:], match)
        match[1].pop('subdomain')
        match[1]['_netloc'] = 'my-subdomain.app-id.appspot.com'
        self.assertEqual(
            router.build(webapp2.Request.blank('/'),
                         'user-profile', match[0], match[1]),
            path
        )

        path = 'http://my-subdomain.app-id.appspot.com/user/calvin/projects'
        match = ((), {'username': '******', 'subdomain': 'my-subdomain'})
        self.assertEqual(router.match(webapp2.Request.blank(path))[1:], match)
        match[1].pop('subdomain')
        match[1]['_netloc'] = 'my-subdomain.app-id.appspot.com'

        self.assertEqual(
            router.build(webapp2.Request.blank('/'),
                         'user-projects', match[0], match[1]),
            path
        )
Example #3
0
    def test_with_variables_name_and_handler(self):
        router = webapp2.Router(
            [
                DomainRoute(
                    "<subdomain>.<:.*>",
                    [
                        PathPrefixRoute(
                            r"/user/<username:\w+>",
                            [
                                HandlerPrefixRoute(
                                    "apps.users.",
                                    [
                                        NamePrefixRoute(
                                            "user-",
                                            [
                                                webapp2.Route(
                                                    "/",
                                                    "UserOverviewHandler",
                                                    "overview",
                                                ),
                                                webapp2.Route(
                                                    "/profile",
                                                    "UserProfileHandler",
                                                    "profile",
                                                ),
                                                webapp2.Route(
                                                    "/projects",
                                                    "UserProjectsHandler",
                                                    "projects",
                                                ),
                                            ],
                                        ),
                                    ],
                                ),
                            ],
                        )
                    ],
                ),
            ]
        )

        path = "http://my-subdomain.app-id.appspot.com/user/calvin/"
        match = ((), {"username": "******", "subdomain": "my-subdomain"})
        self.assertEqual(router.match(webapp2.Request.blank(path))[1:], match)
        match[1].pop("subdomain")
        match[1]["_netloc"] = "my-subdomain.app-id.appspot.com"
        self.assertEqual(
            router.build(
                webapp2.Request.blank("/"), "user-overview", match[0], match[1]
            ),
            path,
        )

        path = "http://my-subdomain.app-id.appspot.com/user/calvin/profile"
        match = ((), {"username": "******", "subdomain": "my-subdomain"})
        self.assertEqual(router.match(webapp2.Request.blank(path))[1:], match)
        match[1].pop("subdomain")
        match[1]["_netloc"] = "my-subdomain.app-id.appspot.com"
        self.assertEqual(
            router.build(
                webapp2.Request.blank("/"), "user-profile", match[0], match[1]
            ),
            path,
        )

        path = "http://my-subdomain.app-id.appspot.com/user/calvin/projects"
        match = ((), {"username": "******", "subdomain": "my-subdomain"})
        self.assertEqual(router.match(webapp2.Request.blank(path))[1:], match)
        match[1].pop("subdomain")
        match[1]["_netloc"] = "my-subdomain.app-id.appspot.com"

        self.assertEqual(
            router.build(
                webapp2.Request.blank("/"), "user-projects", match[0], match[1]
            ),
            path,
        )
Example #4
0
    def test_with_variables_name_and_handler(self):
        router = webapp2.Router(
            [
                PathPrefixRoute(
                    r"/user/<username:\w+>",
                    [
                        HandlerPrefixRoute(
                            "apps.users.",
                            [
                                NamePrefixRoute(
                                    "user-",
                                    [
                                        webapp2.Route(
                                            "/", "UserOverviewHandler", "overview"
                                        ),
                                        webapp2.Route(
                                            "/profile", "UserProfileHandler", "profile"
                                        ),
                                        webapp2.Route(
                                            "/projects",
                                            "UserProjectsHandler",
                                            "projects",
                                        ),
                                    ],
                                ),
                            ],
                        ),
                    ],
                )
            ]
        )

        path = "/user/calvin/"
        match = ((), {"username": "******"})
        self.assertEqual(router.match(webapp2.Request.blank(path))[1:], match)
        self.assertEqual(
            router.build(
                webapp2.Request.blank("/"), "user-overview", match[0], match[1]
            ),
            path,
        )

        path = "/user/calvin/profile"
        match = ((), {"username": "******"})
        self.assertEqual(router.match(webapp2.Request.blank(path))[1:], match)
        self.assertEqual(
            router.build(
                webapp2.Request.blank("/"), "user-profile", match[0], match[1]
            ),
            path,
        )

        path = "/user/calvin/projects"
        match = ((), {"username": "******"})
        self.assertEqual(router.match(webapp2.Request.blank(path))[1:], match)
        self.assertEqual(
            router.build(
                webapp2.Request.blank("/"), "user-projects", match[0], match[1]
            ),
            path,
        )