当前位置: 首页>>代码示例>>Python>>正文


Python factory.Faker方法代码示例

本文整理汇总了Python中factory.Faker方法的典型用法代码示例。如果您正苦于以下问题:Python factory.Faker方法的具体用法?Python factory.Faker怎么用?Python factory.Faker使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在factory的用法示例。


在下文中一共展示了factory.Faker方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import factory [as 别名]
# 或者: from factory import Faker [as 别名]
def __init__(self, signed=True, from_file=None, gecko_id=None, overwrite_data=None):
        super().__init__(signed=signed)

        if not gecko_id:
            gecko_id = f"{factory.Faker('md5').generate({})}@normandy.mozilla.org"

        if from_file:
            self._manifest = json.load(from_file)
        else:
            self._manifest = {
                "manifest_version": 2,
                "name": "normandy test addon",
                "version": "0.1",
                "description": "This is an add-on for us in Normandy's tests",
                "applications": {"gecko": {"id": gecko_id}},
            }

        if overwrite_data:
            self._manifest.update(overwrite_data)

        self.save_manifest() 
开发者ID:mozilla,项目名称:normandy,代码行数:23,代码来源:__init__.py

示例2: test_user_registration

# 需要导入模块: import factory [as 别名]
# 或者: from factory import Faker [as 别名]
def test_user_registration(self):
        """Ensure that user registration works properly."""
        EMAIL = Faker("email").generate()
        PASSWORD = fuzzy.FuzzyText(length=16)
        test_user_data = {
            "password1": PASSWORD,
            "password2": PASSWORD,
            "email": EMAIL,
            "email2": EMAIL,
        }

        # Verify that POSTing user data to the registration view
        # succeeds / returns the right HTTP status code.
        response = self.client.post(
            reverse("account_signup"), test_user_data)
        # Successful form submission will cause the HTTP status code
        # to be "302 Found", not "200 OK".
        self.assertEqual(response.status_code, 302)

        # Verify that a User has been successfully created.
        user_model = get_user_model()
        user_model.objects.get(email=EMAIL) 
开发者ID:pydata,项目名称:conf_site,代码行数:24,代码来源:test_registration.py

示例3: test_age

# 需要导入模块: import factory [as 别名]
# 或者: from factory import Faker [as 别名]
def test_age(self):
        profile = ProfileFactory.build(birth_date=None)
        self.assertRaises(TypeError, lambda: profile.age)
        profile = ProfileFactory.build(birth_date=Faker('date_this_year', before_today=True, after_today=False))
        self.assertEqual(profile.age, 0)
        profile = ProfileFactory.build(birth_date=Faker('date_this_year', before_today=False, after_today=True))
        self.assertEqual(profile.age, 0)
        profile = ProfileFactory.build(birth_date=Faker('date_between', start_date='-725d', end_date='-365d'))
        self.assertEqual(profile.age, 1)
        profile = ProfileFactory.build(birth_date=Faker('date_between', start_date='+365d', end_date='+725d'))
        self.assertEqual(profile.age, -1)
        profile = ProfileFactory.build(birth_date=Faker('date_between', start_date='-6935d', end_date='-6575d'))
        self.assertEqual(profile.age, 18)

        profile = ProfileFactory.build(birth_date=None, death_date=Faker('date_this_year'))
        self.assertRaises(TypeError, lambda: profile.age)
        profile = ProfileFactory.build(
            birth_date=Faker('date_between', start_date='-2000d', end_date='-1825d'),
            death_date=Faker('date_between', start_date='-360d', end_date='-185d'))
        self.assertEqual(profile.age, 4)
        profile = ProfileFactory.build(
            birth_date=Faker('date_between', start_date='-2000d', end_date='-1825d'),
            death_date=Faker('date_between', start_date='+370d', end_date='+545d'))
        self.assertEqual(profile.age, 6) 
开发者ID:tejoesperanto,项目名称:pasportaservo,代码行数:26,代码来源:test_profile_model.py

示例4: fill_excerpt

