Ejemplo n.º 1
0
def create_category_bulk(category_nb, root_category_nb=10, testing=True):
    if not is_testing() and testing:
        raise RuntimeError("Not in testing environment. Set testing to False to silence this error.")

    faker = Factory.create()
    root_category_list = [RootCategory.objects.create(name=faker.word()) for i in range(root_category_nb)]
    return [Category.objects.create(root_category=choice(root_category_list), name=faker.word()) for i in range(category_nb)]
Ejemplo n.º 2
0
def create_profile_bulk(profile_nb, testing=True):
    """Utility function that creates `profile_nb` profiles.
    All fields are randomly generated."""
    if not is_testing() and testing:
        raise RuntimeError("Not in testing environment. Set testing to False to silence this error.")

    faker = Factory.create()
    user_dict = [{"first_name": faker.first_name(),
                  "last_name": faker.last_name(),
                  "email_address": faker.email(),
                  "password": generate_random_password()} for i in range(profile_nb)]

    profile_list = []
    for user_data in user_dict:
        user = get_user_model().objects.create_user(username=user_data["email_address"], password=user_data["password"])
        profile = Profile.objects.create(user=user,
                                         first_name=user_data["first_name"],
                                         last_name=user_data["last_name"])

        profile_list.append(profile)

    return profile_list
Ejemplo n.º 3
0
def create_post_bulk(post_nb, text_content=None, post_type=None, user_list=None, testing=True):
    if not is_testing() and testing:
        raise RuntimeError("Not in testing environment. Set testing to False to silence this error.")

    faker = Factory.create()
    category_list = create_category_bulk(category_nb=30, testing=testing)

    if user_list is None:
        user_list = [p.user for p in create_profile_bulk(profile_nb=10)]

    if text_content is None:
        text_content = faker.paragraph()

    if post_type is None:
        post_type = choice((Post.OFFER, Post.NEED))

    return [Post.objects.create(user=choice(user_list),
                                category=choice(category_list),
                                text_content=text_content,
                                type=post_type,
                                remote=choice((True, False)))
            for i in range(post_nb)]