Exemple #1
0
    def get_context_data(self, **kwargs):
        languages = Language.objects.exclude(code='templates')
        language_choices = [(lang.id, unicode(lang)) for lang in languages]
        try:
            english = Language.objects.get(code='en')
            default_language = english.id
        except Language.DoesNotExist:
            default_language = languages[0].id

        filetypes = []
        for info in formats.get().values():
            filetypes.append([info["pk"], info["display_title"]])

        project_checker_choices = [
            (checker, checker) for checker in sorted(PROJECT_CHECKERS.keys())
        ]
        plugin_choices = sorted([(x, x) for x in fs_plugins.gather()])
        fs_presets = FS_PRESETS.values()
        return {
            'page': 'admin-projects',
            'form_choices': {
                'checkstyle': project_checker_choices,
                'filetypes': filetypes,
                'fs_plugin': plugin_choices,
                'fs_preset': fs_presets,
                'source_language': language_choices,
                'defaults': {
                    'source_language': default_language,
                },
            },
        }
Exemple #2
0
    def get_context_data(self, **kwargs):
        languages = Language.objects.exclude(code='templates')
        language_choices = [(lang.id, unicode(lang)) for lang in languages]
        try:
            english = Language.objects.get(code='en')
            default_language = english.id
        except Language.DoesNotExist:
            default_language = languages[0].id

        filetypes = []
        for info in formats.get().values():
            filetypes.append(
                [info["pk"], info["display_title"]])

        project_checker_choices = [
            (checker, checker)
            for checker
            in sorted(PROJECT_CHECKERS.keys())]
        plugin_choices = sorted([(x, x) for x in fs_plugins.gather()])
        fs_presets = FS_PRESETS.values()
        return {
            'page': 'admin-projects',
            'form_choices': {
                'checkstyle': project_checker_choices,
                'filetypes': filetypes,
                'fs_plugin': plugin_choices,
                'fs_preset': fs_presets,
                'source_language': language_choices,
                'defaults': {
                    'source_language': default_language,
                },
            },
        }
Exemple #3
0
def test_plugin_providers():
    class CustomPlugin(Plugin):
        pass

    @provider(fs_plugins)
    def custom_fs_plugin(**kwargs):
        return dict(custom=CustomPlugin)

    assert fs_plugins.gather()["custom"] == CustomPlugin
Exemple #4
0
def test_form_fs_project_admin(no_fs_plugins, project0):

    class Dummy1FSPlugin(object):
        fs_type = "dummy1_plugin"
        name = "dummy1"

    class Dummy2FSPlugin(object):
        fs_type = "dummy2_plugin"
        name = "dummy2"

    class DummyURLValidator(object):

        def validate(self, v):
            pass

    project0.config["pootle_fs.fs_type"] = "dummy1_plugin"
    project0.config["pootle_fs.fs_url"] = "/foo/bar"
    project0.config["pootle_fs.translation_mappings"] = dict(
        default="/<language_code>/<filename>.<ext>")

    with no_fs_plugins():
        @provider(fs_plugins)
        def fs_plugin_provider(**kwargs_):
            return dict(
                dummy1=Dummy1FSPlugin,
                dummy2=Dummy2FSPlugin)

        @provider(fs_url_validator, sender=Dummy2FSPlugin)
        def fs_url_validator_getter(**kwargs_):
            return DummyURLValidator

        form = ProjectFSAdminForm(
            project=project0,
            data=dict(
                fs_url="/tmp/dummy2",
                fs_type="dummy2",
                translation_mapping=(
                    "/some/path/to/<language_code>/<filename>.<ext>")))
        assert form.is_valid()
        assert form.fs_path_validator is TranslationMappingValidator
        fs_type_choices = list(
            (plugin_type, plugin.name or plugin.fs_type)
            for plugin_type, plugin
            in fs_plugins.gather().items())
        assert list(form.fs_type_choices) == fs_type_choices
        assert list(form.fields["fs_type"].choices) == fs_type_choices
        assert form.fields["fs_type"].initial == "dummy1_plugin"
        assert form.fields["fs_url"].initial == "/foo/bar"
        assert form.fields["translation_mapping"].initial == (
            "/<language_code>/<filename>.<ext>")
        assert isinstance(
            form.fs_url_validator, DummyURLValidator)
        form.save()
        assert project0.config["pootle_fs.fs_type"] == "dummy2"
        assert project0.config["pootle_fs.fs_url"] == "/tmp/dummy2"
        assert project0.config["pootle_fs.translation_mappings"] == dict(
            default="/some/path/to/<language_code>/<filename>.<ext>")
