review/tests/test_encoding.py @ 9030dc9517cf
web: add basic tests
This patch adds a new test module `test_web` to automate testing of web
requests. For now the tests are rather simple and only check for
expected status codes.
To set up the flask app within the tests, it has to be configured
properly. This is the reason why the app configuration part in `web.py`
has been moved into an own function - now it may also be used by the
test module.
author |
Oben Sonne <obensonne@googlemail.com> |
date |
Mon, 02 Jul 2012 22:32:48 +0200 |
parents |
cada9aab8b6f |
children |
(none) |
# coding=utf-8
#
import os
import unicodedata
from nose import with_setup
from util import setup_reviewed_sandbox, teardown_sandbox, review, should_fail_with
from util import get_datastore_repo, get_sandbox_repo, get_ui
from util import check_comment_exists_on_line
from .. import api, messages, rutil
from mercurial.node import hex
@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
def test_comment_encoding():
review(comment=True, message=rutil.tolocal(u'Téstíng.'))
output = review()
assert messages.REVIEW_LOG_COMMENT_LINE % rutil.tolocal(u'Téstíng.') in output
@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
def test_signoff_encoding():
review(signoff=True, message=rutil.tolocal(u'Téstíng.'))
output = review()
assert messages.REVIEW_LOG_SIGNOFF_LINE % rutil.tolocal(u'Téstíng.') in output
@with_setup(setup_reviewed_sandbox(username=u'Tést <tést@test.com>', encoding='UTF-8'), teardown_sandbox)
def test_username_encoding_utf8():
review(comment=True, message=rutil.tolocal(u'Cómment.'))
output = review()
assert u'Tést'.encode('UTF-8') in output
assert u'Cómment.'.encode('UTF-8') in output
@with_setup(setup_reviewed_sandbox(username=u'Tést <tést@test.com>', encoding='ISO-8859-1'), teardown_sandbox)
def test_username_encoding_iso_8859_1():
review(comment=True, message=rutil.tolocal(u'Cómment.'))
output = review()
assert u'Tést'.encode('ISO-8859-1') in output
assert u'Cómment.'.encode('ISO-8859-1') in output
@with_setup(setup_reviewed_sandbox(username=u'Tést <tést@test.com>', encoding='UTF-8', file_encoding='UTF-8'), teardown_sandbox)
def test_file_encoding_utf8():
review(comment=True, message=rutil.tolocal(u'Cómment.'), rev='1')
output = review(rev='1')
normal_output = unicodedata.normalize('NFC', output.decode('UTF-8'))
assert unicodedata.normalize('NFC', u'filé') in normal_output
assert u'Tést'.encode('UTF-8') in output
assert u'Cómment.'.encode('UTF-8') in output
assert u'-oné'.encode('UTF-8') in output
assert u'+óne'.encode('UTF-8') in output
assert u'-twó'.encode('UTF-8') in output
assert u'+two'.encode('UTF-8') in output
assert u'-thrée'.encode('UTF-8') in output
assert u'+threé'.encode('UTF-8') in output
@with_setup(setup_reviewed_sandbox(username=u'Tést <tést@test.com>', encoding='latin-1', file_encoding='latin-1'), teardown_sandbox)
def test_file_encoding_iso88591():
review(comment=True, message=rutil.tolocal(u'Cómment.'), rev='1')
output = review(rev='1')
# TODO: Make this work.
#normal_output = unicodedata.normalize('NFC', output.decode('latin-1'))
#assert unicodedata.normalize('NFC', u'filé') in normal_output
assert u'Tést'.encode('latin-1') in output
assert u'Cómment.'.encode('latin-1') in output
assert u'-oné'.encode('latin-1') in output
assert u'+óne'.encode('latin-1') in output
assert u'-twó'.encode('latin-1') in output
assert u'+two'.encode('latin-1') in output
assert u'-thrée'.encode('latin-1') in output
assert u'+threé'.encode('latin-1') in output