class PlainEndpointTestCase(unittest.TestCase): def setUp(self): super(PlainEndpointTestCase, self).setUp() self.endpoint = PlainEndpoint("/api/", MethodBasedView, "GET", None) def test_matched_path(self): matched_path = "/api/" self.assertEqual(self.endpoint.match(matched_path), ()) def test_unmatched_path(self): unmatched_path = "/api/another" self.assertEqual(self.endpoint.match(unmatched_path), None)
class PlainEndpointTestCase(unittest.TestCase): def setUp(self): super(PlainEndpointTestCase, self).setUp() self.endpoint = PlainEndpoint('/api/', MethodBasedView, 'GET', None) def test_matched_path(self): matched_path = '/api/' self.assertEqual(self.endpoint.match(matched_path), ()) def test_unmatched_path(self): unmatched_path = '/api/another' self.assertEqual(self.endpoint.match(unmatched_path), None)
def define_route(self, path, handler, methods, name=None): """ Define a router as instance of BaseRoute subclass, which passed from register method in RestWSRouter. :param path: URL, which used to get access to API. :param handler: class inherited from MethodBasedView, which used for processing request. :param methods: list of available for user methods or string with concrete method name. :param name: the base to use for the URL names that are created. """ # it's PlainRoute, when don't have any "dynamic symbols" if all(symbol not in path for symbol in ['{', '}']): return PlainEndpoint(path, handler, methods, name) # Try to processing as a dynamic path pattern = '' for part in DYNAMIC_PARAMETER.split(path): match = VALID_DYNAMIC_PARAMETER.match(part) if match: pattern += '(?P<{}>{})'.format(match.group('var'), ANY_VALUE) continue if any(symbol in part for symbol in ['{', '}']): raise EndpointValueError("Invalid {} part of {} path".format(part, path)) # NOQA pattern += re.escape(part) try: compiled = re.compile("^{}$".format(pattern)) except re.error as exc: raise EndpointValueError("Bad pattern '{}': {}".format(pattern, exc)) # NOQA return DynamicEndpoint(path, handler, methods, name, compiled)
def setUp(self): super(PlainEndpointTestCase, self).setUp() self.endpoint = PlainEndpoint("/api/", MethodBasedView, "GET", None)
def setUp(self): super(PlainEndpointTestCase, self).setUp() self.endpoint = PlainEndpoint('/api/', MethodBasedView, 'GET', None)