本文整理汇总了Python中pontoon.base.tests.EntityFactory类的典型用法代码示例。如果您正苦于以下问题:Python EntityFactory类的具体用法?Python EntityFactory怎么用?Python EntityFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EntityFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
self.locale = LocaleFactory.create(cldr_plurals="0,1")
self.project = ProjectFactory.create(locales=[self.locale])
self.main_resource = ResourceFactory.create(project=self.project, path="main.lang")
self.other_resource = ResourceFactory.create(project=self.project, path="other.lang")
self.main_entity = EntityFactory.create(
resource=self.main_resource,
string="Source String",
string_plural="Plural Source String",
key="Source String",
)
self.other_entity = EntityFactory.create(
resource=self.other_resource,
string="Other Source String",
key="Key" + KEY_SEPARATOR + "Other Source String",
)
self.main_translation = TranslationFactory.create(
entity=self.main_entity, locale=self.locale, plural_form=0, string="Translated String"
)
self.main_translation_plural = TranslationFactory.create(
entity=self.main_entity, locale=self.locale, plural_form=1, string="Translated Plural String"
)
self.other_translation = TranslationFactory.create(
entity=self.other_entity, locale=self.locale, string="Other Translated String"
)
self.subpage = SubpageFactory.create(project=self.project, name="Subpage", resources=[self.main_resource])
示例2: test_locales_parts_stats_pages_tied_to_resources
def test_locales_parts_stats_pages_tied_to_resources(self):
"""
Return subpage name and stats for locales resources are available for.
"""
resource_other = ResourceFactory.create(
project=self.project,
path='/other/path.po'
)
EntityFactory.create(resource=resource_other)
StatsFactory.create(resource=resource_other, locale=self.locale)
StatsFactory.create(resource=resource_other, locale=self.locale_other)
SubpageFactory.create(
project=self.project,
name='Subpage',
resources=[self.resource]
)
SubpageFactory.create(
project=self.project,
name='Other Subpage',
resources=[resource_other]
)
project_details = self._fetch_locales_parts_stats()
details = project_details.get(self.locale.code)
details_other = project_details.get(self.locale_other.code)
assert_equal(details[0]['resource__path'], 'Other Subpage')
assert_equal(details[0]['translated_count'], 0)
assert_equal(details[1]['resource__path'], 'Subpage')
assert_equal(details[1]['translated_count'], 0)
assert_equal(details_other[0]['resource__path'], 'Other Subpage')
assert_equal(details_other[0]['translated_count'], 0)
示例3: create_db_entities_translations
def create_db_entities_translations(self):
"""
Create entities and translations in the database for strings
from the fake checkout.
"""
self.main_db_entity = EntityFactory.create(
resource=self.main_db_resource,
string='Source String',
key='Source String',
obsolete=False
)
self.other_db_entity = EntityFactory.create(
resource=self.other_db_resource,
string='Other Source String',
key='Other Source String',
obsolete=False
)
self.main_db_translation = TranslationFactory.create(
entity=self.main_db_entity,
plural_form=None,
locale=self.translated_locale,
string='Translated String',
date=aware_datetime(1970, 1, 1),
approved=True,
extra={'tags': []}
)
示例4: test_parts_stats_pages_tied_to_resources
def test_parts_stats_pages_tied_to_resources(self):
"""
Return subpage name and stats for locales resources are available for.
"""
resource_other = ResourceFactory.create(
project=self.project,
path='/other/path.po'
)
EntityFactory.create(resource=resource_other)
TranslatedResourceFactory.create(resource=resource_other, locale=self.locale)
TranslatedResourceFactory.create(resource=resource_other, locale=self.locale_other)
SubpageFactory.create(
project=self.project,
name='Subpage',
resources=[self.resource]
)
SubpageFactory.create(
project=self.project,
name='Other Subpage',
resources=[resource_other]
)
details = self.locale.parts_stats(self.project)
details_other = self.locale_other.parts_stats(self.project)
assert_equal(details[0]['title'], 'Other Subpage')
assert_equal(details[0]['translated_strings'], 0)
assert_equal(details[1]['title'], 'Subpage')
assert_equal(details[1]['translated_strings'], 0)
assert_equal(details_other[0]['title'], 'Other Subpage')
assert_equal(details_other[0]['translated_strings'], 0)
示例5: test_for_project_locale_order
def test_for_project_locale_order(self):
"""
Return entities in correct order.
"""
entity_second = EntityFactory.create(order=1, resource=self.main_resource, string="Second String")
entity_first = EntityFactory.create(order=0, resource=self.main_resource, string="First String")
entities = Entity.for_project_locale(self.project, self.locale)
assert_equal(entities[2]["original"], "First String")
assert_equal(entities[3]["original"], "Second String")
示例6: setUp
def setUp(self):
self.locale, self.locale_other = LocaleFactory.create_batch(2)
self.project = ProjectFactory.create(
locales=[self.locale, self.locale_other]
)
self.resource = ResourceFactory.create(
project=self.project,
path='/main/path.po'
)
EntityFactory.create(resource=self.resource)
StatsFactory.create(resource=self.resource, locale=self.locale)
示例7: test_for_project_locale_filter
def test_for_project_locale_filter(self):
"""
Evaluate entities filtering by locale, project, obsolete.
"""
other_locale = LocaleFactory.create()
other_project = ProjectFactory.create(locales=[self.locale, other_locale])
# Obsolete_entity
EntityFactory.create(obsolete=True, resource=self.main_resource, string="Obsolete String")
entities = Entity.for_project_locale(self.project, other_locale)
assert_equal(len(entities), 0)
entities = Entity.for_project_locale(other_project, self.locale)
assert_equal(len(entities), 0)
entities = Entity.for_project_locale(self.project, self.locale)
assert_equal(len(entities), 2)
示例8: setUp
def setUp(self):
self.locale = LocaleFactory.create(
cldr_plurals="0,1"
)
self.project = ProjectFactory.create(
locales=[self.locale]
)
self.main_resource = ResourceFactory.create(
project=self.project,
path='main.lang'
)
self.other_resource = ResourceFactory.create(
project=self.project,
path='other.lang'
)
self.main_entity = EntityFactory.create(
resource=self.main_resource,
string='Source String',
string_plural='Plural Source String',
key='Source String'
)
self.other_entity = EntityFactory.create(
resource=self.other_resource,
string='Other Source String',
key='Key' + KEY_SEPARATOR + 'Other Source String'
)
self.main_translation = TranslationFactory.create(
entity=self.main_entity,
locale=self.locale,
plural_form=0,
string='Translated String'
)
self.main_translation_plural = TranslationFactory.create(
entity=self.main_entity,
locale=self.locale,
plural_form=1,
string='Translated Plural String'
)
self.other_translation = TranslationFactory.create(
entity=self.other_entity,
locale=self.locale,
string='Other Translated String'
)
self.subpage = SubpageFactory.create(
project=self.project,
name='Subpage',
resources=[self.main_resource]
)
示例9: setUp
def setUp(self):
self.resource = ResourceFactory.create()
self.locale = LocaleFactory.create()
ProjectLocale.objects.create(project=self.resource.project, locale=self.locale)
TranslatedResource.objects.create(resource=self.resource, locale=self.locale)
self.entities = EntityFactory.create_batch(3, resource=self.resource)
self.entities_pks = [e.pk for e in self.entities]
示例10: test_parts_stats_no_page_multiple_resources
def test_parts_stats_no_page_multiple_resources(self):
"""
Return resource paths and stats for locales resources are available for.
"""
resource_other = ResourceFactory.create(project=self.project, path="/other/path.po")
EntityFactory.create(resource=resource_other)
StatsFactory.create(resource=resource_other, locale=self.locale)
StatsFactory.create(resource=resource_other, locale=self.locale_other)
details = self.locale.parts_stats(self.project)
details_other = self.locale_other.parts_stats(self.project)
assert_equal(details[0]["resource__path"], "/main/path.po")
assert_equal(details[0]["translated_count"], 0)
assert_equal(details[1]["resource__path"], "/other/path.po")
assert_equal(details[1]["translated_count"], 0)
assert_equal(len(details_other), 1)
assert_equal(details_other[0]["resource__path"], "/other/path.po")
assert_equal(details_other[0]["translated_count"], 0)
示例11: test_for_project_locale_order
def test_for_project_locale_order(self):
"""
Return entities in correct order.
"""
# First entity
EntityFactory.create(
order=1,
resource=self.main_resource,
string='Second String'
)
# Second entity
EntityFactory.create(
order=0,
resource=self.main_resource,
string='First String'
)
entities = Entity.for_project_locale(self.project, self.locale)
assert_equal(entities[2]['original'], 'First String')
assert_equal(entities[3]['original'], 'Second String')
示例12: test_parts_stats_pages_tied_to_resources
def test_parts_stats_pages_tied_to_resources(self):
"""
Return subpage name and stats for locales resources are available for.
"""
resource_other = ResourceFactory.create(project=self.project, path="/other/path.po")
EntityFactory.create(resource=resource_other)
StatsFactory.create(resource=resource_other, locale=self.locale)
StatsFactory.create(resource=resource_other, locale=self.locale_other)
SubpageFactory.create(project=self.project, name="Subpage", resources=[self.resource])
SubpageFactory.create(project=self.project, name="Other Subpage", resources=[resource_other])
details = self.locale.parts_stats(self.project)
details_other = self.locale_other.parts_stats(self.project)
assert_equal(details[0]["resource__path"], "Other Subpage")
assert_equal(details[0]["translated_count"], 0)
assert_equal(details[1]["resource__path"], "Subpage")
assert_equal(details[1]["translated_count"], 0)
assert_equal(details_other[0]["resource__path"], "Other Subpage")
assert_equal(details_other[0]["translated_count"], 0)
示例13: test_parts_stats_no_page_multiple_resources
def test_parts_stats_no_page_multiple_resources(self):
"""
Return resource paths and stats for locales resources are available for.
"""
resource_other = ResourceFactory.create(
project=self.project,
path='/other/path.po'
)
EntityFactory.create(resource=resource_other)
TranslatedResourceFactory.create(resource=resource_other, locale=self.locale)
TranslatedResourceFactory.create(resource=resource_other, locale=self.locale_other)
details = self.locale.parts_stats(self.project)
details_other = self.locale_other.parts_stats(self.project)
assert_equal(details[0]['title'], '/main/path.po')
assert_equal(details[0]['translated_strings'], 0)
assert_equal(details[1]['title'], '/other/path.po')
assert_equal(details[1]['translated_strings'], 0)
assert_equal(len(details_other), 1)
assert_equal(details_other[0]['title'], '/other/path.po')
assert_equal(details_other[0]['translated_strings'], 0)
示例14: test_locales_parts_stats_no_page_multiple_resources
def test_locales_parts_stats_no_page_multiple_resources(self):
"""
Return resource paths and stats for locales resources are available for.
"""
resource_other = ResourceFactory.create(
project=self.project,
path='/other/path.po'
)
EntityFactory.create(resource=resource_other)
StatsFactory.create(resource=resource_other, locale=self.locale)
StatsFactory.create(resource=resource_other, locale=self.locale_other)
project_details = self._fetch_locales_parts_stats()
details = project_details.get(self.locale.code)
details_other = project_details.get(self.locale_other.code)
assert_equal(details[0]['resource__path'], '/main/path.po')
assert_equal(details[0]['translated_count'], 0)
assert_equal(details[1]['resource__path'], '/other/path.po')
assert_equal(details[1]['translated_count'], 0)
assert_equal(len(details_other), 1)
assert_equal(details_other[0]['resource__path'], '/other/path.po')
assert_equal(details_other[0]['translated_count'], 0)
示例15: setUp
def setUp(self):
# Create a list of instances in order to filter them.
EntityFactory.create_batch(10)