Skip to content

Commit d400b88

Browse files
committed
Added a test for the create_group_wikis management command.
- Legacy-Id: 12180
1 parent 41945d5 commit d400b88

1 file changed

Lines changed: 46 additions & 2 deletions

File tree

ietf/utils/tests.py

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
# -*- coding: utf-8 -*-
22
import os.path
33
import types
4-
#import json
5-
#from pathlib import Path
4+
import shutil
5+
from StringIO import StringIO
6+
from pipe import pipe
67

78
from textwrap import dedent
89
from email.mime.text import MIMEText
910
from email.mime.image import MIMEImage
1011
from email.mime.multipart import MIMEMultipart
1112

1213
from django.conf import settings
14+
from django.core.management import call_command
1315
from django.template import Context
1416
from django.template.defaulttags import URLNode
1517
from django.templatetags.static import StaticNode
@@ -21,7 +23,9 @@
2123
import ietf.urls
2224
from ietf.utils.management.commands import pyflakes
2325
from ietf.utils.mail import send_mail_text, send_mail_mime, outbox
26+
from ietf.utils.test_data import make_test_data
2427
from ietf.utils.test_runner import get_template_paths
28+
from ietf.group.models import Group
2529

2630
class PyFlakesTestCase(TestCase):
2731

@@ -186,6 +190,46 @@ def check_that_static_tags_resolve(node, origin, checked):
186190
settings.DEBUG = saved_debug
187191

188192

193+
class TestWikiGlueManagementCommand(TestCase):
194+
195+
def setUp(self):
196+
self.wiki_dir_pattern = os.path.abspath('tmp-wiki-dir-root/%s')
197+
if not os.path.exists(self.wiki_dir_pattern):
198+
os.mkdir(os.path.dirname(self.wiki_dir_pattern))
199+
200+
def tearDown(self):
201+
shutil.rmtree(os.path.dirname(self.wiki_dir_pattern))
202+
203+
def test_wiki_create_output(self):
204+
make_test_data()
205+
groups = Group.objects.filter(
206+
type__slug__in=['wg','rg','area'],
207+
state__slug='active'
208+
).order_by('acronym')
209+
out = StringIO()
210+
call_command('create_group_wikis', stdout=out, verbosity=2, wiki_dir_pattern=self.wiki_dir_pattern)
211+
command_output = out.getvalue()
212+
for group in groups:
213+
self.assertIn("Processing group %s" % group.acronym, command_output)
214+
# Do a bit of verification using trac-admin, too
215+
admin_code, admin_output, admin_error = pipe('trac-admin %s permission list' % (self.wiki_dir_pattern % group.acronym))
216+
self.assertEqual(admin_code, 0)
217+
roles = group.role_set.filter(name_id__in=['chair', 'secr', 'ad'])
218+
for role in roles:
219+
user = role.email.address.lower()
220+
self.assertIn("Granting admin permission for %s" % user, command_output)
221+
self.assertIn(user, admin_output)
222+
docs = group.document_set.filter(states__slug='active', type_id='draft')
223+
for doc in docs:
224+
name = doc.name
225+
name = name.replace('draft-','')
226+
name = name.replace(doc.stream_id+'-', '')
227+
name = name.replace(group.acronym+'-', '')
228+
self.assertIn("Adding component %s"%name, command_output)
229+
for page in settings.TRAC_WIKI_PAGES_TEMPLATES:
230+
self.assertIn("Adding page %s" % os.path.basename(page), command_output)
231+
self.assertIn("Indexing default repository", command_output)
232+
189233
## One might think that the code below would work, but it doesn't ...
190234

191235
# def list_static_files(path):

0 commit comments

Comments
 (0)