當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。