# 需要导入模块: import factory [as 别名]
# 或者: from factory import Faker [as 别名]
def fill_excerpt(self, create, extracted, **kwargs):
        """
        Add a plain text plugin for excerpt with a short random text
        """
        if create and extracted:
            placeholder = self.extended_object.placeholders.get(slot="excerpt")

            for language in self.extended_object.get_languages():
                text = factory.Faker(
                    "text",
                    max_nb_chars=random.randint(50, 100),  # nosec
                    locale=language,
                ).generate({})
                add_plugin(
                    language=language,
                    placeholder=placeholder,
                    plugin_type="PlainTextPlugin",
                    body=text,
                ) 
开发者ID:openfun,项目名称:richie,代码行数:21,代码来源:factories.py

示例5: extended_object

# 需要导入模块: import factory [as 别名]
# 或者: from factory import Faker [as 别名]
def extended_object(self):
        """
        Automatically create a related page with the title (or random title if None) in all the
        requested languages
        """
        title = getattr(self, "page_title", None)
        languages = getattr(self, "page_languages", None)
        if not title:
            # Create realistic titles in each language with faker
            languages = languages or [settings.LANGUAGE_CODE]
            title = {
                language: factory.Faker("catch_phrase", locale=language).generate({})
                for language in languages
            }

        return create_i18n_page(
            title,
            in_navigation=getattr(self, "page_in_navigation", False),
            languages=languages,
            parent=getattr(self, "page_parent", None),
            reverse_id=getattr(self, "page_reverse_id", None),
            template=getattr(self, "page_template", None),
        ) 
开发者ID:openfun,项目名称:richie,代码行数:25,代码来源:factories.py

示例6: SlackInstallation

# 需要导入模块: import factory [as 别名]
# 或者: from factory import Faker [as 别名]
def SlackInstallation(session):
    class _SlackInstallationFactory(factory.alchemy.SQLAlchemyModelFactory):
        class Meta:
            model = slack_installation_model
            sqlalchemy_session_persistence = "commit"
            sqlalchemy_session = session

        access_token = factory.Faker("uuid4")
        authorizing_user_id = "abc"

        bot_access_token = factory.Faker("uuid4")
        bot_user_id = "def"

        scope = "identity chat:message:write"
        workspace_id = "SC234sdfsde"
        workspace_name = "ChiPy"

        state = "active"

    return _SlackInstallationFactory 
开发者ID:busy-beaver-dev,项目名称:busy-beaver,代码行数:22,代码来源:slack.py

示例7: make_form_answer

# 需要导入模块: import factory [as 别名]
# 或者: from factory import Faker [as 别名]
def make_form_answer(cls, params=dict()):
        try:
            address = json.loads(params)
        except TypeError:
            if not params:
                params = {}
            return {
                'country': 'GB',
                'thoroughfare': factory.Faker('street_name').generate(params),
                'premise': factory.Faker('building_number').generate(params),
                'locality': {
                    'localityname': factory.Faker('city').generate(params),
                    'administrativearea': factory.Faker('city').generate(params),
                    'postal_code': 'SW1 4AQ',
                }
            }

        address['locality'] = {
            'localityname': address.pop('localityname'),
            'administrativearea': address.pop('administrativearea'),
            'postalcode': address.pop('postalcode'),
        }
        return address 
开发者ID:OpenTechFund,项目名称:hypha,代码行数:25,代码来源:blocks.py

示例8: value

# 需要导入模块: import factory [as 别名]
# 或者: from factory import Faker [as 别名]
def value(self):
        if (
            self.question.type == models.Question.TYPE_MULTIPLE_CHOICE
            or self.question.type == models.Question.TYPE_DYNAMIC_MULTIPLE_CHOICE
        ):
            return [Faker("name").generate({}), Faker("name").generate({})]
        elif self.question.type == models.Question.TYPE_FLOAT:
            return Faker("pyfloat").generate({})
        elif self.question.type == models.Question.TYPE_INTEGER:
            return Faker("pyint").generate({})
        elif self.question.type not in [
            models.Question.TYPE_TABLE,
            models.Question.TYPE_FILE,
            models.Question.TYPE_DATE,
        ]:
            return Faker("name").generate({})

        return None 
开发者ID:projectcaluma,项目名称:caluma,代码行数:20,代码来源:factories.py

示例9: password

# 需要导入模块: import factory [as 别名]
# 或者: from factory import Faker [as 别名]
def password(self, create: bool, extracted: Sequence[Any], **kwargs):
        password = Faker(
            "password",
            length=42,
            special_chars=True,
            digits=True,
            upper_case=True,
            lower_case=True,
        ).generate(
            extra_kwargs={}
        )
        self.set_password(password) 
