|
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | import os.path |
3 | 3 | import types |
4 | | -#import json |
5 | | -#from pathlib import Path |
| 4 | +import shutil |
| 5 | +from StringIO import StringIO |
| 6 | +from pipe import pipe |
6 | 7 |
|
7 | 8 | from textwrap import dedent |
8 | 9 | from email.mime.text import MIMEText |
9 | 10 | from email.mime.image import MIMEImage |
10 | 11 | from email.mime.multipart import MIMEMultipart |
11 | 12 |
|
12 | 13 | from django.conf import settings |
| 14 | +from django.core.management import call_command |
13 | 15 | from django.template import Context |
14 | 16 | from django.template.defaulttags import URLNode |
15 | 17 | from django.templatetags.static import StaticNode |
|
21 | 23 | import ietf.urls |
22 | 24 | from ietf.utils.management.commands import pyflakes |
23 | 25 | from ietf.utils.mail import send_mail_text, send_mail_mime, outbox |
| 26 | +from ietf.utils.test_data import make_test_data |
24 | 27 | from ietf.utils.test_runner import get_template_paths |
| 28 | +from ietf.group.models import Group |
25 | 29 |
|
26 | 30 | class PyFlakesTestCase(TestCase): |
27 | 31 |
|
@@ -186,6 +190,46 @@ def check_that_static_tags_resolve(node, origin, checked): |
186 | 190 | settings.DEBUG = saved_debug |
187 | 191 |
|
188 | 192 |
|
| 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(stats_slug='active', type_id='draft') |
| 223 | + for doc in docs: |
| 224 | + name = doc.name |
| 225 | + name = name.replace('draft-','') |
| 226 | + name = name.replace(group.stream+'-', '') |
| 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 | + |
189 | 233 | ## One might think that the code below would work, but it doesn't ... |
190 | 234 |
|
191 | 235 | # def list_static_files(path): |
|
0 commit comments