Exemple #5
0
    def __init__(self, *args, **kwargs):
        super(ProjectForm, self).__init__(*args, **kwargs)

        queryset = Language.objects.exclude(code='templates')
        self.fields['source_language'].queryset = queryset

        self.fields["filetypes"].initial = [
            self.fields["filetypes"].queryset.get(name="po")]
        self.fields["fs_plugin"].choices = [(x, x) for x in fs_plugins.gather()]
Exemple #6
0
def test_plugin_providers():

    class CustomPlugin(Plugin):
        pass

    @provider(fs_plugins)
    def custom_fs_plugin(**kwargs):
        return dict(custom=CustomPlugin)

    assert fs_plugins.gather()["custom"] == CustomPlugin
Exemple #7
0
def test_form_fs_project_admin(no_fs_plugins, project0):

    class Dummy1FSPlugin(object):
        fs_type = "dummy1_plugin"
        name = "dummy1"

    class Dummy2FSPlugin(object):
        fs_type = "dummy2_plugin"
        name = "dummy2"

    class DummyURLValidator(object):

        def validate(self, v):
            pass

    @provider(fs_plugins)
    def fs_plugin_provider(**kwargs_):
        return dict(
            dummy1=Dummy1FSPlugin,
            dummy2=Dummy2FSPlugin)

    @provider(fs_url_validator, sender=Dummy2FSPlugin)
    def fs_url_validator_getter(**kwargs_):
        return DummyURLValidator

    project0.config["pootle_fs.fs_type"] = "dummy1_plugin"
    project0.config["pootle_fs.fs_url"] = "/foo/bar"
    project0.config["pootle_fs.translation_mappings"] = dict(
        default="/<language_code>/<filename>.<ext>")
    form = ProjectFSAdminForm(
        project=project0,
        data=dict(
            fs_url="/tmp/dummy2",
            fs_type="dummy2",
            translation_mapping="/some/path/to/<language_code>/<filename>.<ext>"))
    assert form.is_valid()
    assert form.fs_path_validator is TranslationMappingValidator
    fs_type_choices = list(
        (plugin_type, plugin.name or plugin.fs_type)
        for plugin_type, plugin
        in fs_plugins.gather().items())
    assert list(form.fs_type_choices) == fs_type_choices
    assert list(form.fields["fs_type"].choices) == fs_type_choices
    assert form.fields["fs_type"].initial == "dummy1_plugin"
    assert form.fields["fs_url"].initial == "/foo/bar"
    assert form.fields["translation_mapping"].initial == (
        "/<language_code>/<filename>.<ext>")
    assert isinstance(
        form.fs_url_validator, DummyURLValidator)
    form.save()
    assert project0.config["pootle_fs.fs_type"] == "dummy2"
    assert project0.config["pootle_fs.fs_url"] == "/tmp/dummy2"
    assert project0.config["pootle_fs.translation_mappings"] == dict(
        default="/some/path/to/<language_code>/<filename>.<ext>")
Exemple #8
0
    def __init__(self, *args, **kwargs):
        super(ProjectForm, self).__init__(*args, **kwargs)

        queryset = Language.objects.exclude(code='templates')
        self.fields['source_language'].queryset = queryset

        self.fields["filetypes"].initial = [
            self.fields["filetypes"].queryset.get(name="po")
        ]
        self.fields["fs_plugin"].choices = [(x, x)
                                            for x in fs_plugins.gather()]
        self.fields["template_name"].initial = (
            self.instance.lang_mapper.get_upstream_code("templates"))
