示例#1
0
def tag_nested_many_many_fixtures():
    user = User(username="******")
    user.save()
    other_user = User(username="******")
    other_user.save()

    eng = Tag(name="eng")
    eng.save()
    eng.users.set([user])
    user_posts = Tag(name="user_posts")
    user_posts.save()
    user_posts.users.set([user])
    random = Tag(name="random", is_public=True)
    random.save()
    random.users.set([other_user])

    user_eng_post = Post(contents="user eng post",
                         access_level="public",
                         created_by=user)
    user_user_post = Post(
        contents="user user post",
        access_level="public",
        created_by=user,
    )
    random_post = Post(
        contents="other random post",
        access_level="public",
        created_by=other_user,
    )
    not_tagged_post = Post(contents="not tagged post",
                           access_level="public",
                           created_by=user)
    all_tagged_post = Post(
        contents="not tagged post",
        access_level="public",
        created_by=user,
    )

    posts = {
        "user_eng_post": user_eng_post,
        "user_user_post": user_user_post,
        "random_post": random_post,
        "not_tagged_post": not_tagged_post,
        "all_tagged_post": all_tagged_post,
    }
    for post in posts.values():
        post.save()

    user_eng_post.tags.set([eng])
    user_user_post.tags.set([user_posts])
    random_post.tags.set([random])
    all_tagged_post.tags.set([eng, user_posts, random])

    user.posts.set(
        [user_eng_post, user_user_post, not_tagged_post, all_tagged_post])
    other_user.posts.set([random_post])

    return posts
示例#2
0
def tag_fixtures():
    """Test data for tests with tags."""
    user = User(username="******")
    user.save()
    other_user = User(username="******")
    other_user.save()
    moderator = User(username="******", is_moderator=True)
    moderator.save()

    eng = Tag(name="eng")
    eng.save()
    foo = Tag(name="foo")
    foo.save()
    random = Tag(name="random", is_public=True)
    random.save()

    user_public_post = Post(contents="public post",
                            created_by=user,
                            access_level="public")
    user_private_post = Post(contents="private user post", created_by=user)
    other_user_public_post = Post(contents="other user public",
                                  created_by=other_user,
                                  access_level="public")
    other_user_private_post = Post(contents="other user private",
                                   created_by=other_user)
    other_user_random_post = Post(contents="other user random",
                                  created_by=other_user)
    other_user_foo_post = Post(contents="other user foo",
                               created_by=other_user)

    posts = {
        "user_public_post": user_public_post,
        "user_private_post": user_private_post,
        "other_user_public_post": other_user_public_post,
        "other_user_private_post": other_user_private_post,
        "other_user_random_post": other_user_random_post,
        "other_user_foo_post": other_user_foo_post,
    }
    for post in posts.values():
        post.save()

    other_user_random_post.tags.set([random])
    other_user_foo_post.tags.set([foo])

    return posts
示例#3
0
def post_fixtures():
    foo = User(username="******")
    foo.save()
    admin = User(username="******", is_moderator=True)
    admin.save()
    banned = User(username="******", is_banned=True)
    banned.save()

    Post(contents="foo public post", access_level="public",
         created_by=foo).save()
    Post(
        contents="foo public post 2",
        access_level="public",
        created_by=foo,
    ).save()
    Post(
        contents="foo private post",
        created_by=foo,
    ).save()
    Post(
        contents="foo private post 2",
        created_by=foo,
    ).save()
    Post(
        contents="private for moderation",
        needs_moderation=True,
        created_by=foo,
    ).save()
    Post(
        contents="public for moderation",
        access_level="public",
        needs_moderation=True,
        created_by=foo,
    ).save()
    Post(
        contents="public admin post",
        access_level="public",
        needs_moderation=True,
        created_by=admin,
    ).save()
    Post(
        contents="private admin post",
        needs_moderation=True,
        created_by=admin,
    ).save()
    Post(contents="banned post", access_level="public",
         created_by=banned).save()