예제 #1
0
 def test_extra_file(self):
     """
     Test extra commit file handling.
     """
     subproject = self.create_subproject()
     subproject.pre_commit_script = get_test_file(
         '../../../../examples/hook-generate-mo'
     )
     appsettings.PRE_COMMIT_SCRIPT_CHOICES.append(
         (subproject.pre_commit_script, 'hook-generate-mo')
     )
     subproject.pre_commit_script = get_test_file(
         '../../../../examples/hook-update-linguas'
     )
     appsettings.PRE_COMMIT_SCRIPT_CHOICES.append(
         (subproject.pre_commit_script, 'hook-update-linguas')
     )
     subproject.extra_commit_file = 'po/%(language)s.mo\npo/LINGUAS'
     subproject.save()
     subproject.full_clean()
     translation = subproject.translation_set.get(language_code='cs')
     # change backend file
     with open(translation.get_filename(), 'a') as handle:
         handle.write(' ')
     # Test committing
     translation.git_commit(
         None, 'TEST <*****@*****.**>', timezone.now(),
         force_commit=True
     )
     linguas = os.path.join(subproject.get_path(), 'po', 'LINGUAS')
     with open(linguas, 'r') as handle:
         data = handle.read()
         self.assertIn('\ncs\n', data)
     self.assertFalse(translation.repo_needs_commit())
예제 #2
0
    def test_importusers(self):
        # First import
        call_command('importusers', get_test_file('users.json'))

        # Test that second import does not change anything
        user = User.objects.get(username='******')
        user.first_name = 'Weblate test user'
        user.save()
        call_command('importusers', get_test_file('users.json'))
        user2 = User.objects.get(username='******')
        self.assertEqual(user.first_name, user2.first_name)
예제 #3
0
파일: tests.py 프로젝트: daleathan/weblate
 def test_import_json_command(self):
     call_command(
         'import_memory',
         get_test_file('memory.json')
     )
     memory = TranslationMemory()
     self.assertEqual(memory.doc_count(), 1)
예제 #4
0
파일: tests.py 프로젝트: dekoza/weblate
 def upload_file(self, name, **kwargs):
     with open(get_test_file(name), 'rb') as handle:
         return self.client.post(
             reverse('memory-upload', **kwargs),
             {'file': handle},
             follow=True
         )
예제 #5
0
파일: tests.py 프로젝트: daleathan/weblate
 def test_import_map(self):
     call_command(
         'import_memory',
         get_test_file('memory.tmx'),
         language_map='en_US:en',
     )
     self.assertEqual(TranslationMemory().doc_count(), 2)
예제 #6
0
파일: tests.py 프로젝트: dekoza/weblate
 def test_import_invalid_command(self):
     with self.assertRaises(CommandError):
         call_command(
             'import_memory',
             get_test_file('cs.po')
         )
     memory = TranslationMemory()
     self.assertEqual(memory.doc_count(), 0)
예제 #7
0
파일: tests.py 프로젝트: dekoza/weblate
 def test_import_empty_json_command(self):
     with self.assertRaises(CommandError):
         call_command(
             'import_memory',
             get_test_file('memory-empty.json')
         )
     memory = TranslationMemory()
     self.assertEqual(memory.doc_count(), 0)
예제 #8
0
 def test_extra_file(self):
     """
     Test extra commit file handling.
     """
     subproject = self.create_subproject()
     subproject.pre_commit_script = get_test_file("../../../../examples/hook-generate-mo")
     appsettings.PRE_COMMIT_SCRIPT_CHOICES.append((subproject.pre_commit_script, "hook-generate-mo"))
     subproject.extra_commit_file = "po/%(language)s.mo"
     subproject.save()
     subproject.full_clean()
     translation = subproject.translation_set.get(language_code="cs")
     # change backend file
     with open(translation.get_filename(), "a") as handle:
         handle.write(" ")
     # Test committing
     translation.git_commit(None, "TEST <*****@*****.**>", timezone.now(), force_commit=True)
예제 #9
0
파일: tests.py 프로젝트: daleathan/weblate
    def test_ssh_add(self):
        self.assertEqual(check_data_writable(), [])
        try:
            oldpath = os.environ['PATH']
            os.environ['PATH'] = ':'.join(
                (get_test_file(''), os.environ['PATH'])
            )
            # Verify there is button for adding
            response = self.client.get(reverse('admin:ssh'))
            self.assertContains(response, 'Add host key')

            # Add the key
            response = self.client.post(
                reverse('admin:ssh'),
                {'action': 'add-host', 'host': 'github.com'}
            )
            self.assertContains(response, 'Added host key for github.com')
        finally:
            os.environ['PATH'] = oldpath

        # Check the file contains it
        hostsfile = os.path.join(settings.DATA_DIR, 'ssh', 'known_hosts')
        with open(hostsfile) as handle:
            self.assertIn('github.com', handle.read())
예제 #10
0
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

from weblate.trans.tests.test_views import ViewTestCase
import weblate.trans.admin_views
from django.test import TestCase
from django.core.urlresolvers import reverse
from django.utils.unittest import SkipTest
from weblate.trans.tests.utils import get_test_file
from weblate.trans.util import add_configuration_error
import tempfile
import shutil
import os

TEST_HOSTS = get_test_file('known_hosts')


class AdminTest(ViewTestCase):
    '''
    Tests for customized admin interface.
    '''
    def setUp(self):
        super(AdminTest, self).setUp()
        self.user.is_staff = True
        self.user.is_superuser = True
        self.user.save()

    def test_index(self):
        response = self.client.get(reverse('admin:index'))
        self.assertContains(response, 'SSH')
