Exemplo n.º 1
0
def test_edit_blog_reader(client, blog, reader_token):
    rv = client.put(
        "/blogs/" + str(blog.url) + "/",
        json={"title": "new title"},
        headers={"Authorization": reader_token[1].token},
    )
    assert rv.json["success"] == 0
    assert rv.json["error"]["code"] == 3

    assert Blog.get().title == blog.title, "Blog title changed"
    assert Blog.get().title != "new title"
Exemplo n.º 2
0
def test_create_jam(client, user_token):
    rv = client.post(
        "/jams/",
        headers={"Authorization": user_token[1].token},
        json={
            "title": "test title for jam",
            "url": "test-jam",
            "description": "description",
            "short_description": "short",
            "start_date": datetime.datetime.now().timestamp() + 5,
            "end_date": datetime.datetime.now().timestamp() + 10,
        },
    )
    assert rv.json["success"] == 1
    assert "jam" in rv.json

    blog = Blog.get()
    assert blog.creator == user_token[0], "Wrong creator"
    assert blog.description == 'Это блог для джема "test title for jam"'

    participiation = BlogParticipiation.get()
    assert participiation.user == user_token[0]
    assert participiation.role == 1, "Not owner on creation"

    jam = Jam.get()
    assert jam.creator == user_token[0], "Wrong creator"
    assert jam.title == "test title for jam"
    assert jam.url == "test-jam"
    assert jam.description == "description"
    assert jam.short_description == "short"
    assert int(jam.start_date) > int(datetime.datetime.now().timestamp())
    assert int(jam.start_date) == int(jam.end_date - 5)
Exemplo n.º 3
0
def test_edit_blog(client, blog, user_token):
    rv = client.put(
        "/blogs/" + str(blog.url) + "/",
        json={"title": "new title"},
        headers={"Authorization": user_token[1].token},
    )
    assert rv.json["success"] == 1

    assert Blog.get().title == "new title", "Blog title not chaged"
Exemplo n.º 4
0
def test_create_blog(client, user_token):
    rv = client.post(
        "/blogs/",
        headers={"Authorization": user_token[1].token},
        json={"url": "blog-url"},
    )
    assert rv.json["success"] == 1
    assert "blog" in rv.json, "No blog in response"

    blog = Blog.get()
    assert blog.creator == user_token[0], "Wrong creator"
    assert blog.id == rv.json["blog"]["id"]

    participiation = BlogParticipiation.get()
    assert participiation.blog.id == rv.json["blog"]["id"]
    assert participiation.user == user_token[0]
    assert participiation.role == 1, "Not owner on creation"
Exemplo n.º 5
0
def convert():
    create_app()

    for t in TuTopic.select():
        creator = User.get_or_none(User.id == t.user)
        if not creator:
            print("Skipped post. Owner:" +
                  TuUser.get(TuUser.user == t.user).user_login)
            continue

        updated = t.topic_date_edit
        if not updated:
            updated = t.topic_date_add

        topic_content = TuTopicContent.get(TuTopicContent.topic == t.topic)
        text = topic_content.topic_text_source

        text = content.replace_uploads_in_text(creator, text)
        # TODO convert questions and photosets

        cut = text.split("<cut>")[0]
        post = Post.create(
            id=t.topic,
            blog=Blog.get(Blog.id == t.blog),
            creator=creator,
            created_date=t.topic_date_add,
            updated_date=updated,
            title=t.topic_title,
            cut_text=cut,
            has_cut="<cut>" in text,
            text=text,
            rating=0,
            is_draft=t.topic_publish == 0,
            is_on_main=t.topic_publish_index == 1,
            reads=0,
            url=t.topic_url,
        )

        tags = t.topic_tags.split(",")
        for tag in tags:
            tag_obj = Tag.get_or_none(title=tag)
            if tag_obj is None:
                tag_obj = Tag.create(title=tag, created_date=t.topic_date_add)
            TagMark.create(tag=tag_obj, post=post)
Exemplo n.º 6
0
def test_edit_jam(client, user_token, jam):
    rv = client.post(
        f"/jams/{jam.url}/",
        headers={"Authorization": user_token[1].token},
        json={"title": "new title"},
    )
    assert rv.json["success"] == 1
    assert "jam" in rv.json

    blog = Blog.get()
    assert blog.creator == user_token[0], "Wrong creator"
    assert blog.description == 'Это блог для джема "new title"'

    participiation = BlogParticipiation.get()
    assert participiation.user == user_token[0]
    assert participiation.role == 1, "Not owner on creation"

    jam = Jam.get()
    assert jam.creator == user_token[0], "Wrong creator"
    assert jam.title == "new title"
    assert jam.url == jam.url
    assert jam.description == jam.description
    assert jam.short_description == jam.short_description
Exemplo n.º 7
0
def convert():
    create_app()

    def get_blog_type(blog):
        if blog.blog_type == "open":
            return 1
        elif blog.blog_type == "hidden":
            return 3
        else:
            return 2

    for b in TuBlog.select():
        blog_type = get_blog_type(b)

        year = b.blog_date_add.year
        month = b.blog_date_add.month
        avatar = content.create_content(b.blog_avatar, "blog_avatar", b.blog,
                                        b.user_owner, year, month)

        updated = b.blog_date_edit
        if not updated:
            updated = b.blog_date_add

        owner = User.get_or_none(User.id == b.user_owner)
        if not owner:
            print("Skipped blog. Owner:" +
                  TuUser.get(TuUser.user == b.user_owner).user_login)
            continue

        about = content.replace_uploads_in_text(owner, b.blog_description)

        url = b.blog_url or "blog" + str(b.blog)
        blog = Blog.create(
            id=b.blog,
            created_date=b.blog_date_add,
            updated_date=updated,
            description=about,
            title=b.blog_title,
            url=url,
            blog_type=blog_type,
            creator=owner,
            image=avatar,
        )

        BlogParticipiation.create(
            blog=blog,
            user=owner,
            role=1,
        )

    for bu in TuBlogUser.select():
        role = 1
        if bu.user_role == 1:
            role = 3
        if bu.user_role > 1:
            role = 1

        BlogParticipiation.create(
            blog=Blog.get(Blog.id == bu.blog),
            user=User.get(User.id == bu.user),
            role=role,
        )