review/tests/test_encoding.py @ 676834353b0d

Categorize only the last signoff of each user.

On the index view, all the signoff of a single user (done on precursors of a
cset) were displayed in the counts.

This patch make sure only the last signoff of each user is counted, so that the
final vote on the latest version of a cset gets displayed.
author Christophe de Vienne <cdevienne@gmail.com>
date Wed, 29 Oct 2014 14:49:08 +0100
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