python类create()的实例源码

test_credential.py 文件源码 项目:aws_ir-api 作者: ThreatResponse 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def fake_sort_key():
    """Generate a fake sort-key in the form of user-email+account_id"""
    fake = Factory.create()

    account_id = "671642278147"
    email = fake.email()
    return "{account_id}+{email}".format(account_id=account_id, email=email)
seatingchart.py 文件源码 项目:levis 作者: rawg 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def create(self):
        people = list(self.people.keys())
        random.shuffle(people)
        return people
demo_content.py 文件源码 项目:ecommerce_api 作者: nbschool 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def get_databases():
    """create a list with the name of each .db file from main folder."""
    list_of_db = glob.glob('*.db')
    return list_of_db
demo_content.py 文件源码 项目:ecommerce_api 作者: nbschool 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def picture_creator(num_picture, index, item):
    ALLOWED_EXTENSION = ['jpg', 'jpeg', 'png', 'gif']
    pictures_path = get_random_pictures(num_picture)
    picture_id = fake.uuid4()
    extension = random.choice(ALLOWED_EXTENSION)
    Picture.create(
        uuid=picture_id,
        extension=extension,
        item=item
    )
    image_folder = utils.get_image_folder()
    if not os.path.exists(image_folder):
        os.makedirs(image_folder)
    shutil.copy2(pictures_path[index], '/{}/{}.{}'.format(image_folder, picture_id, extension))
demo_content.py 文件源码 项目:ecommerce_api 作者: nbschool 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def address_creator(num_addr):
    LIST_COUNTRIES = ['Belgium', 'France', 'Germany',
                      'Greece', 'Italy', 'Portugal', 'Spain']
    for i in range(num_addr):
        country = random.choice(LIST_COUNTRIES)
        Address.create(
            uuid=fake.uuid4(),
            user=User.select().order_by(fn.Random()).get(),
            country=country,
            city=fake.city(),
            post_code=fake.postcode(),
            address=fake.street_name(),
            phone=fake.phone_number(),
        )
demo_content.py 文件源码 项目:ecommerce_api 作者: nbschool 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def favorite_creator(num_favorites):
    for i in range(num_favorites):
        Favorite.create(
            uuid=fake.uuid4(),
            item=Item.select().order_by(fn.Random()).get(),
            user=User.select().order_by(fn.Random()).get(),
            )
mock.py 文件源码 项目:intake 作者: codeforamerica 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def fake_invitation(organization, inviter, **kwargs):
    data = dict(
        email=fake.free_email(),
        created=Pacific.localize(
            fake.date_time_between('-1w', 'now'))
    )
    data.update(kwargs)
    return models.Invitation.create(
        organization=organization,
        inviter=inviter,
        **data)
mock.py 文件源码 项目:intake 作者: codeforamerica 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def make_submission():
    return factories.FormSubmissionWithOrgsFactory.create()
mock.py 文件源码 项目:intake 作者: codeforamerica 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def fillable_pdf(**kwargs):
    attributes = dict(
        name="Sample PDF",
        pdf=File(open(
            'tests/sample_pdfs/sample_form.pdf', 'rb')),
        translator="tests.sample_translator.translate",
        organization=Organization.objects.get(slug='sf_pubdef')
    )
    attributes.update(kwargs)
    return FillablePDFFactory.create(**attributes)
mock.py 文件源码 项目:intake 作者: codeforamerica 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def useable_pdf(org):
    path = getattr(settings, 'TEST_PDF_PATH', os.environ.get('TEST_PDF_PATH'))
    example_pdf = File(open(path, 'rb'))
    return FillablePDFFactory.create(
        name="Clean Slate",
        pdf=example_pdf,
        translator="intake.translators.clean_slate.translator",
        organization=org,
    )