Exemple #9
0
 def clean(self):
     fs_plugin = self.cleaned_data.get("fs_plugin")
     if not fs_plugin:
         return
     plugin = fs_plugins.gather()[fs_plugin]
     fs_url = self.cleaned_data.get("fs_url")
     if not fs_url:
         return
     validator = fs_url_validator.get(plugin)()
     try:
         validator.validate(fs_url)
     except ValidationError:
         self.errors["fs_url"] = self.error_class(
             [_("Invalid fs url or path for plugin '%s'",
                self.cleaned_data["fs_plugin"])])
Exemple #10
0
 def clean(self):
     fs_plugin = self.cleaned_data.get("fs_plugin")
     if not fs_plugin:
         return
     plugin = fs_plugins.gather()[fs_plugin]
     fs_url = self.cleaned_data.get("fs_url")
     if not fs_url:
         return
     validator = fs_url_validator.get(plugin)()
     try:
         validator.validate(fs_url)
     except ValidationError:
         self.errors["fs_url"] = self.error_class([
             _("Invalid Path or URL for chosen Filesystem backend "
               "'%s'") % self.cleaned_data["fs_plugin"]
         ])
Exemple #11
0
def test_admin_view_projects(client, request_users, english):
    user = request_users["user"]

    client.login(
        username=user.username,
        password=request_users["password"])

    response = client.get(
        reverse(
            "pootle-admin-projects"))

    if not user.is_superuser:
        assert response.status_code == 403
        return
    languages = Language.objects.exclude(code='templates')
    language_choices = [(lang.id, unicode(lang)) for lang in languages]
    filetypes = []
    for info in formats.get().values():
        filetypes.append(
            [info["pk"], info["display_title"]])
    project_checker_choices = [
        (checker, checker)
        for checker
        in sorted(PROJECT_CHECKERS.keys())]
    plugin_choices = [(x, x) for x in fs_plugins.gather()]
    expected = {
        'page': 'admin-projects',
        'form_choices': {
            'checkstyle': project_checker_choices,
            'fs_plugin': plugin_choices,
            'filetypes': filetypes,
            'fs_preset': FS_PRESETS,
            'source_language': language_choices,
            'defaults': {
                'source_language': english.id}}}
    for k, v in expected.items():
        assert response.context_data[k] == v
Exemple #12
0
def test_admin_view_projects(client, request_users, english):
    user = request_users["user"]

    client.login(
        username=user.username,
        password=request_users["password"])

    response = client.get(
        reverse(
            "pootle-admin-projects"))

    if not user.is_superuser:
        assert response.status_code == 403
        return
    languages = Language.objects.exclude(code='templates')
    language_choices = [(lang.id, unicode(lang)) for lang in languages]
    filetypes = []
    for info in formats.get().values():
        filetypes.append(
            [info["pk"], info["display_title"]])
    project_checker_choices = [
        (checker, checker)
        for checker
        in sorted(PROJECT_CHECKERS.keys())]
    plugin_choices = [(x, x) for x in fs_plugins.gather()]
    expected = {
        'page': 'admin-projects',
        'form_choices': {
            'checkstyle': project_checker_choices,
            'fs_plugin': plugin_choices,
            'filetypes': filetypes,
            'fs_preset': FS_PRESETS.values(),
            'source_language': language_choices,
            'defaults': {
                'source_language': english.id}}}
    for k, v in expected.items():
        assert response.context_data[k] == v
Exemple #13
0
def test_local_plugin_provider():
    assert fs_plugins.gather()["localfs"] == LocalFSPlugin
