def test_valid_pathname_prefix_init(self): _, routes, req = _configs.pathname_configs() self.assertEqual('/', routes) self.assertEqual('/', req) _, routes, req = _configs.pathname_configs( routes_pathname_prefix='/dash/') self.assertEqual('/dash/', req) _, routes, req = _configs.pathname_configs( requests_pathname_prefix='/my-dash-app/', ) self.assertEqual(routes, '/') self.assertEqual(req, '/my-dash-app/') _, routes, req = _configs.pathname_configs( routes_pathname_prefix='/dash/', requests_pathname_prefix='/my-dash-app/dash/' ) self.assertEqual('/dash/', routes) self.assertEqual('/my-dash-app/dash/', req)
def test_invalid_pathname_prefix(self): with self.assertRaises(_exc.InvalidConfig) as context: _, _, _ = pathname_configs('/my-path', '/another-path') self.assertTrue('url_base_pathname' in str(context.exception)) with self.assertRaises(_exc.InvalidConfig) as context: _, _, _ = pathname_configs(url_base_pathname='/invalid', routes_pathname_prefix='/invalid') self.assertTrue( str(context.exception).split('.')[0].endswith( '`routes_pathname_prefix`')) with self.assertRaises(_exc.InvalidConfig) as context: _, _, _ = pathname_configs( url_base_pathname='/my-path', requests_pathname_prefix='/another-path') self.assertTrue( str(context.exception).split('.')[0].endswith( '`requests_pathname_prefix`')) with self.assertRaises(_exc.InvalidConfig) as context: _, _, _ = pathname_configs('my-path') self.assertTrue('start with `/`' in str(context.exception)) with self.assertRaises(_exc.InvalidConfig) as context: _, _, _ = pathname_configs('/my-path') self.assertTrue('end with `/`' in str(context.exception))
def test_valid_pathname_prefix_init(empty_environ, route_prefix, req_prefix, expected_route, expected_req): _, routes, req = pathname_configs(routes_pathname_prefix=route_prefix, requests_pathname_prefix=req_prefix) if expected_route is not None: assert routes == expected_route assert req == expected_req
def test_invalid_pathname_prefix(empty_environ): with pytest.raises(_exc.InvalidConfig, match="url_base_pathname"): _, _, _ = pathname_configs("/my-path", "/another-path") with pytest.raises(_exc.InvalidConfig) as excinfo: _, _, _ = pathname_configs( url_base_pathname="/invalid", routes_pathname_prefix="/invalid" ) assert str(excinfo.value).split(".")[0].endswith("`routes_pathname_prefix`") with pytest.raises(_exc.InvalidConfig) as excinfo: _, _, _ = pathname_configs( url_base_pathname="/my-path", requests_pathname_prefix="/another-path" ) assert str(excinfo.value).split(".")[0].endswith("`requests_pathname_prefix`") with pytest.raises(_exc.InvalidConfig, match="start with `/`"): _, _, _ = pathname_configs("my-path") with pytest.raises(_exc.InvalidConfig, match="end with `/`"): _, _, _ = pathname_configs("/my-path")
def test_pathname_prefix_environ_requests(self): os.environ['DASH_REQUESTS_PATHNAME_PREFIX'] = '/requests/' _, _, req = pathname_configs() self.assertEqual('/requests/', req)
def test_pathname_prefix_environ_routes(self): os.environ['DASH_ROUTES_PATHNAME_PREFIX'] = '/routes/' _, routes, _ = pathname_configs() self.assertEqual('/routes/', routes)
def test_pathname_prefix_from_environ_app_name(self): os.environ['DASH_APP_NAME'] = 'my-dash-app' _, routes, req = pathname_configs() self.assertEqual('/my-dash-app/', req) self.assertEqual('/', routes)
def test_pathname_prefix_environ_requests(empty_environ): os.environ["DASH_REQUESTS_PATHNAME_PREFIX"] = "/requests/" _, _, req = pathname_configs() assert req == "/requests/"
def test_pathname_prefix_environ_routes(empty_environ): os.environ["DASH_ROUTES_PATHNAME_PREFIX"] = "/routes/" _, routes, _ = pathname_configs() assert routes == "/routes/"
def test_pathname_prefix_from_environ_app_name(empty_environ): os.environ["DASH_APP_NAME"] = "my-dash-app" _, routes, req = pathname_configs() assert req == "/my-dash-app/" assert routes == "/"