コード例 #1
0
    def test_filters(self):
        sources = [
            'tests/i18n/code.py',
        ]
        kwargs = {
            'translations_dir': config.TEMP_DIR,
            'mapping': 'tests/i18n/babel.cfg',
            'source': sources,
            'extract_update': True,
            'compile': True,
            'verbose': logging.DEBUG,
            'version': version.__version__,
        }
        args = argparse.Namespace(**kwargs)
        manage.setup_verbosity(args)
        manage.translate_messages(args)

        manage.sh("""
        pybabel init -i {d}/messages.pot -d {d} -l en_US
        pybabel init -i {d}/messages.pot -d {d} -l fr_FR
        """.format(d=config.TEMP_DIR))

        fake_config = self.get_fake_config()
        fake_config.SUPPORTED_LOCALES = ['en_US', 'fr_FR']
        fake_config.TRANSLATION_DIRS = config.TEMP_DIR
        for app in (journalist_app.create_app(fake_config),
                    source_app.create_app(fake_config)):
            assert i18n.LOCALES == fake_config.SUPPORTED_LOCALES
            self.verify_filesizeformat(app)
            self.verify_rel_datetime_format(app)
コード例 #2
0
    def test_filters(self):
        sources = [
            'tests/i18n/code.py',
        ]
        kwargs = {
            'translations_dir': config.TEMP_DIR,
            'mapping': 'tests/i18n/babel.cfg',
            'source': sources,
            'extract_update': True,
            'compile': True,
            'verbose': logging.DEBUG,
            'version': version.__version__,
        }
        args = argparse.Namespace(**kwargs)
        manage.setup_verbosity(args)
        manage.translate_messages(args)

        manage.sh("""
        pybabel init -i {d}/messages.pot -d {d} -l en_US
        pybabel init -i {d}/messages.pot -d {d} -l fr_FR
        """.format(d=config.TEMP_DIR))

        fake_config = self.get_fake_config()
        fake_config.SUPPORTED_LOCALES = ['en_US', 'fr_FR']
        fake_config.TRANSLATION_DIRS = config.TEMP_DIR
        for app in (journalist_app.create_app(fake_config),
                    source_app.create_app(fake_config)):
            assert i18n.LOCALES == fake_config.SUPPORTED_LOCALES
            self.verify_filesizeformat(app)
            self.verify_rel_datetime_format(app)
コード例 #3
0
ファイル: test_manage.py プロジェクト: zyphlar/securedrop
 def test_clean_tmp_do_nothing(self, caplog):
     args = argparse.Namespace(days=0,
                               directory=' UNLIKELY ',
                               verbose=logging.DEBUG)
     manage.setup_verbosity(args)
     manage.clean_tmp(args)
     assert 'does not exist, do nothing' in caplog.text
コード例 #4
0
    def test_filters(self):
        sources = [
            'tests/i18n/code.py',
        ]
        kwargs = {
            'translations_dir': config.TEMP_DIR,
            'mapping': 'tests/i18n/babel.cfg',
            'source': sources,
            'extract_update': True,
            'compile': True,
            'verbose': logging.DEBUG,
            'version': version.__version__,
        }
        args = argparse.Namespace(**kwargs)
        manage.setup_verbosity(args)
        manage.translate_messages(args)

        manage.sh("""
        pybabel init -i {d}/messages.pot -d {d} -l en_US
        pybabel init -i {d}/messages.pot -d {d} -l fr_FR
        """.format(d=config.TEMP_DIR))

        supported = getattr(config, 'SUPPORTED_LOCALES', None)
        try:
            if supported:
                del config.SUPPORTED_LOCALES
            for app in (journalist.app, source.app):
                config.SUPPORTED_LOCALES = ['en_US', 'fr_FR']
                app.config['BABEL_TRANSLATION_DIRECTORIES'] = config.TEMP_DIR
                i18n.setup_app(app)
                self.verify_filesizeformat(app)
                self.verify_rel_datetime_format(app)
        finally:
            if supported:
                config.SUPPORTED_LOCALES = supported