예제 #11
0
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
#
"""Test for dictionary manipulations."""

from __future__ import unicode_literals

from django.urls import reverse

from weblate.trans.tests.test_views import FixtureTestCase
from weblate.trans.models import Dictionary
from weblate.trans.tests.utils import get_test_file

TEST_TBX = get_test_file('terms.tbx')
TEST_CSV = get_test_file('terms.csv')
TEST_CSV_HEADER = get_test_file('terms-header.csv')
TEST_PO = get_test_file('terms.po')

LONG = '''

<div><b>Game Settings</b> can be found by pressing your device's
Menu Button.</div>

<p>________________</p>
<h1>Interface Icons</h1>

<div><b>The Chest</b><img alt=chest src=chest.png /></div>
<p>Quickslots [Long press the pouches inside to assign items for instant
use]</p>
예제 #12
0
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
#
from unittest import SkipTest

from django.urls import reverse

from weblate.screenshots.models import Screenshot
from weblate.trans.tests.test_views import FixtureTestCase
from weblate.trans.tests.utils import get_test_file
import weblate.screenshots.views

TEST_SCREENSHOT = get_test_file('screenshot.png')


class ViewTest(FixtureTestCase):
    def test_list_empty(self):
        response = self.client.get(
            reverse('screenshots', kwargs=self.kw_component))
        self.assertContains(response, 'Screenshots')

    def do_upload(self, **kwargs):
        with open(TEST_SCREENSHOT, 'rb') as handle:
            data = {'image': handle, 'name': 'Obrazek'}
            data.update(kwargs)
            return self.client.post(reverse('screenshots',
                                            kwargs=self.kw_component),
                                    data,
예제 #13
0
from six import StringIO

from django.test import SimpleTestCase
from django.core.management import call_command
from django.core.management.base import CommandError, SystemCheckError

from weblate.trans.tests.test_models import RepoTestCase
from weblate.trans.tests.test_views import ViewTestCase
from weblate.trans.models import Translation, Component, Suggestion, Source
from weblate.trans.search import Fulltext
from weblate.runner import main
from weblate.trans.tests.utils import get_test_file, create_test_user
from weblate.vcs.mercurial import HgRepository
from weblate.accounts.models import Profile

TEST_PO = get_test_file('cs.po')
TEST_COMPONENTS = get_test_file('components.json')
TEST_COMPONENTS_INVALID = get_test_file('components-invalid.json')


class RunnerTest(SimpleTestCase):
    def test_help(self):
        restore = sys.stdout
        try:
            sys.stdout = StringIO()
            main(['help'])
            self.assertIn('list_versions', sys.stdout.getvalue())
        finally:
            sys.stdout = restore

예제 #14
0
파일: tests.py 프로젝트: dekoza/weblate
          <Product i:nil="true"/>
          <ProductVersion i:nil="true"/>
          <Source i:nil="true"/>
          <Translations>
            <Translation>
              <Language>cs-cz</Language>
              <TranslatedText>Ahoj sv&#x11B;te.</TranslatedText>
            </Translation>
          </Translations>
        </Match>
      </GetTranslationsResult>
    </GetTranslationsResponse>
  </s:Body>
</s:Envelope>
'''.encode('utf-8')
TERMINOLOGY_WDSL = get_test_file('microsoftterminology.wsdl')

DEEPL_RESPONSE = b'''{
    "translations": [
        { "detected_source_language": "EN", "text": "Hallo" }
    ]
}'''


class MachineTranslationTest(TestCase):
    """Testing of machine translation core."""
    def get_machine(self, cls, cache=False):
        machine = cls()
        machine.delete_cache()
        machine.cache_translations = cache
        return machine
예제 #15
0
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
'''
File format specific behavior.
'''
import tempfile
from unittest import TestCase
from weblate.trans.formats import (
    AutoFormat, PoFormat, AndroidFormat, PropertiesFormat,
    JSONFormat, RESXFormat,
    FILE_FORMATS,
)
from weblate.trans.tests.utils import get_test_file

TEST_PO = get_test_file('cs.po')
TEST_JSON = get_test_file('cs.json')
TEST_PROPERTIES = get_test_file('swing.properties')
TEST_ANDROID = get_test_file('strings.xml')
TEST_POT = get_test_file('hello.pot')
TEST_RESX = get_test_file('cs.resx')


class AutoFormatTest(TestCase):
    FORMAT = AutoFormat
    FILE = TEST_PO
    BASE = TEST_POT
    MIME = 'text/x-gettext-catalog'
    EXT = 'po'
    COUNT = 5
    MATCH = 'msgid_plural'
예제 #16
0
import translate.__version__
from translate.storage.po import pofile

from weblate.lang.models import Language
from weblate.formats.auto import AutoFormat
from weblate.formats.ttkit import (
    PoFormat, AndroidFormat, PropertiesFormat, JoomlaFormat, JSONFormat,
    JSONNestedFormat, RESXFormat, PhpFormat, XliffFormat, TSFormat, YAMLFormat,
    RubyYAMLFormat, DTDFormat, WindowsRCFormat, WebExtensionJSONFormat,
)
from weblate.formats.models import FILE_FORMATS
from weblate.formats.auto import detect_filename
from weblate.trans.tests.utils import get_test_file, TempDirMixin


