1. Eric Larson
  2. Dragoman


Dragoman / dragoman / lib / test / test_gettext_import.py

# -*- coding: utf-8 -*-
import os
from pymongo import Connection

from dragoman.lib.storage import Catalog
from dragoman.lib.client import Connection as DMConnection
from dragoman.lib.gettext_tools import GettextCatalog
from dragoman.lib.testing import start_test_server

_here_ = os.path.abspath(os.path.dirname(__file__))
PO, LANG = os.path.join(_here_, 'gettext_import.po'), 'piglatin'

class TestGettextImporter(object):
    def setup_class(self):
        self.server = start_test_server()
        c = Connection()
        self.api_base = '%s/api' % self.server.base_url        

    def test_parser(self):
        catalog = GettextCatalog(PO, LANG)
        msgs = catalog.messages

        # make sure the first set is correct
        assert msgs[0]['msgid'] == ''
        assert 'Project-Id-Version' in msgs[0]['msgstr']
        # verifies multiline works
        assert 'Generated-By: Babel' in msgs[0]['msgstr']

        # make sure the chinese stuff works
        assert msgs[1]['msgid'] == 'Interview with visa %s cleared for restart'
        assert msgs[1]['msgstr'] == '与visa %s的面试已被清空,可重新开始'

        # verify the last msg is there
        last = msgs.pop()
        assert last['msgid'] == "Each %(type)s must sum to exactly %(target)s."
        assert last['msgstr'] == "每种%(type)s相加必须等于%(target)s。"
    def test_remote_import(self):
        c = DMConnection(self.api_base)
        c = DMConnection(self.api_base)['test_import'][LANG]
        result = c("Interview with visa %s cleared for restart")
        assert result == "与visa %s的面试已被清空,可重新开始"