コード例 #5
0
ファイル: test_manage.py プロジェクト: zyphlar/securedrop
 def test_clean_tmp_too_young(self, caplog):
     args = argparse.Namespace(days=24*60*60,
                               directory=config.TEMP_DIR,
                               verbose=logging.DEBUG)
     open(os.path.join(config.TEMP_DIR, 'FILE'), 'a').close()
     manage.setup_verbosity(args)
     manage.clean_tmp(args)
     assert 'modified less than' in caplog.text
コード例 #6
0
def test_clean_tmp_too_young(config, caplog):
    args = argparse.Namespace(days=24 * 60 * 60,
                              directory=config.TEMP_DIR,
                              verbose=logging.DEBUG)
    # create a file
    io.open(os.path.join(config.TEMP_DIR, "FILE"), "a").close()

    manage.setup_verbosity(args)
    manage.clean_tmp(args)
    assert "modified less than" in caplog.text
コード例 #7
0
ファイル: test_manage.py プロジェクト: zyphlar/securedrop
 def test_clean_tmp_removed(self, caplog):
     args = argparse.Namespace(days=0,
                               directory=config.TEMP_DIR,
                               verbose=logging.DEBUG)
     fname = os.path.join(config.TEMP_DIR, 'FILE')
     with open(fname, 'a'):
         old = time.time() - 24*60*60
         os.utime(fname, (old, old))
     manage.setup_verbosity(args)
     manage.clean_tmp(args)
     assert 'FILE removed' in caplog.text
コード例 #8
0
    def test_i18n(self):
        sources = [
            'tests/i18n/code.py',
            'tests/i18n/template.html',
        ]
        kwargs = {
            'translations_dir': config.TEMP_DIR,
            'mapping': 'tests/i18n/babel.cfg',
            'source': sources,
            'extract_update': True,
            'compile': True,
            'verbose': logging.DEBUG,
            'version': version.__version__,
        }
        args = argparse.Namespace(**kwargs)
        manage.setup_verbosity(args)
        manage.translate_messages(args)

        manage.sh("""
        pybabel init -i {d}/messages.pot -d {d} -l en_US

        pybabel init -i {d}/messages.pot -d {d} -l fr_FR
        sed -i -e '/code hello i18n/,+1s/msgstr ""/msgstr "code bonjour"/' \
              {d}/fr_FR/LC_MESSAGES/messages.po

        pybabel init -i {d}/messages.pot -d {d} -l zh_Hans_CN
        sed -i -e '/code hello i18n/,+1s/msgstr ""/msgstr "code chinese"/' \
              {d}/zh_Hans_CN/LC_MESSAGES/messages.po

        pybabel init -i {d}/messages.pot -d {d} -l ar
        sed -i -e '/code hello i18n/,+1s/msgstr ""/msgstr "code arabic"/' \
              {d}/ar/LC_MESSAGES/messages.po

        pybabel init -i {d}/messages.pot -d {d} -l nb_NO
        sed -i -e '/code hello i18n/,+1s/msgstr ""/msgstr "code norwegian"/' \
              {d}/nb_NO/LC_MESSAGES/messages.po
        """.format(d=config.TEMP_DIR))

        manage.translate_messages(args)

        supported = getattr(config, 'SUPPORTED_LOCALES', None)
        try:
            if supported:
                del config.SUPPORTED_LOCALES
            for app in (journalist.app, source.app):
                config.SUPPORTED_LOCALES = [
                    'en_US', 'fr_FR', 'zh_Hans_CN', 'ar', 'nb_NO'
                ]
                i18n.setup_app(app, translation_dirs=config.TEMP_DIR)
                self.verify_i18n(app)
        finally:
            if supported:
                config.SUPPORTED_LOCALES = supported