TEST_PO = get_test_file('cs.po')
TEST_JSON = get_test_file('cs.json')
TEST_NESTED_JSON = get_test_file('cs-nested.json')
TEST_WEBEXT_JSON = get_test_file('cs-webext.json')
TEST_PHP = get_test_file('cs.php')
TEST_JOOMLA = get_test_file('cs.ini')
TEST_PROPERTIES = get_test_file('swing.properties')
TEST_ANDROID = get_test_file('strings.xml')
TEST_XLIFF = get_test_file('cs.xliff')
TEST_POT = get_test_file('hello.pot')
TEST_POT_UNICODE = get_test_file('unicode.pot')
TEST_RESX = get_test_file('cs.resx')
TEST_TS = get_test_file('cs.ts')
TEST_YAML = get_test_file('cs.pyml')
TEST_RUBY_YAML = get_test_file('cs.ryml')
TEST_DTD = get_test_file('cs.dtd')
예제 #17
0
"""Test for user handling."""

import os

from django.contrib.sites.models import Site
from django.core.management import call_command
from django.core.management.base import CommandError
from django.test import TestCase

from weblate.accounts.models import Profile
from weblate.auth.models import User
from weblate.lang.models import Language
from weblate.trans.models import Project
from weblate.trans.tests.utils import TempDirMixin, get_test_file

USERDATA_JSON = get_test_file('userdata.json')


class CommandTest(TestCase, TempDirMixin):
    """Test for management commands."""
    def test_userdata(self):
        # Create test user
        language = Language.objects.get(code='cs')
        user = User.objects.create_user('testuser', '*****@*****.**', 'x')
        user.profile.translated = 1000
        user.profile.languages.add(language)
        user.profile.secondary_languages.add(language)
        user.profile.save()
        user.profile.watched.add(
            Project.objects.create(name='name', slug='name'))
예제 #18
0
from io import StringIO
from unittest import SkipTest

from django.core.management import call_command
from django.core.management.base import CommandError, SystemCheckError
from django.test import SimpleTestCase, TestCase

from weblate.accounts.models import Profile
from weblate.runner import main
from weblate.trans.models import Component, Translation
from weblate.trans.tests.test_models import RepoTestCase
from weblate.trans.tests.test_views import FixtureTestCase, ViewTestCase
from weblate.trans.tests.utils import create_test_user, get_test_file
from weblate.vcs.mercurial import HgRepository

TEST_PO = get_test_file("cs.po")
TEST_COMPONENTS = get_test_file("components.json")
TEST_COMPONENTS_INVALID = get_test_file("components-invalid.json")


class RunnerTest(SimpleTestCase):
    def test_help(self):
        restore = sys.stdout
        try:
            sys.stdout = StringIO()
            main(["help"])
            self.assertIn("list_versions", sys.stdout.getvalue())
        finally:
            sys.stdout = restore

예제 #19
0
    PhpFormat,
    PoFormat,
    PoXliffFormat,
    PropertiesFormat,
    RESXFormat,
    RubyYAMLFormat,
    TSFormat,
    WebExtensionJSONFormat,
    XliffFormat,
    YAMLFormat,
)
from weblate.lang.models import Language
from weblate.trans.tests.test_views import FixtureTestCase
from weblate.trans.tests.utils import TempDirMixin, get_test_file

TEST_PO = get_test_file("cs.po")
TEST_CSV = get_test_file("cs-mono.csv")
TEST_CSV_NOHEAD = get_test_file("cs.csv")
TEST_FLATXML = get_test_file("cs-flat.xml")
TEST_JSON = get_test_file("cs.json")
TEST_NESTED_JSON = get_test_file("cs-nested.json")
TEST_WEBEXT_JSON = get_test_file("cs-webext.json")
TEST_PHP = get_test_file("cs.php")
TEST_JOOMLA = get_test_file("cs.joomla.ini")
TEST_INI = get_test_file("cs.ini")
TEST_PROPERTIES = get_test_file("swing.properties")
TEST_GWT = get_test_file("gwt.properties")
TEST_ANDROID = get_test_file("strings.xml")
TEST_XLIFF = get_test_file("cs.xliff")
TEST_POXLIFF = get_test_file("cs.poxliff")
TEST_XLIFF_ID = get_test_file("ids.xliff")
예제 #20
0
    PoFormat,
    PoXliffFormat,
    PropertiesFormat,
    RESXFormat,
    RubyYAMLFormat,
    TSFormat,
    WebExtensionJSONFormat,
    WindowsRCFormat,
    XliffFormat,
    YAMLFormat,
)
from weblate.lang.models import Language
from weblate.trans.tests.test_views import FixtureTestCase
from weblate.trans.tests.utils import TempDirMixin, get_test_file

TEST_PO = get_test_file('cs.po')
TEST_CSV = get_test_file('cs-mono.csv')
TEST_CSV_NOHEAD = get_test_file('cs.csv')
TEST_JSON = get_test_file('cs.json')
TEST_NESTED_JSON = get_test_file('cs-nested.json')
TEST_WEBEXT_JSON = get_test_file('cs-webext.json')
TEST_PHP = get_test_file('cs.php')
TEST_JOOMLA = get_test_file('cs.ini')
TEST_PROPERTIES = get_test_file('swing.properties')
TEST_ANDROID = get_test_file('strings.xml')
TEST_XLIFF = get_test_file('cs.xliff')
TEST_XLIFF_ID = get_test_file('ids.xliff')
TEST_POT = get_test_file('hello.pot')
TEST_POT_UNICODE = get_test_file('unicode.pot')
TEST_RESX = get_test_file('cs.resx')
TEST_TS = get_test_file('cs.ts')
예제 #21
0
class GitlabFakeRepository(GitlabRepository):
    _is_supported = None
    _version = None
    _cmd = get_test_file('lab')
