python类Faker()的实例源码

factories.py 文件源码 项目:postix 作者: c3cashdesk 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def product_factory(items=False):
    fake = Faker('en-US')
    p = Product.objects.create(name=fake.catch_phrase(),
                               price=random.choice([50 * i for i in range(5)]),
                               tax_rate=19)
    if items:
        ProductItem.objects.create(item=item_factory(), product=p,
                                   amount=1)
    return p
test_device_server.py 文件源码 项目:Complete-Bunq-API-Python-Wrapper 作者: PJUllrich 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def setUp(self):
        super().setUp(DeviceServer)
        self.faker = Faker()
faker.py 文件源码 项目:djipsum 作者: agusmakmun 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def fake_binary(self):
        """
        Return random binary format.
        Faker Factory also provide about this binary.

        Example:
            b"\x00\x01\x02\x03\x04\x05\x06\x07"
            b"\x0b\x0c\x0e\x0f"

        1. from Djipsum
            faker.fake_binary()
        2. from Faker Factory
            faker.fake.binary(length=10)
        """
        return self.djipsum_fields().randomBinaryField()
faker.py 文件源码 项目:djipsum 作者: agusmakmun 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def fake_null_boolean(self):
        """
        Faker Factory also provide about this null boolean.

        Example:
            None, True, False

        1. from Djipsum
            faker.fake_null_boolean()
        2. from Faker Factory
            faker.fake.null_boolean()
        """
        return self.djipsum_fields().randomize([None, True, False])
faker.py 文件源码 项目:djipsum 作者: agusmakmun 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def fake_file(self):
        """
        Return string name of file.
        Faker Factory also provide about this file.

        Example:
            file.zip, awesomefile.tar.gz, samplefile.docx, djipsum.pdf

        1. from Djipsum
            faker.fake_file()
        2. from Faker Factory
            faker.fake.file_name()
        """
        return self.djipsum_fields().randomFileField()
faker.py 文件源码 项目:djipsum 作者: agusmakmun 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def fake_ipaddress(self):
        """
        Faker Factory also provide about this ipaddress,
        such as ipv4, ipv6, ...etc

        Example:
            192.168.1.1, 66.249.65.54, 255.255.255.0, 2001:db8:a0b:12f0::1

        1. from Djipsum
            faker.fake_ipaddress()
        2. from Faker Factory
            faker.fake.ipv4(), faker.fake.ipv6()
        """
        return self.djipsum_fields().randomGenericIPAddressField()
faker.py 文件源码 项目:djipsum 作者: agusmakmun 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def fake_paragraphs(self):
        """
        Generate the paragraphs for `TextField`.
        Faker Factory also provide about this paragraphs.

        Example:
        1. from Djipsum
            faker.fake_paragraphs()
        2. from Faker Factory
            ' '.join(faker.fake.paragraphs())
        """
        return self.djipsum_fields().randomTextField()
faker.py 文件源码 项目:djipsum 作者: agusmakmun 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def fake_url(self):
        """
        Generate the url for `URLField`.
        Faker Factory also provide about this url.

        Example:
            `https://python.web.id`, `http://dracos-linux.org`

        1. from Djipsum
            faker.fake_url()
        2. from Faker Factory
            faker.fake.url()
        """
        return self.djipsum_fields().randomURLField()
data_generator.py 文件源码 项目:Office365-REST-Python-Client 作者: vgrem 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def generate_contacts(context):
    contacts_list = ctx.web.lists.get_by_title("Contacts")
    fake = Faker()
    for idx in range(0, 1):
        name = fake.name()
        contact_properties = {'__metadata': {'type': 'SP.Data.ContactsListItem'}, 'Title': name}
        contact_item = contacts_list.add_item(contact_properties)
        context.execute_query()
        print("Contact '{0}' has been created".format(contact_item.properties["Title"]))
