Skip to content

Commit 99df95d

Browse files
committed
Cleaned up created names. Improved validation during migration. Cleaned up migration output. Cleaned the last of the awp includes from secr views. Removed now unused secr templates. Build extresource urls correctly during submission and when creating group wikis.
- Legacy-Id: 18158
1 parent 53f7bc3 commit 99df95d

17 files changed

Lines changed: 14883 additions & 14896 deletions

File tree

ietf/doc/migrations/0034_populate_docextresources.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55

66
import re
77

8-
import debug
8+
import debug # pyflakes:ignore
99

1010
from collections import OrderedDict, Counter
11+
from io import StringIO
1112

1213
from django.db import migrations
1314

@@ -30,14 +31,12 @@
3031
"Github page": "github_repo",
3132
"GitHub repo.*": "github_repo",
3233
"Github repository.*": "github_repo",
33-
"GitHub notifications": "github_notify",
3434
"GitHub org.*": "github_org",
3535
"GitHub User.*": "github_username",
3636
"GitLab User": "gitlab_username",
3737
"GitLab User Name": "gitlab_username",
3838
}
3939

40-
# TODO: Review all the None values below and make sure ignoring the URLs they match is really the right thing to do.
4140
url_map = OrderedDict({
4241
"https?://github\\.com": "github_repo",
4342
"https://git.sr.ht/": "repo",
@@ -62,19 +61,25 @@ def forward(apps, schema_editor):
6261
DocumentUrl = apps.get_model('doc', 'DocumentUrl')
6362

6463
stats = Counter()
64+
stats_file = StringIO()
6565

6666
for doc_url in DocumentUrl.objects.all():
67+
doc_url.url = doc_url.url.strip()
6768
match_found = False
6869
for regext,slug in name_map.items():
69-
if re.match(regext, doc_url.desc):
70+
if re.fullmatch(regext, doc_url.desc):
7071
match_found = True
7172
stats['mapped'] += 1
7273
name = ExtResourceName.objects.get(slug=slug)
73-
DocExtResource.objects.create(doc=doc_url.doc, name_id=slug, value=doc_url.url, display_name=doc_url.desc) # TODO: validate this value against name.type
74+
try:
75+
validate_external_resource_value(name, doc_url.url)
76+
DocExtResource.objects.create(doc=doc_url.doc, name_id=slug, value=doc_url.url, display_name=doc_url.desc)
77+
except ValidationError as e: # pyflakes:ignore
78+
print("Failed validation:", doc_url.url, e, file=stats_file)
79+
stats['failed_validation'] +=1
7480
break
7581
if not match_found:
7682
for regext, slug in url_map.items():
77-
doc_url.url = doc_url.url.strip()
7883
if re.search(regext, doc_url.url):
7984
match_found = True
8085
if slug:
@@ -90,16 +95,18 @@ def forward(apps, schema_editor):
9095
doc_url.url = re.sub('/blob/master.*$', '', doc_url.url)
9196
try:
9297
validate_external_resource_value(name, doc_url.url)
93-
DocExtResource.objects.create(doc=doc_url.doc, name=name, value=doc_url.url, display_name=doc_url.desc) # TODO: validate this value against name.type
98+
DocExtResource.objects.create(doc=doc_url.doc, name=name, value=doc_url.url, display_name=doc_url.desc)
9499
except ValidationError as e: # pyflakes:ignore
95-
debug.show('("Failed validation:", doc_url.url, e)')
100+
print("Failed validation:", doc_url.url, e, file=stats_file)
96101
stats['failed_validation'] +=1
97102
else:
98103
stats['ignored'] +=1
99104
break
100105
if not match_found:
101-
debug.show('("Not Mapped:",doc_url.desc, doc_url.tag.slug, doc_url.doc.name, doc_url.url)')
106+
print("Not Mapped:",doc_url.desc, doc_url.tag.slug, doc_url.doc.name, doc_url.url, file=stats_file)
102107
stats['not_mapped'] += 1
108+
print('')
109+
print(stats_file.getvalue())
103110
print (stats)
104111

105112
def reverse(apps, schema_editor):

ietf/doc/tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,9 +1056,9 @@ def test_document_bibtex(self):
10561056
self.assertNotIn('day', entry)
10571057

10581058
april1 = IndividualRfcFactory.create(
1059-
stream_id = 'rse',
1059+
stream_id = 'ise',
10601060
states = [('draft','rfc'),('draft-iesg','pub')],
1061-
std_level_id = 'ind',
1061+
std_level_id = 'inf',
10621062
time = datetime.datetime(1990,0o4,0o1),
10631063
)
10641064
num = april1.rfc_number()

ietf/doc/tests_draft.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,17 +1129,16 @@ def test_edit_doc_extresources(self):
11291129

11301130
goodlines = """
11311131
github_repo https://github.com/some/repo Some display text
1132-
github_notify notify@example.com
11331132
github_username githubuser
1134-
website http://example.com/http/is/fine
1133+
webpage http://example.com/http/is/fine
11351134
"""
11361135

11371136
r = self.client.post(url, dict(resources=goodlines, submit="1"))
11381137
self.assertEqual(r.status_code,302)
11391138
doc = Document.objects.get(name=self.docname)
11401139
self.assertEqual(doc.latest_event(DocEvent,type="changed_document").desc[:35], 'Changed document external resources')
11411140
self.assertIn('github_username githubuser', doc.latest_event(DocEvent,type="changed_document").desc)
1142-
self.assertEqual(doc.docextresource_set.count(), 4)
1141+
self.assertEqual(doc.docextresource_set.count(), 3)
11431142
self.assertEqual(doc.docextresource_set.get(name__slug='github_repo').display_name, 'Some display text')
11441143

11451144

ietf/group/migrations/0034_populate_groupextresources.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55

66
import re
77

8-
import debug
8+
import debug # pyflakes:ignore
99

1010
from collections import OrderedDict, Counter
11+
from io import StringIO
1112

1213
from django.db import migrations
1314
from django.core.exceptions import ValidationError
@@ -30,25 +31,12 @@
3031
"Github page": "github_repo",
3132
"GitHub repo.*": "github_repo",
3233
"Github repository.*": "github_repo",
33-
"GitHub notifications": "github_notify",
3434
"GitHub org.*": "github_org",
3535
"GitHub User.*": "github_username",
3636
"GitLab User": "gitlab_username",
3737
"GitLab User Name": "gitlab_username",
3838
}
3939

40-
# TODO: Consider dropping known bad links at this point
41-
# " *https?://www.ietf.org/html.charters/*": None, # all these links are dead
42-
# " *http://www.bell-labs.com/mailing-lists/pint": None, # dead link
43-
# "http://www.ietf.org/wg/videos/mile-overview.html": None, # dead link
44-
# " http://domen.uninett.no/~hta/ietf/notary-status.h": None, # dead link
45-
# " http://www.ERC.MsState.Edu/packetway": None, # dead link
46-
# "mailarchive\\.ietf\\.org" : None,
47-
# "bell-labs\\.com": None,
48-
# "html\\.charters": None,
49-
# "datatracker\\.ietf\\.org": None,
50-
# etc.
51-
5240
url_map = OrderedDict({
5341
"https?://github\\.com": "github_repo",
5442
"https?://trac\\.ietf\\.org/.*/wiki": "wiki",
@@ -68,19 +56,25 @@ def forward(apps, schema_editor):
6856
GroupUrl = apps.get_model('group', 'GroupUrl')
6957

7058
stats = Counter()
59+
stats_file = StringIO()
7160

7261
for group_url in GroupUrl.objects.all():
62+
group_url.url = group_url.url.strip()
7363
match_found = False
7464
for regext,slug in name_map.items():
75-
if re.match(regext, group_url.name):
65+
if re.fullmatch(regext, group_url.name):
7666
match_found = True
7767
stats['mapped'] += 1
7868
name = ExtResourceName.objects.get(slug=slug)
79-
GroupExtResource.objects.create(group=group_url.group, name_id=slug, value=group_url.url, display_name=group_url.name) # TODO: validate this value against name.type
69+
try:
70+
validate_external_resource_value(name, group_url.url)
71+
GroupExtResource.objects.create(group=group_url.group, name_id=slug, value=group_url.url, display_name=group_url.name) # TODO: validate this value against name.type
72+
except ValidationError as e: # pyflakes:ignore
73+
print("Failed validation:", group_url.url, e, file=stats_file)
74+
stats['failed_validation'] +=1
8075
break
8176
if not match_found:
8277
for regext, slug in url_map.items():
83-
group_url.url = group_url.url.strip()
8478
if re.search(regext, group_url.url):
8579
match_found = True
8680
if slug:
@@ -96,16 +90,18 @@ def forward(apps, schema_editor):
9690
group_url.url = re.sub('/blob/master.*$', '', group_url.url)
9791
try:
9892
validate_external_resource_value(name, group_url.url)
99-
GroupExtResource.objects.create(group=group_url.group, name=name, value=group_url.url, display_name=group_url.name) # TODO: validate this value against name.type
93+
GroupExtResource.objects.create(group=group_url.group, name=name, value=group_url.url, display_name=group_url.name)
10094
except ValidationError as e: # pyflakes:ignore
101-
debug.show('("Failed validation:", group_url.url, e)')
95+
print("Failed validation:", group_url.url, e, file=stats_file)
10296
stats['failed_validation'] +=1
10397
else:
10498
stats['ignored'] +=1
10599
break
106100
if not match_found:
107-
debug.show('("Not Mapped:",group_url.group.acronym, group_url.name, group_url.url)')
101+
print("Not Mapped:",group_url.group.acronym, group_url.name, group_url.url, file=stats_file)
108102
stats['not_mapped'] += 1
103+
print('')
104+
print(stats_file.getvalue())
109105
print(stats)
110106

111107
def reverse(apps, schema_editor):

ietf/group/tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def setUp(self):
7474
set_coverage_checking(False)
7575
a = WgDraftFactory()
7676
b = WgDraftFactory()
77-
RelatedDocument.objects.create(source=a,target=b.docalias.first(),relationship_id='normref')
77+
RelatedDocument.objects.create(source=a,target=b.docalias.first(),relationship_id='refnorm')
7878

7979
def tearDown(self):
8080
set_coverage_checking(True)

ietf/group/tests_info.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -658,17 +658,16 @@ def test_edit_extresources(self):
658658

659659
goodlines = """
660660
github_repo https://github.com/some/repo Some display text
661-
github_notify notify@example.com
662661
github_username githubuser
663-
website http://example.com/http/is/fine
662+
webpage http://example.com/http/is/fine
664663
"""
665664

666665
r = self.client.post(url, dict(resources=goodlines, submit="1"))
667666
self.assertEqual(r.status_code,302)
668667
group = Group.objects.get(acronym=group.acronym)
669668
self.assertEqual(group.latest_event(GroupEvent,type="info_changed").desc[:20], 'Resources changed to')
670669
self.assertIn('github_username githubuser', group.latest_event(GroupEvent,type="info_changed").desc)
671-
self.assertEqual(group.groupextresource_set.count(), 4)
670+
self.assertEqual(group.groupextresource_set.count(), 3)
672671
self.assertEqual(group.groupextresource_set.get(name__slug='github_repo').display_name, 'Some display text')
673672

674673

ietf/ietfauth/tests.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -693,14 +693,13 @@ def test_edit_person_extresources(self):
693693

694694
goodlines = """
695695
github_repo https://github.com/some/repo Some display text
696-
github_notify notify@example.com
697696
github_username githubuser
698-
website http://example.com/http/is/fine
697+
webpage http://example.com/http/is/fine
699698
"""
700699

701700
r = self.client.post(url, dict(resources=goodlines, submit="1"))
702701
self.assertEqual(r.status_code,302)
703-
self.assertEqual(person.personextresource_set.count(), 4)
702+
self.assertEqual(person.personextresource_set.count(), 3)
704703
self.assertEqual(person.personextresource_set.get(name__slug='github_repo').display_name, 'Some display text')
705704

706705

0 commit comments

Comments
 (0)