예제 #22
0
파일: tests.py 프로젝트: yante/weblate
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
#

from django.core.files import File
from django.urls import reverse
from rest_framework.test import APITestCase

from weblate.auth.models import Group, User
from weblate.screenshots.models import Screenshot
from weblate.trans.models import Change, Component, Project, Translation, Unit
from weblate.trans.tests.utils import RepoTestMixin, get_test_file
from weblate.utils.django_hacks import immediate_on_commit, immediate_on_commit_leave
from weblate.utils.state import STATE_TRANSLATED

TEST_PO = get_test_file("cs.po")
TEST_BADPLURALS = get_test_file("cs-badplurals.po")
TEST_SCREENSHOT = get_test_file("screenshot.png")


class APIBaseTest(APITestCase, RepoTestMixin):
    @classmethod
    def setUpClass(cls):
        super().setUpClass()
        immediate_on_commit(cls)

    @classmethod
    def tearDownClass(cls):
        super().tearDownClass()
        immediate_on_commit_leave(cls)
예제 #23
0
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

"""
Tests for import and export.
"""

from __future__ import unicode_literals

from django.core.urlresolvers import reverse

from weblate.trans.tests.test_views import ViewTestCase
from weblate.trans.tests.utils import get_test_file

TEST_PO = get_test_file('cs.po')
TEST_CSV = get_test_file('cs.csv')
TEST_PO_BOM = get_test_file('cs-bom.po')
TEST_FUZZY_PO = get_test_file('cs-fuzzy.po')
TEST_MO = get_test_file('cs.mo')
TEST_ANDROID = get_test_file('strings-cs.xml')

TRANSLATION_OURS = 'Nazdar světe!\n'
TRANSLATION_PO = 'Ahoj světe!\n'


class ImportBaseTest(ViewTestCase):
    '''
    Base test of file imports.
    '''
    test_file = TEST_PO
예제 #24
0
 def test_import_empty_users(self):
     """Test importing empty file"""
     call_command('importusers', get_test_file('users-empty.json'))
     # Only anonymous user
     self.assertEqual(User.objects.count(), 1)
예제 #25
0
    "email": "*****@*****.**",
    "fullname": "First Last",
    "captcha": "9999",
}

GH_BACKENDS = (
    "social_core.backends.email.EmailAuth",
    "social_core.backends.github.GithubOAuth2",
    "weblate.accounts.auth.WeblateUserBackend",
)
SAML_BACKENDS = (
    "social_core.backends.email.EmailAuth",
    "social_core.backends.saml.SAMLAuth",
    "weblate.accounts.auth.WeblateUserBackend",
)
with open(get_test_file("saml.crt")) as handle:
    SAML_CERT = handle.read()
with open(get_test_file("saml.key")) as handle:
    SAML_KEY = handle.read()


class BaseRegistrationTest(TestCase, RegistrationTestMixin):
    clear_cookie = False
    social_cleanup = False

    @classmethod
    def setUpClass(cls):
        super().setUpClass()
        immediate_on_commit(cls)

    @classmethod
예제 #26
0
#
"""Test for import and export."""

from copy import copy

from django.contrib.messages import ERROR
from django.test import SimpleTestCase
from django.urls import reverse

from weblate.formats.helpers import BytesIOMode
from weblate.trans.forms import SimpleUploadForm
from weblate.trans.models import ComponentList
from weblate.trans.tests.test_views import ViewTestCase
from weblate.trans.tests.utils import get_test_file

TEST_PO = get_test_file("cs.po")
TEST_CSV = get_test_file("cs.csv")
TEST_CSV_QUOTES = get_test_file("cs-quotes.csv")
TEST_CSV_QUOTES_ESCAPED = get_test_file("cs-quotes-escaped.csv")
TEST_PO_BOM = get_test_file("cs-bom.po")
TEST_FUZZY_PO = get_test_file("cs-fuzzy.po")
TEST_BADPLURALS = get_test_file("cs-badplurals.po")
TEST_POT = get_test_file("hello.pot")
TEST_POT_CHARSET = get_test_file("hello-charset.pot")
TEST_MO = get_test_file("cs.mo")
TEST_XLIFF = get_test_file("cs.poxliff")
TEST_ANDROID = get_test_file("strings-cs.xml")
TEST_XLSX = get_test_file("cs.xlsx")
TEST_TBX = get_test_file("terms.tbx")

TRANSLATION_OURS = "Nazdar světe!\n"
예제 #27
0
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

"""
Tests for import and export.
"""

from weblate.trans.tests.test_views import ViewTestCase
from django.core.urlresolvers import reverse
from weblate.trans.tests.utils import get_test_file

TEST_PO = get_test_file('cs.po')
TEST_MO = get_test_file('cs.mo')
TEST_ANDROID = get_test_file('strings-cs.xml')

TRANSLATION_OURS = u'Nazdar světe!\n'
TRANSLATION_PO = u'Ahoj světe!\n'


class ImportTest(ViewTestCase):
    '''
    Testing of file imports.
    '''
    test_file = TEST_PO

    def setUp(self):
        super(ImportTest, self).setUp()
예제 #28
0
from django.utils.encoding import force_text

import six

from translate.storage.po import pofile