Exemple #14
0
    def add_arguments(self, parser):
        format_names = formats.get().keys()
        fs_plugins_names = fs_plugins.gather().keys()

        parser.add_argument(
            'code',
            action='store',
            help='Project code',
        )
        parser.add_argument(
            "--name",
            action="store",
            dest="name",
            help="Project name",
        )
        parser.add_argument(
            "--filetype",
            action="append",
            dest="filetypes",
            choices=format_names,
            default=[],
            help="File types: {0}. Default: po".format(
                 " | ".join(format_names)),
        )
        mapping_group = parser.add_mutually_exclusive_group(required=True)
        mapping_group.add_argument(
            "--preset-mapping",
            action="store",
            dest="preset_mapping",
            choices=FS_PRESETS.keys(),
            help="Filesystem layout preset: {0}".format(
                 " | ".join(FS_PRESETS.keys())),
        )
        mapping_group.add_argument(
            "--mapping",
            action="store",
            dest="mapping",
            help="Custom filesystem layout",
        )
        parser.add_argument(
            "--fs-type",
            action="store",
            dest="fs_type",
            default="localfs",
            choices=fs_plugins_names,
            help="Filesystem type: {0}".format(" | ".join(fs_plugins_names)),
        )
        parser.add_argument(
            "--fs-url",
            action="store",
            dest="fs_url",
            default="",
            help="Filesystem path or URL.",
        )
        parser.add_argument(
            "--source-language",
            action="store",
            dest="sourcelang",
            default="en",
            help=("Source language. Examples: [en | es | fr | ...]."
                  "Default: %(default)s"),
        )
        parser.add_argument(
            "--report-email",
            action="store",
            default="",
            dest="contact",
            help="Contact email for reports. Example: [email protected].",
        )
        parser.add_argument(
            "--disabled",
            action="store_true",
            dest="disabled",
            help="Does the project start disabled?",
        )
        parser.add_argument(
            "--checkstyle",
            action="store",
            dest="checkstyle",
            choices=PROJECT_CHECKERS.keys(),
            default="standard",
            help="Quality check styles. Example: {0}. Default: %(default)s"
                 .format(" | ".join(PROJECT_CHECKERS.keys())),
        )
Exemple #15
0
def test_local_plugin_provider():
    assert fs_plugins.gather()["localfs"] == LocalFSPlugin
Exemple #16
0
    def add_arguments(self, parser):
        format_names = formats.get().keys()
        fs_plugins_names = fs_plugins.gather().keys()

        parser.add_argument(
            'code',
            action='store',
            help='Project code',
        )
        parser.add_argument(
            "--name",
            action="store",
            dest="name",
            help="Project name",
        )
        parser.add_argument(
            "--filetype",
            action="append",
            dest="filetypes",
            choices=format_names,
            default=[],
            help="File types: {0}. Default: po".format(
                " | ".join(format_names)),
        )
        mapping_group = parser.add_mutually_exclusive_group(required=True)
        mapping_group.add_argument(
            "--preset-mapping",
            action="store",
            dest="preset_mapping",
            choices=FS_PRESETS.keys(),
            help="Filesystem layout preset: {0}".format(" | ".join(
                FS_PRESETS.keys())),
        )
        mapping_group.add_argument(
            "--mapping",
            action="store",
            dest="mapping",
            help="Custom filesystem layout",
        )
        parser.add_argument(
            "--fs-type",
            action="store",
            dest="fs_type",
            default="localfs",
            choices=fs_plugins_names,
            help="Filesystem type: {0}".format(" | ".join(fs_plugins_names)),
        )
        parser.add_argument(
            "--fs-url",
            action="store",
            dest="fs_url",
            default="",
            help="Filesystem path or URL.",
        )
        parser.add_argument(
            "--source-language",
            action="store",
            dest="sourcelang",
            default="en",
            help=("Source language. Examples: [en | es | fr | ...]."
                  "Default: %(default)s"),
        )
        parser.add_argument(
            "--report-email",
            action="store",
            default="",
            dest="contact",
            help="Contact email for reports. Example: [email protected].",
        )
        parser.add_argument(
            "--disabled",
            action="store_true",
            dest="disabled",
            help="Does the project start disabled?",
        )
        parser.add_argument(
            "--checkstyle",
            action="store",
            dest="checkstyle",
            choices=PROJECT_CHECKERS.keys(),
            default="standard",
            help="Quality check styles. Example: {0}. Default: %(default)s".
            format(" | ".join(PROJECT_CHECKERS.keys())),
        )