def test_strip_whitespace(self): self.assertEqual(MacroUrlPattern('').compiled, '^$') self.assertEqual(MacroUrlPattern(' news/all/').compiled, '^news/all/$') self.assertEqual( MacroUrlPattern('^news/all/$ ').compiled, '^news/all/$') self.assertEqual( MacroUrlPattern(' ^news/all/ ').compiled, '^news/all/$') self.assertEqual( MacroUrlPattern(' ^news/all/ \n').compiled, '^news/all/$')
def test_nomacro(self): self.assertEqual(MacroUrlPattern('^$').compiled, '^$') self.assertEqual( MacroUrlPattern('^news/all/$').compiled, '^news/all/$') self.assertEqual( MacroUrlPattern('^news/all/$').compiled, '^news/all/$') self.assertEqual( MacroUrlPattern('^news/all/$').compiled, '^news/all/$') self.assertEqual( MacroUrlPattern('^news/:news/$').compiled, '^news/:news/$')
def test_page(self): self.assertEqual( MacroUrlPattern('page/:page').compiled, '^page/(?P<page>\d+)$') self.assertEqual( MacroUrlPattern('product/:product_page').compiled, '^product/(?P<product_page>\d+)$') self.assertEqual( MacroUrlPattern('product/:page/:product_page').compiled, '^product/(?P<page>\d+)/(?P<product_page>\d+)$') self.assertEqual( MacroUrlPattern('product/:page/:product_page/:news_page').compiled, '^product/(?P<page>\d+)/(?P<product_page>\d+)/(?P<news_page>\d+)$')
def test_id(self): self.assertEqual( MacroUrlPattern('page/:id').compiled, '^page/(?P<id>\d+)$') self.assertEqual( MacroUrlPattern('product/:product_id').compiled, '^product/(?P<product_id>\d+)$') self.assertEqual( MacroUrlPattern('product/:id/:product_id').compiled, '^product/(?P<id>\d+)/(?P<product_id>\d+)$') self.assertEqual( MacroUrlPattern('product/:id/:product_id/:news_id').compiled, '^product/(?P<id>\d+)/(?P<product_id>\d+)/(?P<news_id>\d+)$')
def test_strongurl(self): self.assertEqual( MacroUrlPattern( 'orders/:date/:uuid/products/:slug/:variant_id').compiled, '^orders/(?P<date>\\d{4}-(0?([1-9])|10|11|12)-((0|1|2)?([1-9])|[1-3]0|31))/(?P<uuid>[' 'a-fA-F0-9]{8}-?[a-fA-F0-9]{4}-?[1345][a-fA-F0-9]{3}-?[a-fA-F0-9]{4}-?[a-fA-F0-9]{' '12})/products/(?P<slug>[\\w-]+)/(?P<variant_id>\\d+)$')
def test_year(self): self.assertEqual( MacroUrlPattern('news/:year').compiled, '^news/(?P<year>\d{4})$')
def test_slug(self): self.assertEqual( MacroUrlPattern('page/:slug').compiled, '^page/(?P<slug>[\w-]+)$') self.assertEqual( MacroUrlPattern('page/:category_slug/:slug').compiled, '^page/(?P<category_slug>[\w-]+)/(?P<slug>[\w-]+)$')
def test_normalize_url(self): self.assertEqual(MacroUrlPattern('').compiled, '^$') self.assertEqual(MacroUrlPattern('news/all/').compiled, '^news/all/$') self.assertEqual( MacroUrlPattern('^news/all/$').compiled, '^news/all/$') self.assertEqual(MacroUrlPattern('^news/all/').compiled, '^news/all/$')
def test_uid(self): self.assertEqual( MacroUrlPattern('invoice/:uuid').compiled, '^invoice/(?P<uuid>[a-fA-F0-9]{8}-?[a-fA-F0-9]{4}-?[1345][a-fA-F0-9]{3}-?[a-fA-F0-9]{4}-?[' 'a-fA-F0-9]{12})$')
def test_date(self): self.assertEqual( MacroUrlPattern('news/:date/').compiled, '^news/(?P<date>\d{4}-(0?([1-9])|10|11|12)-((0|1|2)?([1-9])|[1-3]0|31))/$' )
def test_year_month_day(self): self.assertEqual( MacroUrlPattern('news/:year/:month/:day/').compiled, '^news/(?P<year>\d{4})/(?P<month>(0?([1-9])|10|11|12))/(?P<day>((0|1|2)?([1-9])|[1-3]0|31))/$' )
def test_year_month(self): self.assertEqual( MacroUrlPattern('news/:year/:month').compiled, '^news/(?P<year>\d{4})/(?P<month>(0?([1-9])|10|11|12))$')