def test_project_add_locale(client_superuser): locale_kl = LocaleFactory.create(code="kl", name="Klingon") locale_gs = LocaleFactory.create(code="gs", name="Geonosian") project = ProjectFactory.create( data_source=Project.DataSource.DATABASE, locales=[locale_kl], repositories=[], ) _create_or_update_translated_resources(project, [locale_kl]) url = reverse("pontoon.admin.project", args=(project.slug,)) # Boring data creation for FormSets. Django is painful with that, # or I don't know how to handle that more gracefully. form = ProjectForm(instance=project) form_data = dict(form.initial) del form_data["width"] del form_data["deadline"] del form_data["contact"] form_data.update( { "subpage_set-INITIAL_FORMS": "0", "subpage_set-TOTAL_FORMS": "1", "subpage_set-MIN_NUM_FORMS": "0", "subpage_set-MAX_NUM_FORMS": "1000", "externalresource_set-TOTAL_FORMS": "1", "externalresource_set-MAX_NUM_FORMS": "1000", "externalresource_set-MIN_NUM_FORMS": "0", "externalresource_set-INITIAL_FORMS": "0", "tag_set-TOTAL_FORMS": "1", "tag_set-INITIAL_FORMS": "0", "tag_set-MAX_NUM_FORMS": "1000", "tag_set-MIN_NUM_FORMS": "0", "repositories-INITIAL_FORMS": "0", "repositories-MIN_NUM_FORMS": "0", "repositories-MAX_NUM_FORMS": "1000", "repositories-TOTAL_FORMS": "0", # These are the values that actually matter. "pk": project.pk, "locales": [locale_kl.id, locale_gs.id], "configuration_file": "", } ) response = client_superuser.post(url, form_data) assert response.status_code == 200 assert b". Error." not in response.content # Verify we have the right ProjectLocale objects. pl = ProjectLocale.objects.filter(project=project) assert len(pl) == 2 # Verify that TranslatedResource objects have been created. resource = Resource.objects.get(project=project, path="database") tr = TranslatedResource.objects.filter(resource=resource) assert len(tr) == 2
def test_project_add_locale(client_superuser): locale_kl = LocaleFactory.create(code='kl', name='Klingon') locale_gs = LocaleFactory.create(code='gs', name='Geonosian') project = ProjectFactory.create( data_source='database', locales=[locale_kl], repositories=[], ) _create_or_update_translated_resources(project, [locale_kl]) url = reverse('pontoon.admin.project', args=(project.slug, )) # Boring data creation for FormSets. Django is painful with that, # or I don't know how to handle that more gracefully. form = ProjectForm(instance=project) form_data = dict(form.initial) del form_data['width'] del form_data['deadline'] del form_data['contact'] form_data.update({ 'subpage_set-INITIAL_FORMS': '0', 'subpage_set-TOTAL_FORMS': '1', 'subpage_set-MIN_NUM_FORMS': '0', 'subpage_set-MAX_NUM_FORMS': '1000', 'externalresource_set-TOTAL_FORMS': '1', 'externalresource_set-MAX_NUM_FORMS': '1000', 'externalresource_set-MIN_NUM_FORMS': '0', 'externalresource_set-INITIAL_FORMS': '0', 'tag_set-TOTAL_FORMS': '1', 'tag_set-INITIAL_FORMS': '0', 'tag_set-MAX_NUM_FORMS': '1000', 'tag_set-MIN_NUM_FORMS': '0', 'repositories-INITIAL_FORMS': '0', 'repositories-MIN_NUM_FORMS': '0', 'repositories-MAX_NUM_FORMS': '1000', 'repositories-TOTAL_FORMS': '0', # These are the values that actually matter. 'pk': project.pk, 'locales': [locale_kl.id, locale_gs.id], }) response = client_superuser.post(url, form_data) assert response.status_code == 200 assert b'. Error.' not in response.content # Verify we have the right ProjectLocale objects. pl = ProjectLocale.objects.filter(project=project) assert len(pl) == 2 # Verify that TranslatedResource objects have been created. resource = Resource.objects.get(project=project, path='database') tr = TranslatedResource.objects.filter(resource=resource) assert len(tr) == 2
def test_project_add_locale(client_superuser): locale_kl = LocaleFactory.create(code='kl', name='Klingon') locale_gs = LocaleFactory.create(code='gs', name='Geonosian') project = ProjectFactory.create( data_source='database', locales=[locale_kl], repositories=[], ) _create_or_update_translated_resources(project, [locale_kl]) url = reverse('pontoon.admin.project', args=(project.slug,)) # Boring data creation for FormSets. Django is painful with that, # or I don't know how to handle that more gracefully. form = ProjectForm(instance=project) form_data = dict(form.initial) del form_data['width'] del form_data['deadline'] del form_data['contact'] form_data.update({ 'subpage_set-INITIAL_FORMS': '0', 'subpage_set-TOTAL_FORMS': '1', 'subpage_set-MIN_NUM_FORMS': '0', 'subpage_set-MAX_NUM_FORMS': '1000', 'externalresource_set-TOTAL_FORMS': '1', 'externalresource_set-MAX_NUM_FORMS': '1000', 'externalresource_set-MIN_NUM_FORMS': '0', 'externalresource_set-INITIAL_FORMS': '0', 'tag_set-TOTAL_FORMS': '1', 'tag_set-INITIAL_FORMS': '0', 'tag_set-MAX_NUM_FORMS': '1000', 'tag_set-MIN_NUM_FORMS': '0', 'repositories-INITIAL_FORMS': '0', 'repositories-MIN_NUM_FORMS': '0', 'repositories-MAX_NUM_FORMS': '1000', 'repositories-TOTAL_FORMS': '0', # These are the values that actually matter. 'pk': project.pk, 'locales': [locale_kl.id, locale_gs.id], }) response = client_superuser.post(url, form_data) assert response.status_code == 200 assert '. Error.' not in response.content # Verify we have the right ProjectLocale objects. pl = ProjectLocale.objects.filter(project=project) assert len(pl) == 2 # Verify that TranslatedResource objects have been created. resource = Resource.objects.get(project=project, path='database') tr = TranslatedResource.objects.filter(resource=resource) assert len(tr) == 2
def test_manage_project_strings_translated_resource(client_superuser): """Test that adding new strings to a project enables translation of that project on all enabled locales. """ locales = [ LocaleFactory.create(code='kl', name='Klingon'), LocaleFactory.create(code='gs', name='Geonosian'), ] project = ProjectFactory.create( data_source='database', locales=locales, repositories=[] ) locales_count = len(locales) _create_or_update_translated_resources(project, locales) url = reverse('pontoon.admin.project.strings', args=(project.slug,)) new_strings = """ Morty, do you know what "Wubba lubba dub dub" means? Oh that's just Rick's stupid non-sense catch phrase. It's not. In my people's tongue, it means "I am in great pain, please help me". """ strings_count = 4 response = client_superuser.post(url, {'new_strings': new_strings}) assert response.status_code == 200 # Verify no strings have been created as entities. entities = list(Entity.objects.filter(resource__project=project)) assert len(entities) == strings_count # Verify the resource has the right stats. resources = Resource.objects.filter(project=project) assert len(resources) == 1 resource = resources[0] assert resource.total_strings == strings_count # Verify the correct TranslatedResource objects have been created. translated_resources = TranslatedResource.objects.filter(resource__project=project) assert len(translated_resources) == locales_count # Verify stats have been correctly updated on locale, project and resource. for tr in translated_resources: assert tr.total_strings == strings_count project = Project.objects.get(id=project.id) assert project.total_strings == strings_count * locales_count for l in locales: locale = Locale.objects.get(id=l.id) assert locale.total_strings == strings_count
def test_manage_project_strings_translated_resource(client_superuser): """Test that adding new strings to a project enables translation of that project on all enabled locales. """ locales = [ LocaleFactory.create(code='kl', name='Klingon'), LocaleFactory.create(code='gs', name='Geonosian'), ] project = ProjectFactory.create(data_source='database', locales=locales, repositories=[]) locales_count = len(locales) _create_or_update_translated_resources(project, locales) url = reverse('pontoon.admin.project.strings', args=(project.slug, )) new_strings = """ Morty, do you know what "Wubba lubba dub dub" means? Oh that's just Rick's stupid non-sense catch phrase. It's not. In my people's tongue, it means "I am in great pain, please help me". """ strings_count = 4 response = client_superuser.post(url, {'new_strings': new_strings}) assert response.status_code == 200 # Verify no strings have been created as entities. entities = list(Entity.objects.filter(resource__project=project)) assert len(entities) == strings_count # Verify the resource has the right stats. resources = Resource.objects.filter(project=project) assert len(resources) == 1 resource = resources[0] assert resource.total_strings == strings_count # Verify the correct TranslatedResource objects have been created. translated_resources = TranslatedResource.objects.filter( resource__project=project) assert len(translated_resources) == locales_count # Verify stats have been correctly updated on locale, project and resource. for tr in translated_resources: assert tr.total_strings == strings_count project = Project.objects.get(id=project.id) assert project.total_strings == strings_count * locales_count for l in locales: locale = Locale.objects.get(id=l.id) assert locale.total_strings == strings_count
def test_project_visible_for_users( users_permissions_group, user_a, public_project, private_project ): def get_permissions_group(obj, permissions_group): def _getattr(obj, permissions_group): return getattr(obj, permissions_group) return functools.reduce(_getattr, [obj] + permissions_group.split(".")) projects = Project.objects.visible_for(user_a).filter( pk__in=[public_project.pk, private_project.pk] ) assert list(projects) == [ public_project, ] # Make user_a a project translator private_project_locale = ProjectLocaleFactory.create( project=private_project, locale=LocaleFactory.create() ) get_permissions_group(private_project_locale, users_permissions_group).user_set.add( user_a ) projects = Project.objects.visible_for(user_a).filter( pk__in=[public_project.pk, private_project.pk] ) assert list(projects) == [public_project]
def locale_c(): translators_group = GroupFactory.create(name="locale translators", ) managers_group = GroupFactory.create(name="locale managers", ) return LocaleFactory.create( code="nv", name="Na'vi", translators_group=translators_group, managers_group=managers_group, )
def locale_c(): translators_group = GroupFactory.create( name='locale translators', ) managers_group = GroupFactory.create( name='locale managers', ) return LocaleFactory.create( code="nv", name="Na'vi", translators_group=translators_group, managers_group=managers_group, )
def locale_c(): return LocaleFactory(code="nv", name="Na'vi",)
def test_manage_project_strings_download_csv(client_superuser): locale_kl = LocaleFactory.create(code='kl', name='Klingon') locale_gs = LocaleFactory.create(code='gs', name='Geonosian') project = ProjectFactory.create(data_source='database', locales=[locale_kl, locale_gs], repositories=[]) url = reverse('pontoon.admin.project.strings', args=(project.slug, )) new_strings = """ And on the pedestal these words appear: 'My name is Ozymandias, king of kings: Look on my works, ye Mighty, and despair!' """ response = client_superuser.post(url, {'new_strings': new_strings}) assert response.status_code == 200 # Test downloading the data. response = client_superuser.get(url, {'format': 'csv'}) assert response.status_code == 200 assert response._headers['content-type'] == ('Content-Type', 'text/csv') # Verify the original content is here. assert b'pedestal' in response.content assert b'Ozymandias' in response.content assert b'Mighty' in response.content # Verify we have the locale columns. assert b'kl' in response.content assert b'gs' in response.content # Now add some translations. entity = Entity.objects.filter( string='And on the pedestal these words appear:')[0] TranslationFactory.create( string='Et sur le piédestal il y a ces mots :', entity=entity, locale=locale_kl, approved=True, ) TranslationFactory.create( string='Und auf dem Sockel steht die Schrift: ‚Mein Name', entity=entity, locale=locale_gs, approved=True, ) entity = Entity.objects.filter( string='\'My name is Ozymandias, king of kings:')[0] TranslationFactory.create( string='"Mon nom est Ozymandias, Roi des Rois.', entity=entity, locale=locale_kl, approved=True, ) TranslationFactory.create( string='Ist Osymandias, aller Kön’ge König: –', entity=entity, locale=locale_gs, approved=True, ) entity = Entity.objects.filter( string='Look on my works, ye Mighty, and despair!\'')[0] TranslationFactory.create( string='Voyez mon œuvre, vous puissants, et désespérez !"', entity=entity, locale=locale_kl, approved=True, ) TranslationFactory.create( string='Seht meine Werke, Mächt’ge, und erbebt!‘', entity=entity, locale=locale_gs, approved=True, ) response = client_superuser.get(url, {'format': 'csv'}) # Verify the translated content is here. assert b'pedestal' in response.content assert 'piédestal'.encode('utf-8') in response.content assert b'Sockel' in response.content assert b'Mighty' in response.content assert b'puissants' in response.content assert 'Mächt’ge'.encode('utf-8') in response.content
def test_manage_project_strings_download_csv(client_superuser): locale_kl = LocaleFactory.create(code="kl", name="Klingon") locale_gs = LocaleFactory.create(code="gs", name="Geonosian") project = ProjectFactory.create(data_source="database", locales=[locale_kl, locale_gs], repositories=[]) url = reverse("pontoon.admin.project.strings", args=(project.slug, )) new_strings = """ And on the pedestal these words appear: 'My name is Ozymandias, king of kings: Look on my works, ye Mighty, and despair!' """ response = client_superuser.post(url, {"new_strings": new_strings}) assert response.status_code == 200 # Test downloading the data. response = client_superuser.get(url, {"format": "csv"}) assert response.status_code == 200 assert response._headers["content-type"] == ("Content-Type", "text/csv") # Verify the original content is here. assert b"pedestal" in response.content assert b"Ozymandias" in response.content assert b"Mighty" in response.content # Verify we have the locale columns. assert b"kl" in response.content assert b"gs" in response.content # Now add some translations. entity = Entity.objects.filter( string="And on the pedestal these words appear:")[0] TranslationFactory.create( string="Et sur le piédestal il y a ces mots :", entity=entity, locale=locale_kl, approved=True, ) TranslationFactory.create( string="Und auf dem Sockel steht die Schrift: ‚Mein Name", entity=entity, locale=locale_gs, approved=True, ) entity = Entity.objects.filter( string="'My name is Ozymandias, king of kings:")[0] TranslationFactory.create( string='"Mon nom est Ozymandias, Roi des Rois.', entity=entity, locale=locale_kl, approved=True, ) TranslationFactory.create( string="Ist Osymandias, aller Kön’ge König: –", entity=entity, locale=locale_gs, approved=True, ) entity = Entity.objects.filter( string="Look on my works, ye Mighty, and despair!'")[0] TranslationFactory.create( string='Voyez mon œuvre, vous puissants, et désespérez !"', entity=entity, locale=locale_kl, approved=True, ) TranslationFactory.create( string="Seht meine Werke, Mächt’ge, und erbebt!‘", entity=entity, locale=locale_gs, approved=True, ) response = client_superuser.get(url, {"format": "csv"}) # Verify the translated content is here. assert b"pedestal" in response.content assert "piédestal".encode("utf-8") in response.content assert b"Sockel" in response.content assert b"Mighty" in response.content assert b"puissants" in response.content assert "Mächt’ge".encode("utf-8") in response.content
def test_manage_project_strings_download_csv(client_superuser): locale_kl = LocaleFactory.create(code='kl', name='Klingon') locale_gs = LocaleFactory.create(code='gs', name='Geonosian') project = ProjectFactory.create( data_source='database', locales=[locale_kl, locale_gs], repositories=[] ) url = reverse('pontoon.admin.project.strings', args=(project.slug,)) new_strings = """ And on the pedestal these words appear: 'My name is Ozymandias, king of kings: Look on my works, ye Mighty, and despair!' """ response = client_superuser.post(url, {'new_strings': new_strings}) assert response.status_code == 200 # Test downloading the data. response = client_superuser.get(url, {'format': 'csv'}) assert response.status_code == 200 assert response._headers['content-type'] == ('Content-Type', 'text/csv') # Verify the original content is here. assert 'pedestal' in response.content assert 'Ozymandias' in response.content assert 'Mighty' in response.content # Verify we have the locale columns. assert 'kl' in response.content assert 'gs' in response.content # Now add some translations. entity = Entity.objects.filter(string='And on the pedestal these words appear:')[0] TranslationFactory.create( string='Et sur le piédestal il y a ces mots :', entity=entity, locale=locale_kl, approved=True, ) TranslationFactory.create( string='Und auf dem Sockel steht die Schrift: ‚Mein Name', entity=entity, locale=locale_gs, approved=True, ) entity = Entity.objects.filter(string='\'My name is Ozymandias, king of kings:')[0] TranslationFactory.create( string='"Mon nom est Ozymandias, Roi des Rois.', entity=entity, locale=locale_kl, approved=True, ) TranslationFactory.create( string='Ist Osymandias, aller Kön’ge König: –', entity=entity, locale=locale_gs, approved=True, ) entity = Entity.objects.filter(string='Look on my works, ye Mighty, and despair!\'')[0] TranslationFactory.create( string='Voyez mon œuvre, vous puissants, et désespérez !"', entity=entity, locale=locale_kl, approved=True, ) TranslationFactory.create( string='Seht meine Werke, Mächt’ge, und erbebt!‘', entity=entity, locale=locale_gs, approved=True, ) response = client_superuser.get(url, {'format': 'csv'}) # Verify the translated content is here. assert 'pedestal' in response.content assert 'piédestal' in response.content assert 'Sockel' in response.content assert 'Mighty' in response.content assert 'puissants' in response.content assert 'Mächt’ge' in response.content