def test_can_set_included_routes_using_except_config(self): Config.set("js_routes.filters.except", ["posts.s*", "home"]) routes = JsRoutes().to_dict()["routes"] expected = { "posts.index": { "uri": "posts", "methods": ["GET"], "bindings": {} }, "postComments.index": { "uri": "posts/{post}/comments", "methods": ["GET"], "bindings": {}, }, "postComments.show": { "uri": "posts/{post}/comments/{comment}", "methods": ["GET"], "bindings": {}, }, "admin.users.index": { "uri": "admin/users", "methods": ["GET"], "bindings": {}, }, } self.assertEqual(expected, routes)
def test_returns_unfiltered_routes_when_both_only_and_except_configs_set( self): Config.set( "js_routes.filters", { "except": ["posts.s*", "home"], "only": ["some.other.routes"], "groups": [] }, ) routes = JsRoutes().to_dict()["routes"] self.assertEqual(all_expected_routes, routes)
def test_can_set_included_routes_using_groups_config(self): Config.set("js_routes.filters.groups", {"posts": ["posts.s*"]}) self.application.bind("config.js_routes", "tests.unit.test_routes") routes = JsRoutes("posts").to_dict()["routes"] expected = { "posts.show": { "uri": "posts/{post}", "methods": ["GET"], "bindings": {} }, "posts.store": { "uri": "posts", "methods": ["POST"], "bindings": {} }, } self.assertEqual(expected, routes)
def test_can_set_included_routes_using_only_config(self): Config.set("js_routes.filters.only", ["posts.s*", "home"]) routes = JsRoutes().to_dict()["routes"] expected = { "home": { "uri": "home", "methods": ["GET"], "bindings": {} }, "posts.show": { "uri": "posts/{post}", "methods": ["GET"], "bindings": {} }, "posts.store": { "uri": "posts", "methods": ["POST"], "bindings": {} }, } self.assertEqual(expected, routes)
def test_can_set_included_routes_using_groups_array_config(self): Config.set("js_routes.filters.groups", { "posts": ["posts.s*"], "admin": ["admin.*"] }) routes = JsRoutes(["posts", "admin"]).to_dict()["routes"] expected = { "posts.show": { "uri": "posts/{post}", "methods": ["GET"], "bindings": {} }, "posts.store": { "uri": "posts", "methods": ["POST"], "bindings": {} }, "admin.users.index": { "uri": "admin/users", "methods": ["GET"], "bindings": {}, }, } self.assertEqual(expected, routes)
def tearDown(self): super().tearDown() Config.set("js_routes", self.original_config)
def can_ignore_passed_group_not_set_in_config(self): Config.set("js_routes.filters.groups", {"posts": ["posts.s*"]}) routes = JsRoutes(["unknown_group"]).to_dict()["routes"] self.assertEqual(all_expected_routes, routes)