コード例 #9
0
    def test_i18n(self):
        sources = [
            'tests/i18n/code.py',
            'tests/i18n/template.html',
        ]
        kwargs = {
            'translations_dir': config.TEMP_DIR,
            'mapping': 'tests/i18n/babel.cfg',
            'source': sources,
            'extract_update': True,
            'compile': True,
            'verbose': logging.DEBUG,
            'version': version.__version__,
        }
        args = argparse.Namespace(**kwargs)
        manage.setup_verbosity(args)
        manage.translate_messages(args)

        manage.sh("""
        pybabel init -i {d}/messages.pot -d {d} -l en_US

        pybabel init -i {d}/messages.pot -d {d} -l fr_FR
        sed -i -e '/code hello i18n/,+1s/msgstr ""/msgstr "code bonjour"/' \
              {d}/fr_FR/LC_MESSAGES/messages.po

        pybabel init -i {d}/messages.pot -d {d} -l zh_Hans_CN
        sed -i -e '/code hello i18n/,+1s/msgstr ""/msgstr "code chinese"/' \
              {d}/zh_Hans_CN/LC_MESSAGES/messages.po

        pybabel init -i {d}/messages.pot -d {d} -l ar
        sed -i -e '/code hello i18n/,+1s/msgstr ""/msgstr "code arabic"/' \
              {d}/ar/LC_MESSAGES/messages.po

        pybabel init -i {d}/messages.pot -d {d} -l nb_NO
        sed -i -e '/code hello i18n/,+1s/msgstr ""/msgstr "code norwegian"/' \
              {d}/nb_NO/LC_MESSAGES/messages.po

        pybabel init -i {d}/messages.pot -d {d} -l es_ES
        sed -i -e '/code hello i18n/,+1s/msgstr ""/msgstr "code spanish"/' \
              {d}/es_ES/LC_MESSAGES/messages.po
        """.format(d=config.TEMP_DIR))

        manage.translate_messages(args)

        fake_config = self.get_fake_config()
        fake_config.SUPPORTED_LOCALES = [
            'en_US', 'fr_FR', 'zh_Hans_CN', 'ar', 'nb_NO'
        ]
        fake_config.TRANSLATION_DIRS = config.TEMP_DIR
        for app in (journalist_app.create_app(fake_config),
                    source_app.create_app(fake_config)):
            assert i18n.LOCALES == fake_config.SUPPORTED_LOCALES
            self.verify_i18n(app)
コード例 #10
0
    def test_i18n(self):
        sources = [
            'tests/i18n/code.py',
            'tests/i18n/template.html',
        ]
        kwargs = {
            'translations_dir': config.TEMP_DIR,
            'mapping': 'tests/i18n/babel.cfg',
            'source': sources,
            'extract_update': True,
            'compile': True,
            'verbose': logging.DEBUG,
            'version': version.__version__,
        }
        args = argparse.Namespace(**kwargs)
        manage.setup_verbosity(args)
        manage.translate_messages(args)

        manage.sh("""
        pybabel init -i {d}/messages.pot -d {d} -l en_US

        pybabel init -i {d}/messages.pot -d {d} -l fr_FR
        sed -i -e '/code hello i18n/,+1s/msgstr ""/msgstr "code bonjour"/' \
              {d}/fr_FR/LC_MESSAGES/messages.po

        pybabel init -i {d}/messages.pot -d {d} -l zh_Hans_CN
        sed -i -e '/code hello i18n/,+1s/msgstr ""/msgstr "code chinese"/' \
              {d}/zh_Hans_CN/LC_MESSAGES/messages.po

        pybabel init -i {d}/messages.pot -d {d} -l ar
        sed -i -e '/code hello i18n/,+1s/msgstr ""/msgstr "code arabic"/' \
              {d}/ar/LC_MESSAGES/messages.po

        pybabel init -i {d}/messages.pot -d {d} -l nb_NO
        sed -i -e '/code hello i18n/,+1s/msgstr ""/msgstr "code norwegian"/' \
              {d}/nb_NO/LC_MESSAGES/messages.po

        pybabel init -i {d}/messages.pot -d {d} -l es_ES
        sed -i -e '/code hello i18n/,+1s/msgstr ""/msgstr "code spanish"/' \
              {d}/es_ES/LC_MESSAGES/messages.po
        """.format(d=config.TEMP_DIR))

        manage.translate_messages(args)

        fake_config = self.get_fake_config()
        fake_config.SUPPORTED_LOCALES = [
            'en_US', 'fr_FR', 'zh_Hans_CN', 'ar', 'nb_NO']
        fake_config.TRANSLATION_DIRS = config.TEMP_DIR
        for app in (journalist_app.create_app(fake_config),
                    source_app.create_app(fake_config)):
            assert i18n.LOCALES == fake_config.SUPPORTED_LOCALES
            self.verify_i18n(app)
