Skip to content
This repository has been archived by the owner on Dec 4, 2018. It is now read-only.

Commit

Permalink
Merge pull request #838 from cfpb/section_or_subterp_diffs
Browse files Browse the repository at this point in the history
Properly fix subterp diff URL regex
  • Loading branch information
chosak authored Nov 13, 2017
2 parents 41bc0d4 + 9e90f33 commit c8e38f2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
27 changes: 21 additions & 6 deletions regulations/tests/urls_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
import re

from unittest import TestCase
from django.core.urlresolvers import reverse, resolve

from regulations.urls import section_or_subterp_pattern


class RegexTests(TestCase):
def test_section_or_subterp_matches_section(self):
self.assertRegexpMatches('201-2', section_or_subterp_pattern)

def test_section_or_subterp_matches_subterp_appendices(self):
self.assertRegexpMatches(
'201-Appendices-Interp',
section_or_subterp_pattern
)

def test_section_or_subterp_matches_subterp_subpart(self):
self.assertRegexpMatches(
'201-Subpart-XY-Interp',
section_or_subterp_pattern
)


class UrlTests(TestCase):
def test_about(self):
Expand Down Expand Up @@ -33,9 +54,3 @@ def test_diff_url(self):
args=('201-2', '2011-1738_20121011', '2012-22345_20131022'))
self.assertEqual(
r, '/diff/201-2/2011-1738_20121011/2012-22345_20131022')

def test_diff_url_supports_multiple_dashes(self):
r = reverse(
'chrome_section_diff_view',
args=('201-Interp-XYZ', '2011-1738', '2012-22345'))
self.assertEqual(r, '/diff/201-Interp-XYZ/2011-1738/2012-22345')
13 changes: 11 additions & 2 deletions regulations/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,19 @@
notice_pattern = meta_version % 'notice_id'

reg_pattern = r'(?P<label_id>[\d]+)'
section_pattern = r'(?P<label_id>[\d]+[-][\w-]+)'
section_pattern = r'(?P<label_id>[\d]+[-][\w]+)'
interp_pattern = r'(?P<label_id>[-\d\w]+[-]Interp)'
paragraph_pattern = r'(?P<label_id>[-\d\w]+)'
subterp_pattern = r'(?P<label_id>[\d]+-(Appendices|Subpart(-[A-Z]+)?)-Interp)'
section_or_subterp_pattern = (
r'(?P<label_id>'
'[\d]+'
'('
'([-][\w]+)|'
'(-(Appendices|Subpart(-[A-Z]+)?)-Interp)'
')'
')'
)

lt_cache = cache_page(settings.CACHES['eregs_longterm_cache']['TIMEOUT'],
cache='eregs_longterm_cache')
Expand Down Expand Up @@ -63,7 +72,7 @@
# Diff view of a section for non-JS viewers (or book markers)
# Example: http://.../diff/201-4/2011-1738/2013-10704
url(r'^diff/%s/%s/%s$' %
(section_pattern, version_pattern, newer_version_pattern),
(section_or_subterp_pattern, version_pattern, newer_version_pattern),
lt_cache(ChromeSectionDiffView.as_view()),
name='chrome_section_diff_view'),
# Redirect to version by date
Expand Down

0 comments on commit c8e38f2

Please sign in to comment.