コード例 #1
0
ファイル: forum.py プロジェクト: Z19900505/Python.learn
def topicsread(user, topic, last_read):
    """Create a topicsread object for the user and a topic."""
    topicsread = TopicsRead()
    topicsread.user_id = user.id
    topicsread.topic_id = topic.id
    topicsread.forum_id = topic.forum_id
    topicsread.last_read = last_read
    topicsread.save()
    return topicsread
コード例 #2
0
def test_forum_update_read(database, user, topic):
    """Test the update read method."""
    forumsread = ForumsRead.query.\
        filter(ForumsRead.user_id == user.id,
               ForumsRead.forum_id == topic.forum_id).first()

    topicsread = TopicsRead.query.\
        filter(TopicsRead.user_id == user.id,
               TopicsRead.topic_id == topic.id).first()

    forum = topic.forum

    with current_app.test_request_context():
        # Test with logged in user
        login_user(user)

        # Should return False because topicsread is None
        assert not forum.update_read(current_user, forumsread, topicsread)

        # This is the first time the user visits the topic
        topicsread = TopicsRead()
        topicsread.user_id = user.id
        topicsread.topic_id = topic.id
        topicsread.forum_id = topic.forum_id
        topicsread.last_read = datetime.utcnow()
        topicsread.save()

        # hence, we also need to create a new forumsread entry
        assert forum.update_read(current_user, forumsread, topicsread)

        forumsread = ForumsRead.query.\
            filter(ForumsRead.user_id == user.id,
                   ForumsRead.forum_id == topic.forum_id).first()

        # everything should be up-to-date now
        assert not forum.update_read(current_user, forumsread, topicsread)

        post = Post(content="Test Content")
        post.save(user=user, topic=topic)

        # Updating the topicsread tracker
        topicsread.last_read = datetime.utcnow()
        topicsread.save()

        # now the forumsread tracker should also need a update
        assert forum.update_read(current_user, forumsread, topicsread)

        logout_user()
        # should fail because the user is logged out
        assert not forum.update_read(current_user, forumsread, topicsread)
コード例 #3
0
def test_topicsread(topic, user):
    """Tests if the topicsread trakcer can be saved/edited and deleted with the
    implemented save and delete methods."""
    topicsread = TopicsRead()
    topicsread.user_id = user.id
    topicsread.topic_id = topic.id
    topicsread.forum_id = topic.forum_id
    topicsread.last_read = datetime.utcnow()
    topicsread.save()
    assert topicsread is not None

    topicsread.delete()
    topicsread = TopicsRead.query.filter_by(topic_id=topicsread.topic_id).first()
    assert topicsread is None
コード例 #4
0
ファイル: test_forum_models.py プロジェクト: 0xsKu/flaskbb
def test_forum_update_read(database, user, topic):
    """Test the update read method."""
    forumsread = ForumsRead.query.\
        filter(ForumsRead.user_id == user.id,
               ForumsRead.forum_id == topic.forum_id).first()

    topicsread = TopicsRead.query.\
        filter(TopicsRead.user_id == user.id,
               TopicsRead.topic_id == topic.id).first()

    forum = topic.forum

    with current_app.test_request_context():
        # Test with logged in user
        login_user(user)

        # Should return False because topicsread is None
        assert not forum.update_read(current_user, forumsread, topicsread)

        # This is the first time the user visits the topic
        topicsread = TopicsRead()
        topicsread.user_id = user.id
        topicsread.topic_id = topic.id
        topicsread.forum_id = topic.forum_id
        topicsread.last_read = datetime.utcnow()
        topicsread.save()

        # hence, we also need to create a new forumsread entry
        assert forum.update_read(current_user, forumsread, topicsread)

        forumsread = ForumsRead.query.\
            filter(ForumsRead.user_id == user.id,
                   ForumsRead.forum_id == topic.forum_id).first()

        # everything should be up-to-date now
        assert not forum.update_read(current_user, forumsread, topicsread)

        post = Post(content="Test Content")
        post.save(user=user, topic=topic)

        # Updating the topicsread tracker
        topicsread.last_read = datetime.utcnow()
        topicsread.save()

        # now the forumsread tracker should also need a update
        assert forum.update_read(current_user, forumsread, topicsread)

        logout_user()
        # should fail because the user is logged out
        assert not forum.update_read(current_user, forumsread, topicsread)