コード例 #11
0
ファイル: test_manage.py プロジェクト: zyphlar/securedrop
    def test_translate_messages_l10n(self):
        source = [
            join(self.dir, 'i18n/code.py'),
            join(self.dir, 'i18n/template.html'),
        ]
        kwargs = {
            'translations_dir': config.TEMP_DIR,
            'mapping': join(self.dir, 'i18n/babel.cfg'),
            'source': source,
            'extract_update': True,
            'compile': True,
            'verbose': logging.DEBUG,
            'version': version.__version__,
        }
        args = argparse.Namespace(**kwargs)
        manage.setup_verbosity(args)
        manage.translate_messages(args)
        messages_file = join(config.TEMP_DIR, 'messages.pot')
        assert exists(messages_file)
        pot = open(messages_file).read()
        assert 'code hello i18n' in pot
        assert 'template hello i18n' in pot

        locale = 'en_US'
        locale_dir = join(config.TEMP_DIR, locale)
        manage.sh("pybabel init -i {} -d {} -l {}".format(
            messages_file,
            config.TEMP_DIR,
            locale,
        ))
        mo_file = join(locale_dir, 'LC_MESSAGES/messages.mo')
        assert not exists(mo_file)
        manage.translate_messages(args)
        assert exists(mo_file)
        mo = open(mo_file).read()
        assert 'code hello i18n' in mo
        assert 'template hello i18n' in mo
コード例 #12
0
ファイル: test_manage.py プロジェクト: zyphlar/securedrop
 def test_verbose(self, caplog):
     args = manage.get_args().parse_args(['--verbose', 'run'])
     manage.setup_verbosity(args)
     manage.log.debug('VISIBLE')
     assert 'VISIBLE' in caplog.text
コード例 #13
0
def test_not_verbose(caplog):
    args = manage.get_args().parse_args(["run"])
    manage.setup_verbosity(args)
    manage.log.debug("INVISIBLE")
    assert "INVISIBLE" not in caplog.text
コード例 #14
0
def test_verbose(caplog):
    args = manage.get_args().parse_args(["--verbose", "run"])
    manage.setup_verbosity(args)
    manage.log.debug("VISIBLE")
    assert "VISIBLE" in caplog.text
コード例 #15
0
ファイル: test_manage.py プロジェクト: zyphlar/securedrop
    def test_translate_messages_compile_arg(self):
        source = [
            join(self.dir, 'i18n/code.py'),
        ]
        kwargs = {
            'translations_dir': config.TEMP_DIR,
            'mapping': join(self.dir, 'i18n/babel.cfg'),
            'source': source,
            'extract_update': True,
            'compile': False,
            'verbose': logging.DEBUG,
            'version': version.__version__,
        }
        args = argparse.Namespace(**kwargs)
        manage.setup_verbosity(args)
        manage.translate_messages(args)
        messages_file = join(config.TEMP_DIR, 'messages.pot')
        assert exists(messages_file)
        pot = open(messages_file).read()
        assert 'code hello i18n' in pot

        locale = 'en_US'
        locale_dir = join(config.TEMP_DIR, locale)
        po_file = join(locale_dir, 'LC_MESSAGES/messages.po')
        manage.sh("pybabel init -i {} -d {} -l {}".format(
            messages_file,
            config.TEMP_DIR,
            locale,
        ))
        assert exists(po_file)
        # pretend this happened a few seconds ago
        few_seconds_ago = time.time() - 60
        os.utime(po_file, (few_seconds_ago, few_seconds_ago))

        mo_file = join(locale_dir, 'LC_MESSAGES/messages.mo')

        #
        # Extract+update but do not compile
        #
        old_po_mtime = getmtime(po_file)
        assert not exists(mo_file)
        manage.translate_messages(args)
        assert not exists(mo_file)
        current_po_mtime = getmtime(po_file)
        assert old_po_mtime < current_po_mtime

        #
        # Compile but do not extract+update
        #
        source = [
            join(self.dir, 'i18n/code.py'),
            join(self.dir, 'i18n/template.html'),
        ]
        kwargs['extract_update'] = False
        kwargs['compile'] = True
        args = argparse.Namespace(**kwargs)
        old_po_mtime = current_po_mtime
        manage.translate_messages(args)
        assert old_po_mtime == getmtime(po_file)
        mo = open(mo_file).read()
        assert 'code hello i18n' in mo
        assert 'template hello i18n' not in mo