from weblate.lang.models import Language
from weblate.trans.formats import (
    AutoFormat, PoFormat, AndroidFormat, PropertiesFormat,
    JSONFormat, RESXFormat, PhpFormat, XliffFormat, TSFormat,
    FILE_FORMATS, detect_filename,
)
from weblate.trans.tests.utils import get_test_file


TEST_PO = get_test_file('cs.po')
TEST_JSON = get_test_file('cs.json')
TEST_PHP = get_test_file('cs.php')
TEST_PROPERTIES = get_test_file('swing.properties')
TEST_ANDROID = get_test_file('strings.xml')
TEST_XLIFF = get_test_file('cs.xliff')
TEST_POT = get_test_file('hello.pot')
TEST_POT_UNICODE = get_test_file('unicode.pot')
TEST_RESX = get_test_file('cs.resx')
TEST_TS = get_test_file('cs.ts')


class AutoLoadTest(TestCase):
    def single_test(self, filename, fileclass):
        with open(filename, 'rb') as handle:
            store = AutoFormat.parse(handle)
예제 #29
0
파일: tests.py 프로젝트: nijel/weblate
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
#
from unittest import SkipTest

from django.urls import reverse

import weblate.screenshots.views
from weblate.screenshots.models import Screenshot
from weblate.trans.tests.test_views import FixtureTestCase
from weblate.trans.tests.utils import get_test_file

TEST_SCREENSHOT = get_test_file('screenshot.png')