コード例 #5
0
def test_topic_tracker_needs_update(database, user, topic):
    """Tests if the topicsread tracker needs an update if a new post has been
    submitted.
    """
    forumsread = ForumsRead.query.\
        filter(ForumsRead.user_id == user.id,
               ForumsRead.forum_id == topic.forum_id).first()

    topicsread = TopicsRead.query.\
        filter(TopicsRead.user_id == user.id,
               TopicsRead.topic_id == topic.id).first()

    with current_app.test_request_context():
        assert topic.tracker_needs_update(forumsread, topicsread)

        # Update the tracker
        topicsread = TopicsRead()
        topicsread.user_id = user.id
        topicsread.topic_id = topic.id
        topicsread.forum_id = topic.forum_id
        topicsread.last_read = datetime.utcnow()
        topicsread.save()

        forumsread = ForumsRead()
        forumsread.user_id = user.id
        forumsread.forum_id = topic.forum_id
        forumsread.last_read = datetime.utcnow()
        forumsread.save()

        # Now the topic should be read
        assert not topic.tracker_needs_update(forumsread, topicsread)

        post = Post(content="Test Content")
        post.save(topic=topic, user=user)

        assert topic.tracker_needs_update(forumsread, topicsread)
コード例 #6
0
def test_forum_update_read_two_topics(database, user, topic, topic_moderator):
    """Test if the ForumsRead tracker will be updated if there are two topics
    and where one is unread and the other is read.
    """
    forumsread = ForumsRead.query.\
        filter(ForumsRead.user_id == user.id,
               ForumsRead.forum_id == topic.forum_id).first()

    forum = topic.forum

    with current_app.test_request_context():
        # Test with logged in user
        login_user(user)

        # This is the first time the user visits the topic
        topicsread = TopicsRead()
        topicsread.user_id = user.id
        topicsread.topic_id = topic.id
        topicsread.forum_id = topic.forum_id
        topicsread.last_read = datetime.utcnow()
        topicsread.save()

        # will not create a entry because there is still one unread topic
        assert not forum.update_read(current_user, forumsread, topicsread)
コード例 #7
0
ファイル: test_forum_models.py プロジェクト: 0xsKu/flaskbb
def test_topic_tracker_needs_update(database, user, topic):
    """Tests if the topicsread tracker needs an update if a new post has been
    submitted.
    """
    forumsread = ForumsRead.query.\
        filter(ForumsRead.user_id == user.id,
               ForumsRead.forum_id == topic.forum_id).first()

    topicsread = TopicsRead.query.\
        filter(TopicsRead.user_id == user.id,
               TopicsRead.topic_id == topic.id).first()

    with current_app.test_request_context():
        assert topic.tracker_needs_update(forumsread, topicsread)

        # Update the tracker
        topicsread = TopicsRead()
        topicsread.user_id = user.id
        topicsread.topic_id = topic.id
        topicsread.forum_id = topic.forum_id
        topicsread.last_read = datetime.utcnow()
        topicsread.save()

        forumsread = ForumsRead()
        forumsread.user_id = user.id
        forumsread.forum_id = topic.forum_id
        forumsread.last_read = datetime.utcnow()
        forumsread.save()

        # Now the topic should be read
        assert not topic.tracker_needs_update(forumsread, topicsread)

        post = Post(content="Test Content")
        post.save(topic=topic, user=user)

        assert topic.tracker_needs_update(forumsread, topicsread)
コード例 #8
0
ファイル: test_forum_models.py プロジェクト: 0xsKu/flaskbb
def test_forum_update_read_two_topics(database, user, topic, topic_moderator):
    """Test if the ForumsRead tracker will be updated if there are two topics
    and where one is unread and the other is read.
    """
    forumsread = ForumsRead.query.\
        filter(ForumsRead.user_id == user.id,
               ForumsRead.forum_id == topic.forum_id).first()

    forum = topic.forum

    with current_app.test_request_context():
        # Test with logged in user
        login_user(user)

        # This is the first time the user visits the topic
        topicsread = TopicsRead()
        topicsread.user_id = user.id
        topicsread.topic_id = topic.id
        topicsread.forum_id = topic.forum_id
        topicsread.last_read = datetime.utcnow()
        topicsread.save()

        # will not create a entry because there is still one unread topic
        assert not forum.update_read(current_user, forumsread, topicsread)