开发者ID:ecds,项目名称:readux,代码行数:14,代码来源:factories.py

示例10: password

# 需要导入模块: import factory [as 别名]
# 或者: from factory import Faker [as 别名]
def password(self, create: bool, extracted: Sequence[Any], **kwargs):
        password = (
            extracted
            if extracted
            else Faker(
                "password",
                length=42,
                special_chars=True,
                digits=True,
                upper_case=True,
                lower_case=True,
            ).generate(extra_kwargs={})
        )
        self.set_password(password) 
开发者ID:LucianU,项目名称:bud,代码行数:16,代码来源:factories.py

示例11: password

# 需要导入模块: import factory [as 别名]
# 或者: from factory import Faker [as 别名]
def password(self, create: bool, extracted: Sequence[Any], **kwargs):
        password = Faker(
            "password",
            length=42,
            special_chars=True,
            digits=True,
            upper_case=True,
            lower_case=True,
        ).generate(extra_kwargs={})
        self.set_password(password) 
开发者ID:realpython,项目名称:django_cookiecutter_docker,代码行数:12,代码来源:factories.py

示例12: test_has_more_flag

# 需要导入模块: import factory [as 别名]
# 或者: from factory import Faker [as 别名]
def test_has_more_flag(self):
        # A normal blog post with introduction and content.
        PostFactory()
        # A blog post without an introduction.
        PostFactory(content=Faker('text').generate({}))

        qs = Post.objects.get_queryset().order_by('id')
        self.assertEqual(len(qs), 2)
        for i, flag in enumerate((True, False)):
            with self.subTest(has_more=flag):
                self.assertEqual(qs[i].has_more, flag) 
开发者ID:tejoesperanto,项目名称:pasportaservo,代码行数:13,代码来源:test_blog_models.py

示例13: test_str

# 需要导入模块: import factory [as 别名]
# 或者: from factory import Faker [as 别名]
def test_str(self):
        loc = WhereaboutsFactory.build(name="Córdoba", state="", country=Country('AR'))
        self.assertEquals(str(loc), "Location of Córdoba (Argentina)")
        loc = WhereaboutsFactory.build(name="Córdoba", state="Córdoba", country=Country('AR'))
        self.assertEquals(str(loc), "Location of Córdoba (Córdoba, Argentina)")
        loc = WhereaboutsFactory.build(
            name=Faker('city', locale='el_GR'), state="", country=Country('GR'))
        self.assertEquals(str(loc), "Location of {} ({})".format(loc.name, loc.country.name))
        loc = WhereaboutsFactory.build(
            name=Faker('city', locale='el_GR'), state=Faker('region', locale='el_GR'), country=Country('GR'))
        self.assertEquals(str(loc), "Location of {} ({}, {})".format(loc.name, loc.state, loc.country.name)) 
开发者ID:tejoesperanto,项目名称:pasportaservo,代码行数:13,代码来源:test_whereabouts_model.py

示例14: test_str

# 需要导入模块: import factory [as 别名]
# 或者: from factory import Faker [as 别名]
def test_str(self):
        # A place in a known city is expected to be "City-name, Country-name".
        place = PlaceFactory.build(city="Córdoba", country=Country('AR'))
        self.assertEqual(str(place), "Córdoba, Argentino")

        # A place in an unknown city is expected to be "Country-name".
        place = PlaceFactory.build(city="", country=Country('UY'))
        self.assertEqual(str(place), "Urugvajo")

        # A place in a known city is expected to be "City-name, Country-name".
        place = PlaceFactory.build(city=Faker('city'), country=Country('CL'))
        self.assertEqual(str(place), '{}, {}'.format(place.city, place.country.name)) 
开发者ID:tejoesperanto,项目名称:pasportaservo,代码行数:14,代码来源:test_place_model.py

示例15: state_province

# 需要导入模块: import factory [as 别名]
# 或者: from factory import Faker [as 别名]
def state_province(self):
        if self.country in COUNTRIES_WITH_MANDATORY_REGION or random() > 0.85:
            return Faker('state').generate({})
        else:
            return "" 
开发者ID:tejoesperanto,项目名称:pasportaservo,代码行数:7,代码来源:factories.py


注:本文中的factory.Faker方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。