コード例 #16
0
ファイル: test_manage.py プロジェクト: zyphlar/securedrop
    def test_translate_desktop_l10n(self):
        in_files = {}
        for what in ('source', 'journalist'):
            in_files[what] = join(config.TEMP_DIR, what + '.desktop.in')
            shutil.copy(join(self.dir, 'i18n/' + what + '.desktop.in'),
                        in_files[what])
        kwargs = {
            'translations_dir': config.TEMP_DIR,
            'source': [in_files['source']],
            'extract_update': True,
            'compile': False,
            'verbose': logging.DEBUG,
            'version': version.__version__,
        }
        args = argparse.Namespace(**kwargs)
        manage.setup_verbosity(args)
        manage.translate_desktop(args)
        messages_file = join(config.TEMP_DIR, 'desktop.pot')
        assert exists(messages_file)
        pot = open(messages_file).read()
        assert 'SecureDrop Source Interfaces' in pot
        # pretend this happened a few seconds ago
        few_seconds_ago = time.time() - 60
        os.utime(messages_file, (few_seconds_ago, few_seconds_ago))

        i18n_file = join(config.TEMP_DIR, 'source.desktop')

        #
        # Extract+update but do not compile
        #
        kwargs['source'] = in_files.values()
        old_messages_mtime = getmtime(messages_file)
        assert not exists(i18n_file)
        manage.translate_desktop(args)
        assert not exists(i18n_file)
        current_messages_mtime = getmtime(messages_file)
        assert old_messages_mtime < current_messages_mtime

        locale = 'fr_FR'
        po_file = join(config.TEMP_DIR, locale + ".po")
        manage.sh("""
        msginit  --no-translator \
                 --locale {locale} \
                 --output {po_file} \
                 --input {messages_file}
        sed -i -e '/{source}/,+1s/msgstr ""/msgstr "SOURCE FR"/' \
                 {po_file}
        """.format(source='SecureDrop Source Interfaces',
                   messages_file=messages_file,
                   po_file=po_file,
                   locale=locale))
        assert exists(po_file)

        #
        # Compile but do not extract+update
        #
        kwargs['source'] = in_files.values() + ['BOOM']
        kwargs['extract_update'] = False
        kwargs['compile'] = True
        args = argparse.Namespace(**kwargs)
        old_messages_mtime = current_messages_mtime
        manage.translate_desktop(args)
        assert old_messages_mtime == getmtime(messages_file)
        po = open(po_file).read()
        assert 'SecureDrop Source Interfaces' in po
        assert 'SecureDrop Journalist Interfaces' not in po
        i18n = open(i18n_file).read()
        assert 'SOURCE FR' in i18n
コード例 #17
0
def test_not_verbose(caplog):
    args = manage.get_args().parse_args(['run'])
    manage.setup_verbosity(args)
    manage.log.debug('INVISIBLE')
    assert 'INVISIBLE' not in caplog.text