fake.py 文件源码 项目:smart-iiot 作者: quanpower 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def posts(count=100):
    fake = Faker()
    user_count = User.query.count()
    for i in range(count):
        u = User.query.offset(randint(0, user_count - 1)).first()
        p = Post(body=fake.text(),
                 timestamp=fake.past_date(),
                 author=u)
        db.session.add(p)
    db.session.commit()
safaker.py 文件源码 项目:security-unit-testing 作者: lavalamp- 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def get_create_post_kwargs():
        """
        Get a dictionary of values to submit to the post creation endpoint.
        :return: A dictionary of values to submit to the post creation endpoint.
        """
        faker = Faker()
        f = open("streetart/tests/files/puppy.jpg", "r")
        return {
            "title": faker.word(),
            "description": faker.paragraph(),
            "image": f,
        }
safaker.py 文件源码 项目:security-unit-testing 作者: lavalamp- 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def get_create_user_kwargs():
        """
        Get a dictionary of values to submit to the user registration endpoint.
        :return: A dictionary of values to submit to the user registration endpoint.
        """
        faker = Faker()
        return {
            "email": faker.email(),
            "first_name": faker.first_name(),
            "last_name": faker.last_name(),
            "password": faker.password(),
        }
safaker.py 文件源码 项目:security-unit-testing 作者: lavalamp- 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def get_edit_post_kwargs():
        """
        Get a dictionary of values to submit to the edit post endpoint.
        :return: A dictionary of values to submit to the edit post endpoint.
        """
        faker = Faker()
        return {
            "title": faker.word(),
            "description": faker.paragraph(),
            "latitude": float(faker.pydecimal()),
            "longitude": float(faker.pydecimal()),
        }
conftest.py 文件源码 项目:faker_extras 作者: christabor 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def fake():
    _fake = Faker()
    _fake.add_provider(human.HumanProvider)
    _fake.add_provider(alien.AlienProvider)
    _fake.add_provider(binary.BinaryProvider)
    _fake.add_provider(chemistry.ChemistryProvider)
    _fake.add_provider(biology.GeneticProvider)
    return _fake
tools_test.py 文件源码 项目:netcrawl 作者: Wyko 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test_locate_mac_runs_without_error():
    fake = Faker()

    for i in range(10):
        locate(fake.mac_address())
conftest.py 文件源码 项目:netcrawl 作者: Wyko 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def inventory_db():
    """Sets up a test inventory database and returns the
    database name"""

    config.parse_config()

    fake = Faker()
    dbname= '_'.join(['fakedb',
                   fake.word(),
                   fake.word(),
                   fake.word(),
                  ])

    config.cc.inventory.name = dbname

    # Create the database
    db= io_sql.sql_database()
    db.create_database(dbname)
    assert db.database_exists(dbname)
    del(db)

    print('Inventroy_db: ', dbname)

    # Pass the database to the test functions
    yield

    print('Done with inventory_db: ', dbname)

    # Delete the database after use
    db= io_sql.sql_database()
    db.delete_database(dbname)
    assert not db.database_exists(dbname)
scene_waitinglist.py 文件源码 项目:pretix-screenshots 作者: pretix 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def waitinglistentries(event, items):
    fake = faker.Faker()
    for i in range(42):
        event.waitinglistentries.create(
            item=random.choice(items),
            created=fake.date_time_between(start_date="-14d", end_date="now", tzinfo=None),
            email=fake.email()
        )
base.py 文件源码 项目:django-rest-framework-tricks 作者: barseghyanartur 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def setUpTestData(cls):
        """Set up class."""

        # Create user
        cls.user = factories.TestUsernameSuperAdminUserFactory()

        # Fake data
        cls.faker = Faker()
base.py 文件源码 项目:django-rest-framework-tricks 作者: barseghyanartur 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def setUpTestData(cls):
        """Set up class."""

        # Create user
        cls.user = factories.TestUsernameSuperAdminUserFactory()

        # Fake data
        cls.faker = Faker()


问题


面经


文章

微信
公众号

扫码关注公众号