__init__.py 文件源码 项目:juicer 作者: eubr-bigsea 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def masking_gen(attribute_name, details):
    """
    Apply masking to a RDD of rows. Rows are first grouped by key in order to
    have rows with same value for the column available at same time (if the
    value is the same, the mask will be the same).
    @FIXME: Define a good size for partitions / groups (for instance use part
    of string or range of numbers, but it depends on the data type).
    """
    def masking(group):
        from faker import Factory
        faker_obj = Factory.create(details.get('lang', 'en_GB'))
        faker_obj.seed(random.randint(0, 100000))

        if not hasattr(faker_obj, details.get('label_type', 'name')):
            raise ValueError(_('Invalid masking type: {}').format(
                details.get('label_type')))

        action = getattr(faker_obj, details.get('label_type', 'name'))
        faker_ctx = {}

        result = []
        for row in group[1]:
            as_dict = row.asDict()
            value = as_dict.get(attribute_name)
            if value in faker_ctx:
                new_value = faker_ctx.get(value)
            else:
                new_value = action(**details.get('label_args', {}))
                faker_ctx[value] = new_value

            as_dict[attribute_name] = new_value
            result.append(as_dict)
        return result

    return masking
db_seeder.py 文件源码 项目:Ulatwiaczek 作者: Marucik 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def handle(self, *args, **options):
        number = options['count'][0]
        fake = Factory.create('pl_PL')
        for i in range(number):
            nauczyciel = Nauczyciel(None, fake.first_name().encode('ascii','ignore'), fake.last_name().encode('ascii','ignore'))
            nauczyciel.save()

            nazwaPrzedmiotu = fake.job().encode('ascii','ignore')
            przedmiot = Przedmiot(None, nazwaPrzedmiotu, nazwaPrzedmiotu[0:3])
            przedmiot.save()

            test = Test(None, random.randint(1, Przedmiot.objects.all().count()), random.randint(5, 15), random.randint(20, 40),fake.sentence(nb_words=6, variable_nb_words=True) ,datetime.date.today(), datetime.date.today(), True)
            test.save()
factories.py 文件源码 项目:munch-core 作者: crunchmail 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def auto_create_sending_domain(
            self, create, extracted, create_sending_domain=True):
        if not create:
            return

        if create_sending_domain:
            SendingDomain.objects.create(
                name=self.name, organization=self.author.organization)
factories.py 文件源码 项目:munch-core 作者: crunchmail 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def groups(self, create, extracted, **kwargs):
        if not create:
            return

        if extracted:
            for group in extracted:
                if group in [
                        'users', 'collaborators',
                        'managers', 'administrators']:
                    self.groups.add(Group.objects.filter(name=group)[0])
generate_data.py 文件源码 项目:aiohttp_admin 作者: aio-libs 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def init(loop):
    print("Generating Fake Data")
    pg = await init_postgres(conf['postgres'], loop)
    fake = Factory.create()
    fake.seed(1234)
    await preapre_tables(pg)

    quiestion_num = 1000
    choices_num = 5
    question_ids = await generate_questions(pg, quiestion_num, fake)
    await generate_choices(pg, choices_num, fake, question_ids)

    pg.close()
    await pg.wait_closed()
generate_data.py 文件源码 项目:aiohttp_admin 作者: aio-libs 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def init(loop):
    print("Generating Fake Data")
    mongo = await init_mongo(conf['mongo'], loop)
    fake = Factory.create()
    fake.seed(1234)

    await prepare_coolections(mongo.user, mongo.message, mongo.follower)

    users = await generate_users(mongo.user, db.user, 100, fake)
    await generate_messages(mongo.message, db.message, 50, fake, users)
    user_ids = [v['_id'] for v in users]
    await generate_followers(mongo.follower, db.follower, 5, fake, user_ids)
generate_data.py 文件源码 项目:aiohttp_admin 作者: aio-libs 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def init(loop):
    print("Generating Fake Data")
    pg = await init_postgres(conf['postgres'], loop)
    fake = Factory.create()
    fake.seed(1234)
    await prepare_tables(pg)

    rows = 1000

    tag_ids = await generate_tags(pg, 500, fake)
    post_ids = await generate_posts(pg, rows, fake, tag_ids)
    await generate_comments(pg, 25, fake, post_ids)


问题


面经


文章

微信
公众号

扫码关注公众号