class ViewTest(FixtureTestCase):
    def test_list_empty(self):
        response = self.client.get(
            reverse('screenshots', kwargs=self.kw_component)
        )
        self.assertContains(response, 'Screenshots')

    def do_upload(self, **kwargs):
        with open(TEST_SCREENSHOT, 'rb') as handle:
            data = {'image': handle, 'name': 'Obrazek'}
            data.update(kwargs)
            return self.client.post(
                reverse('screenshots', kwargs=self.kw_component),
예제 #30
0
파일: tests.py 프로젝트: atallahade/weblate
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
#

from django.core.files import File
from django.urls import reverse

from rest_framework.test import APITestCase

from weblate.auth.models import User, Group
from weblate.screenshots.models import Screenshot
from weblate.trans.models import Project, Change, Unit, Source
from weblate.trans.tests.utils import RepoTestMixin, get_test_file

TEST_PO = get_test_file('cs.po')
TEST_SCREENSHOT = get_test_file('screenshot.png')


class APIBaseTest(APITestCase, RepoTestMixin):
    def setUp(self):
        self.clone_test_repos()
        self.component = self.create_component()
        self.translation_kwargs = {
            'language__code': 'cs',
            'component__slug': 'test',
            'component__project__slug': 'test'
        }
        self.component_kwargs = {'slug': 'test', 'project__slug': 'test'}
        self.project_kwargs = {'slug': 'test'}
        self.tearDown()
예제 #31
0
 def test_import_map(self):
     call_command(
         "import_memory", get_test_file("memory.tmx"), language_map="en_US:en"
     )
     self.assertEqual(Memory.objects.count(), 2)
예제 #32
0
 def mock_pypi():
     with open(get_test_file("pypi.json")) as handle:
         responses.add(responses.GET, PYPI, body=handle.read())
예제 #33
0
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
#
"""File format specific behavior."""
from __future__ import unicode_literals

from io import BytesIO

from openpyxl import load_workbook

from weblate.formats.external import XlsxFormat
from weblate.formats.tests.test_formats import AutoFormatTest
from weblate.trans.tests.utils import get_test_file

XLSX_FILE = get_test_file('cs-mono.xlsx')


class XlsxFormatTest(AutoFormatTest):
    FORMAT = XlsxFormat
    FILE = XLSX_FILE
    MIME = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
    EXT = 'xlsx'
    COUNT = 4
    MASK = '*/translations.xlsx'
    EXPECTED_PATH = 'cs_CZ/translations.xlsx'
    FIND = 'HELLO'
    FIND_MATCH = 'Hello, world!\r\n'
    MATCH = b'PK'
    NEW_UNIT_MATCH = b'PK'
    BASE = XLSX_FILE
예제 #34
0
 def upload_file(self, name, **kwargs):
     with open(get_test_file(name), 'rb') as handle:
         return self.client.post(reverse('memory-upload', **kwargs),
                                 {'file': handle},
                                 follow=True)
예제 #35
0
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
#
"""Test for import and export."""

from copy import copy

from django.contrib.messages import ERROR
from django.test import SimpleTestCase
from django.urls import reverse

from weblate.trans.forms import SimpleUploadForm
from weblate.trans.models import ComponentList
from weblate.trans.tests.test_views import ViewTestCase
from weblate.trans.tests.utils import get_test_file

TEST_PO = get_test_file('cs.po')
TEST_CSV = get_test_file('cs.csv')
TEST_CSV_QUOTES = get_test_file('cs-quotes.csv')
TEST_CSV_QUOTES_ESCAPED = get_test_file('cs-quotes-escaped.csv')
TEST_PO_BOM = get_test_file('cs-bom.po')
TEST_FUZZY_PO = get_test_file('cs-fuzzy.po')
TEST_BADPLURALS = get_test_file('cs-badplurals.po')
TEST_MO = get_test_file('cs.mo')
TEST_XLIFF = get_test_file('cs.poxliff')
TEST_ANDROID = get_test_file('strings-cs.xml')
TEST_XLSX = get_test_file('cs.xlsx')

TRANSLATION_OURS = 'Nazdar světe!\n'
TRANSLATION_PO = 'Ahoj světe!\n'

예제 #36
0
 def test_import_invalid_command(self):
     with self.assertRaises(CommandError):
         call_command('import_memory', get_test_file('cs.po'))
     memory = TranslationMemory()
     self.assertEqual(memory.doc_count(), 0)
예제 #37
0
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

import os
import shutil
from django.test import TestCase
from weblate.trans.ssh import get_host_keys, create_ssh_wrapper, ssh_file
from weblate.trans.tests.utils import get_test_file
from weblate.trans.tests import OverrideSettings
from weblate import appsettings

TEST_HOSTS = get_test_file('known_hosts')


class SSHTest(TestCase):
    '''
    Tests for customized admin interface.
    '''
    @OverrideSettings(DATA_DIR=OverrideSettings.TEMP_DIR)
    def test_parse(self):
        tempdir = os.path.join(appsettings.DATA_DIR, 'ssh')
        os.makedirs(tempdir)
        shutil.copy(TEST_HOSTS, tempdir)
        hosts = get_host_keys()
        self.assertEqual(len(hosts), 50)

    @OverrideSettings(DATA_DIR=OverrideSettings.TEMP_DIR)
예제 #38
0
 def test_import_empty_json_command(self):
     with self.assertRaises(CommandError):
         call_command('import_memory', get_test_file('memory-empty.json'))
     memory = TranslationMemory()
     self.assertEqual(memory.doc_count(), 0)
예제 #39
0
 def test_importdjangousers(self):
     # First import
     call_command('importusers', get_test_file('users-django.json'))
     self.assertEqual(User.objects.count(), 2)
예제 #40
0
from six import StringIO

from django.test import TestCase
from django.core.management import call_command
from django.core.management.base import CommandError

from weblate.trans.tests.test_models import RepoTestCase
from weblate.trans.models import (Translation, SubProject, Suggestion,
                                  IndexUpdate)
from weblate.runner import main
from weblate.trans.tests.utils import get_test_file, create_test_user
from weblate.trans.vcs import HgRepository
from weblate.accounts.models import Profile

TEST_PO = get_test_file('cs.po')
TEST_COMPONENTS = get_test_file('components.json')


class RunnerTest(TestCase):
    def test_help(self):
        main(['help'])


class ImportProjectTest(RepoTestCase):
    def do_import(self, path=None, **kwargs):
        call_command('import_project', 'test',
                     self.git_repo_path if path is None else path, 'master',
                     '**/*.po', **kwargs)

    def test_import(self):
예제 #41
0
 def test_import_invalid_users(self):
     """Test error handling in user import"""
     call_command('importusers', get_test_file('users-invalid.json'))
     # Only anonymous user
     self.assertEqual(User.objects.count(), 1)
예제 #42
0
    def test_screenshots(self):
        """Screenshot tests."""
        text = ("Automatic translation via machine translation uses active "
                "machine translation engines to get the best possible "
                "translations and applies them in this project.")
        self.create_component()
        language = Language.objects.get(code="cs")

        source = Unit.objects.get(source=text,
                                  translation__language=language).source_unit
        source.explanation = "Help text for automatic translation tool"
        source.save()
        glossary = Glossary.objects.get()
        Term.objects.create(
            user=None,
            glossary=glossary,
            language=language,
            source="machine translation",
            target="strojový překlad",
        )
        Term.objects.create(
            user=None,
            glossary=glossary,
            language=language,
            source="project",
            target="projekt",
        )
        source.translation.component.alert_set.all().delete()

        def capture_unit(name, tab):
            unit = Unit.objects.get(source=text,
                                    translation__language=language)
            with self.wait_for_page_load():
                self.driver.get("{0}{1}".format(self.live_server_url,
                                                unit.get_absolute_url()))
            self.click(htmlid=tab)
            self.screenshot(name)
            with self.wait_for_page_load():
                self.click("Dashboard")

        def wait_search():
            WebDriverWait(self.driver, 30).until(
                presence_of_element_located(
                    (By.XPATH, '//tbody[@id="search-results"]/tr')))

        self.do_login(superuser=True)
        capture_unit("source-information.png", "toggle-nearby")
        self.click(htmlid="projects-menu")
        with self.wait_for_page_load():
            self.click("Browse all projects")
        with self.wait_for_page_load():
            self.click("WeblateOrg")
        with self.wait_for_page_load():
            self.click("Django")
        self.click("Manage")
        with self.wait_for_page_load():
            self.click("Screenshots")

        # Upload screenshot
        self.driver.find_element(By.ID,
                                 "id_name").send_keys("Automatic translation")
        element = self.driver.find_element(By.ID, "id_image")
        element.send_keys(
            element._upload(get_test_file("screenshot.png"))  # noqa: SLF001
        )
        with self.wait_for_page_load():
            element.submit()

        # Perform OCR
        if weblate.screenshots.views.HAS_OCR:
            self.click(htmlid="screenshots-auto")
            wait_search()

            self.screenshot("screenshot-ocr.png")

        # Add string manually
        self.driver.find_element(By.ID,
                                 "search-input").send_keys("'{}'".format(text))
        self.click(htmlid="screenshots-search")
        wait_search()
        self.click(self.driver.find_element(By.CLASS_NAME, "add-string"))

        # Unit should have screenshot assigned now
        capture_unit("screenshot-context.png", "toggle-machinery")
예제 #43
0
파일: tests.py 프로젝트: urbalazs/weblate
 def test_import_tmx2_command(self):
     call_command('import_memory', get_test_file('memory2.tmx'))
     memory = TranslationMemory()
     self.assertEqual(memory.doc_count(), 1)
예제 #44
0
파일: tests.py 프로젝트: dekoza/weblate
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
#

from django.core.files import File
from django.urls import reverse

from rest_framework.test import APITestCase

from weblate.auth.models import User, Group
from weblate.screenshots.models import Screenshot
from weblate.trans.models import Project, Change, Unit, Source
from weblate.trans.tests.utils import RepoTestMixin, get_test_file

TEST_PO = get_test_file('cs.po')
TEST_SCREENSHOT = get_test_file('screenshot.png')


class APIBaseTest(APITestCase, RepoTestMixin):
    def setUp(self):
        self.clone_test_repos()
        self.component = self.create_component()
        self.translation_kwargs = {
            'language__code': 'cs',
            'component__slug': 'test',
            'component__project__slug': 'test'
        }
        self.component_kwargs = {
            'slug': 'test',
            'project__slug': 'test'
예제 #45
0
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
'''
File format specific behavior.
'''
import tempfile
from unittest import TestCase
from weblate.trans.formats import (
    AutoFormat, PoFormat, AndroidFormat,
)
from weblate.trans.tests.utils import get_test_file

TEST_PO = get_test_file('cs.po')
TEST_ANDROID = get_test_file('strings.xml')
TEST_POT = get_test_file('hello.pot')


class AutoFormatTest(TestCase):
    FORMAT = AutoFormat
    FILE = TEST_PO
    BASE = TEST_POT
    MIME = 'text/x-gettext-catalog'
    EXT = 'po'
    COUNT = 5
    MATCH = 'msgid_plural'
    MASK = 'po/*.po'
    EXPECTED_PATH = '/path/po/cs_CZ.po'
예제 #46
0
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

"""
Tests for import and export.
"""

from weblate.trans.tests.test_views import ViewTestCase
from django.core.urlresolvers import reverse
from weblate.trans.tests.utils import get_test_file

TEST_PO = get_test_file("cs.po")
TEST_CSV = get_test_file("cs.csv")
TEST_PO_BOM = get_test_file("cs-bom.po")
TEST_FUZZY_PO = get_test_file("cs-fuzzy.po")
TEST_MO = get_test_file("cs.mo")
TEST_ANDROID = get_test_file("strings-cs.xml")

TRANSLATION_OURS = u"Nazdar světe!\n"
TRANSLATION_PO = u"Ahoj světe!\n"


class ImportBaseTest(ViewTestCase):
    """
    Base test of file imports.
    """
예제 #47
0
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

"""
Tests for dictionary manipulations.
"""

from __future__ import unicode_literals

from django.core.urlresolvers import reverse

from weblate.trans.tests.test_views import ViewTestCase
from weblate.trans.models import Dictionary
from weblate.trans.tests.utils import get_test_file

TEST_TBX = get_test_file('terms.tbx')
TEST_CSV = get_test_file('terms.csv')
TEST_CSV_HEADER = get_test_file('terms-header.csv')
TEST_PO = get_test_file('terms.po')


class DictionaryTest(ViewTestCase):
    '''
    Testing of dictionary manipulations.
    '''

    def get_url(self, url):
        return reverse(url, kwargs={
            'lang': 'cs',
            'project': self.subproject.project.slug,
        })
예제 #48
0
from django.core.management import call_command
from django.core.management.base import CommandError, SystemCheckError
from django.test import SimpleTestCase
from six import StringIO

from weblate.accounts.models import Profile
from weblate.runner import main
from weblate.trans.models import Component, Source, Suggestion, Translation
from weblate.trans.search import Fulltext
from weblate.trans.tests.test_models import RepoTestCase
from weblate.trans.tests.test_views import ViewTestCase
from weblate.trans.tests.utils import create_test_user, get_test_file
from weblate.vcs.mercurial import HgRepository

TEST_PO = get_test_file('cs.po')
TEST_COMPONENTS = get_test_file('components.json')
TEST_COMPONENTS_INVALID = get_test_file('components-invalid.json')


class RunnerTest(SimpleTestCase):
    def test_help(self):
        restore = sys.stdout
        try:
            sys.stdout = StringIO()
            main(['help'])
            self.assertIn('list_versions', sys.stdout.getvalue())
        finally:
            sys.stdout = restore

예제 #49
0
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
#

"""Test for import and export."""

from __future__ import unicode_literals

from django.contrib.messages import ERROR
from django.test import SimpleTestCase
from django.urls import reverse

from weblate.trans.forms import SimpleUploadForm
from weblate.trans.tests.test_views import ViewTestCase
from weblate.trans.tests.utils import get_test_file

TEST_PO = get_test_file('cs.po')
TEST_CSV = get_test_file('cs.csv')
TEST_CSV_QUOTES = get_test_file('cs-quotes.csv')
TEST_CSV_QUOTES_ESCAPED = get_test_file('cs-quotes-escaped.csv')
TEST_PO_BOM = get_test_file('cs-bom.po')
TEST_FUZZY_PO = get_test_file('cs-fuzzy.po')
TEST_BADPLURALS = get_test_file('cs-badplurals.po')
TEST_MO = get_test_file('cs.mo')
TEST_XLIFF = get_test_file('cs.poxliff')
TEST_ANDROID = get_test_file('strings-cs.xml')

TRANSLATION_OURS = 'Nazdar světe!\n'
TRANSLATION_PO = 'Ahoj světe!\n'


class ImportBaseTest(ViewTestCase):
예제 #50
0
"""

from django.test import TestCase
from django.core.management import call_command
from django.core.management.base import CommandError
from django.contrib.auth.models import User

from weblate.trans.tests.test_models import RepoTestCase
from weblate.trans.models import (
    Translation, SubProject, Suggestion, IndexUpdate
)
from weblate.runner import main
from weblate.trans.tests.utils import get_test_file
from weblate.accounts.models import Profile

TEST_PO = get_test_file('cs.po')
TEST_COMPONENTS = get_test_file('components.json')


class RunnerTest(TestCase):
    def test_help(self):
        main(['help'])


class ImportProjectTest(RepoTestCase):
    def do_import(self, path=None, **kwargs):
        call_command(
            'import_project',
            'test',
            self.git_repo_path if path is None else path,
            'master',
예제 #51
0
 def test_import_empty_users(self):
     """Test importing empty file"""
     call_command('importusers', get_test_file('users-empty.json'))
     # Only anonymous user
     self.assertEqual(User.objects.count(), 1)
예제 #52
0
파일: test_txt.py 프로젝트: nijel/weblate
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
#
"""File format specific behavior."""
from __future__ import unicode_literals

import os.path

from weblate.formats.tests.test_formats import AutoFormatTest
from weblate.formats.txt import AppStoreFormat
from weblate.trans.tests.utils import get_test_file

APPSTORE_FILE = get_test_file('short_description.txt')


class AppStoreFormatTest(AutoFormatTest):
    FORMAT = AppStoreFormat
    FILE = APPSTORE_FILE
    MIME = 'text/plain'
    EXT = 'txt'
    COUNT = 1
    MASK = 'market/*'
    EXPECTED_PATH = 'market/cs_CZ'
    FIND = 'Hello world'
    FIND_CONTEXT = 'short_description.txt:1'
    FIND_MATCH = 'Hello world'
    MATCH = None
    BASE = APPSTORE_FILE
예제 #53
0
 def test_importdjangousers(self):
     # First import
     call_command('importusers', get_test_file('users-django.json'))
     self.assertEqual(User.objects.count(), 2)
예제 #54
0
          <Product i:nil="true"/>
          <ProductVersion i:nil="true"/>
          <Source i:nil="true"/>
          <Translations>
            <Translation>
              <Language>cs-cz</Language>
              <TranslatedText>Ahoj sv&#x11B;te.</TranslatedText>
            </Translation>
          </Translations>
        </Match>
      </GetTranslationsResult>
    </GetTranslationsResponse>
  </s:Body>
</s:Envelope>
'''.encode('utf-8')
TERMINOLOGY_WDSL = get_test_file('microsoftterminology.wsdl')

DEEPL_RESPONSE = b'''{
    "translations": [
        { "detected_source_language": "EN", "text": "Hallo" }
    ]
}'''


class MachineTranslationTest(TestCase):
    """Testing of machine translation core."""
    def get_machine(self, cls, cache=False):
        machine = cls()
        machine.delete_cache()
        machine.cache_translations = cache
        return machine
예제 #55
0
 def test_import_invalud_users(self):
     """Test error handling in user import"""
     call_command('importusers', get_test_file('users-invalid.json'))
     # Only anonymous user
     self.assertEqual(User.objects.count(), 1)
예제 #56
0
 def test_import_invalid_command(self):
     with self.assertRaises(CommandError):
         call_command("import_memory", get_test_file("cs.po"))
     self.assertEqual(Memory.objects.count(), 0)
예제 #57
0
 def test_import_empty_json_command(self):
     with self.assertRaises(CommandError):
         call_command("import_memory", get_test_file("memory-empty.json"))
     self.assertEqual(Memory.objects.count(), 0)
예제 #58
0
 def test_import_tmx2_command(self):
     call_command("import_memory", get_test_file("memory2.tmx"))
     self.assertEqual(Memory.objects.count(), 1)
예제 #59
0
파일: tests.py 프로젝트: dtschan/weblate
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

from django.contrib.auth.models import User, Group
from django.core.cache import cache
from django.core.urlresolvers import reverse

from rest_framework.test import APITestCase

from weblate.trans.models.project import Project, get_acl_cache_key
from weblate.trans.tests.utils import RepoTestMixin, get_test_file

TEST_PO = get_test_file('cs.po')


class APIBaseTest(APITestCase, RepoTestMixin):
    def setUp(self):
        self.clone_test_repos()
        self.subproject = self.create_subproject()
        self.translation_kwargs = {
            'language__code': 'cs',
            'subproject__slug': 'test',
            'subproject__project__slug': 'test'
        }
        self.component_kwargs = {
            'slug': 'test',
            'project__slug': 'test'
        }
예제 #60
0
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
#
"""File format specific behavior."""
from __future__ import unicode_literals

from io import BytesIO

from openpyxl import load_workbook

from weblate.formats.external import XlsxFormat
from weblate.formats.tests.test_formats import AutoFormatTest
from weblate.trans.tests.utils import get_test_file

XLSX_FILE = get_test_file('cs-mono.xlsx')


class XlsxFormatTest(AutoFormatTest):
    FORMAT = XlsxFormat
    FILE = XLSX_FILE
    MIME = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
    EXT = 'xlsx'
    COUNT = 4
    MASK = '*/translations.xlsx'
    EXPECTED_PATH = 'cs_CZ/translations.xlsx'
    FIND = 'HELLO'
    FIND_MATCH = 'Hello, world!\r\n'
    MATCH = b'PK'
    NEW_UNIT_MATCH = b'PK'
    BASE = XLSX_FILE