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>")
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>")
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 project0.config["pootle_fs.fs_type"] = "dummy2" form = ProjectFSAdminForm( project=project0, data=dict( translation_mapping=( "/some/path/to/<language_code>/<filename>.<ext>"))) assert form.is_valid() assert form.fs_path_validator is TranslationMappingValidator assert form.fields["translation_mapping"].initial == ( "/<language_code>/<filename>.<ext>") form.save() assert project0.config["pootle_fs.translation_mappings"] == dict( default="/some/path/to/<language_code>/<filename>.<ext>")