def assertSorted(self, templates): matchers = sorted( URITemplateMatcher(URITemplate(t)) for t in templates) self.assertEqual(templates, [ matcher.template.uri for matcher in matchers]) self.assertEqual(templates, [ matcher.template.uri for matcher in sorted( list(reversed(matchers)))])
def test_interim_query(self): # query variables are not exactly implemented due to significant # complexities involved with integration with various platforms # and frameworks. template = URITemplate('/{root}/somewhere{?hello}') url = '/value/somewhere' matcher = URITemplateMatcher(template) result = matcher(url) # missing values ignored self.assertEqual({ 'root': 'value', }, result)
def compile(self): self._trace = [] self._converters = {} self._static_weights = [] self._argument_weights = [] # need to populate self.arguments # XXX subdomain and/or host ignored self._trace.append((False, '|')) for t, n, c, p in template_to_regex_patternstr.iter_template( self.rule): self._trace.append((isinstance(t, URIVariable), c)) self._matcher = URITemplateMatcher(self.rule)
def test_mismatch_types(self): with self.assertRaises(TypeError): sorted([ '/raw_string', URITemplateMatcher(URITemplate('/template')) ])
def test_matcher_equality_dynamic(self): first = URITemplateMatcher(URITemplate('/test{/path*}')) second = URITemplateMatcher(URITemplate('/test{/path*}')) self.assertEqual(first, second)
def test_matcher_equality_static(self): first = URITemplateMatcher(URITemplate('/test')) second = URITemplateMatcher(URITemplate('/test')) self.assertEqual(first, second)
def test_matcher_invalid(self): with self.assertRaises(ValueError): URITemplateMatcher(URITemplate('/{value}/{value}'))
def test_matcher_basics(self): static = URITemplateMatcher(URITemplate('/test')) self.assertEqual(static('/test'), {})