Updated mgmt command to find github repos to back up. Improved test coverage of branch changes. Branch ready for merge.

- Legacy-Id: 18163
This commit is contained in:
Robert Sparks 2020-07-13 17:36:34 +00:00
parent 99df95d542
commit 6227162e53
6 changed files with 44 additions and 25 deletions

View file

@ -2,8 +2,8 @@
import json
from django.core.management.base import BaseCommand
from django.db.models import F
from ietf.extresource.models import ExtResource
from ietf.doc.models import DocExtResource
from ietf.group.models import GroupExtResource
from ietf.person.models import PersonExtResource
@ -14,17 +14,33 @@ class Command(BaseCommand):
def handle(self, *args, **options):
info_dict = {}
for repo in ExtResource.objects.filter(name__slug='github_repo'):
for repo in DocExtResource.objects.filter(name__slug='github_repo'):
if not repo.value.endswith('/'):
repo.value += '/'
if repo not in info_dict:
info_dict[repo.value] = []
for username in DocExtResource.objects.filter(extresource__name__slug='github_username', doc__name__in=repo.docextresource_set.values_list('doc__name',flat=True).distinct()):
for username in DocExtResource.objects.filter(name__slug='github_username', doc=F('doc')):
info_dict[repo.value].push(username.value)
for username in GroupExtResource.objects.filter(extresource__name__slug='github_username', group__acronym__in=repo.groupextresource_set.values_list('group__acronym',flat=True).distinct()):
for repo in GroupExtResource.objects.filter(name__slug='github_repo'):
if not repo.value.endswith('/'):
repo.value += '/'
if repo not in info_dict:
info_dict[repo.value] = []
for username in GroupExtResource.objects.filter(name__slug='github_username', group=F('group')):
info_dict[repo.value].push(username.value)
for username in PersonExtResource.objects.filter(extresource__name__slug='github_username', person_id__in=repo.personextresource_set.values_list('person__id',flat=True).distinct()):
for repo in PersonExtResource.objects.filter(name__slug='github_repo'):
if not repo.value.endswith('/'):
repo.value += '/'
if repo not in info_dict:
info_dict[repo.value] = []
for username in PersonExtResource.objects.filter(name__slug='github_username', person=F('person')):
info_dict[repo.value].push(username.value)
print (json.dumps(info_dict))
#print (json.dumps(info_dict))
# For now, all we need are the repo names
for name in info_dict.keys():
print(name)

View file

@ -1117,8 +1117,8 @@ class IndividualInfoFormsTests(TestCase):
badlines = (
'github_repo https://github3.com/some/repo',
'github_notify badaddr',
'website /not/a/good/url'
'notavalidtag blahblahblah'
'website /not/a/good/url',
'notavalidtag blahblahblah',
)
for line in badlines:
@ -1140,6 +1140,7 @@ class IndividualInfoFormsTests(TestCase):
self.assertIn('github_username githubuser', doc.latest_event(DocEvent,type="changed_document").desc)
self.assertEqual(doc.docextresource_set.count(), 3)
self.assertEqual(doc.docextresource_set.get(name__slug='github_repo').display_name, 'Some display text')
self.assertIn(doc.docextresource_set.first().name.slug,str(doc.docextresource_set.first()))
class SubmitToIesgTests(TestCase):

View file

@ -68,7 +68,7 @@ def forward(apps, schema_editor):
name = ExtResourceName.objects.get(slug=slug)
try:
validate_external_resource_value(name, group_url.url)
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
GroupExtResource.objects.create(group=group_url.group, name_id=slug, value=group_url.url, display_name=group_url.name)
except ValidationError as e: # pyflakes:ignore
print("Failed validation:", group_url.url, e, file=stats_file)
stats['failed_validation'] +=1

View file

@ -31,7 +31,7 @@ from ietf.group.factories import (GroupFactory, RoleFactory, GroupEventFactory,
from ietf.group.models import Group, GroupEvent, GroupMilestone, GroupStateTransitions, Role
from ietf.group.utils import save_group_in_history, setup_default_community_list_for_group
from ietf.meeting.factories import SessionFactory
from ietf.name.models import DocTagName, GroupStateName, GroupTypeName
from ietf.name.models import DocTagName, GroupStateName, GroupTypeName, ExtResourceName
from ietf.person.models import Person, Email
from ietf.person.factories import PersonFactory
from ietf.review.factories import ReviewRequestFactory, ReviewAssignmentFactory
@ -634,6 +634,7 @@ class GroupEditTests(TestCase):
def test_edit_extresources(self):
group = GroupFactory(acronym='mars',parent=GroupFactory(type_id='area'))
CharterFactory(group=group)
ExtResourceName.objects.create(slug='keymaster', name='Keymaster', type_id='email')
url = urlreverse('ietf.group.views.edit', kwargs=dict(group_type=group.type_id, acronym=group.acronym, action="edit", field="resources"))
login_testing_unauthorized(self, "secretary", url)
@ -646,8 +647,9 @@ class GroupEditTests(TestCase):
badlines = (
'github_repo https://github3.com/some/repo',
'github_notify badaddr',
'website /not/a/good/url'
'notavalidtag blahblahblah'
'website /not/a/good/url',
'notavalidtag blahblahblah',
'github_repo',
)
for line in badlines:
@ -660,6 +662,8 @@ class GroupEditTests(TestCase):
github_repo https://github.com/some/repo Some display text
github_username githubuser
webpage http://example.com/http/is/fine
jabber_room xmpp:mars@jabber.example.com
keymaster keymaster@example.org Group Rooter
"""
r = self.client.post(url, dict(resources=goodlines, submit="1"))
@ -667,8 +671,13 @@ class GroupEditTests(TestCase):
group = Group.objects.get(acronym=group.acronym)
self.assertEqual(group.latest_event(GroupEvent,type="info_changed").desc[:20], 'Resources changed to')
self.assertIn('github_username githubuser', group.latest_event(GroupEvent,type="info_changed").desc)
self.assertEqual(group.groupextresource_set.count(), 3)
self.assertEqual(group.groupextresource_set.count(), 5)
self.assertEqual(group.groupextresource_set.get(name__slug='github_repo').display_name, 'Some display text')
self.assertIn(group.groupextresource_set.first().name.slug, str(group.groupextresource_set.first()))
# exercise format_resources
r = self.client.get(url)
self.assertIn('Group Rooter', unicontent(r))
def test_edit_field(self):

View file

@ -860,15 +860,6 @@ def edit(request, group_type=None, acronym=None, action="edit", field=None):
return entry % dict(attr=attr, new=new, old=old)
def format_urls(urls, fs="\n"):
res = []
for u in urls:
if u.name:
res.append("%s (%s)" % (u.url, u.name))
else:
res.append(u.url)
return fs.join(res)
def format_resources(resources, fs="\n"):
res = []
for r in resources:

View file

@ -681,8 +681,9 @@ class IetfAuthTests(TestCase):
badlines = (
'github_repo https://github3.com/some/repo',
'github_notify badaddr',
'website /not/a/good/url'
'notavalidtag blahblahblah'
'website /not/a/good/url',
'notavalidtag blahblahblah',
'website',
)
for line in badlines:
@ -701,6 +702,7 @@ class IetfAuthTests(TestCase):
self.assertEqual(r.status_code,302)
self.assertEqual(person.personextresource_set.count(), 3)
self.assertEqual(person.personextresource_set.get(name__slug='github_repo').display_name, 'Some display text')
self.assertIn(person.personextresource_set.first().name.slug, str(person.personextresource_set.first()))
class OpenIDConnectTests(TestCase):