Switch to unified view

a/Allura/allura/tests/helpers.py b/Allura/allura/tests/helpers.py
1
# -*- coding: utf-8 -*- 
1
# -*- coding: utf-8 -*- 
2
from os import path, environ, getcwd
2
from os import path, environ, getcwd
3
import os
3
import os
4
import sys
4
import logging
5
import logging
5
import tempfile
6
import tempfile
6
import subprocess
7
import subprocess
7
import json
8
import json
8
import urllib2
9
import urllib2
...
...
27
from allura import model as M
28
from allura import model as M
28
from allura.lib.custom_middleware import environ as ENV, MagicalC
29
from allura.lib.custom_middleware import environ as ENV, MagicalC
29
30
30
DFL_CONFIG = environ.get('SF_SYSTEM_FUNC') and 'sandbox-test.ini' or 'test.ini'
31
DFL_CONFIG = environ.get('SF_SYSTEM_FUNC') and 'sandbox-test.ini' or 'test.ini'
31
DFL_APP_NAME = 'main_without_authn'
32
DFL_APP_NAME = 'main_without_authn'
33
ENABLE_CONTENT_VALIDATION = False
32
34
33
log = logging.getLogger(__name__)
35
log = logging.getLogger(__name__)
34
36
35
37
36
def run_app_setup():
38
def run_app_setup():
...
...
201
            f = tempfile.NamedTemporaryFile(prefix='html5-', delete=False)
203
            f = tempfile.NamedTemporaryFile(prefix='html5-', delete=False)
202
            f.write(html)
204
            f.write(html)
203
            f.close()
205
            f.close()
204
            message = "Validation errors (" + f.name + "):\n" + resp
206
            message = "Validation errors (" + f.name + "):\n" + resp
205
            message = message.decode('ascii','ignore')
207
            message = message.decode('ascii','ignore')
208
            if ENABLE_CONTENT_VALIDATION:
206
            ok_(False, message)
209
                ok_(False, message)
210
            else:
211
                sys.stderr.write('=' * 40 + '\n' + msg + '\n')
212
                
207
        
213
        
208
def validate_html5_chunk(html):
214
def validate_html5_chunk(html):
209
        """ When you don't have a html & body tags - this adds it"""
215
        """ When you don't have a html & body tags - this adds it"""
210
        html = '''<!DOCTYPE html> 
216
        html = '''<!DOCTYPE html> 
211
        <html> 
217
        <html> 
...
...
232
        stdout, stderr = p.communicate(html)
238
        stdout, stderr = p.communicate(html)
233
        if stdout.startswith('jslint: No problems found'):
239
        if stdout.startswith('jslint: No problems found'):
234
            os.unlink(f.name)
240
            os.unlink(f.name)
235
            return
241
            return
236
        stdout = stdout.decode('UTF-8', 'replace')
242
        stdout = stdout.decode('UTF-8', 'replace')
237
        raise Exception('JavaScript validation error(s) (see ' + f.name + '):  ' + '\n'.join(repr(s) for s in stdout.split('\n') if s))
243
        msg = 'JavaScript validation error(s) (see ' + f.name + '):  ' + '\n'.join(repr(s) for s in stdout.split('\n') if s)
244
        if ENABLE_CONTENT_VALIDATION:
245
            raise Exception(msg)
246
        else:
247
            sys.stderr.write('=' * 40 + '\n' + msg + '\n')
238
248
239
def validate_page(html_or_response):
249
def validate_page(html_or_response):
240
    validate_html(html_or_response)
250
    validate_html(html_or_response)
241
    validate_js(html_or_response)
251
    validate_js(html_or_response)