コード例 #1
0
ファイル: test_post.py プロジェクト: jstine/flaskeddit
    def test_post_downvote_post(self, test_client):
        """
        Test POST request to the /community/_/post/_/downvote route to assert the user
        successfuly downvotes the post.
        """
        password = "******"
        hashed_password = bcrypt.generate_password_hash(password)
        app_user = AppUser(username="******", password=hashed_password)
        community = Community(name="mockcommunity",
                              description="mockdescription",
                              app_user=app_user)
        post = Post(
            title="mockposttitle",
            post="mockpost",
            app_user=app_user,
            community=community,
        )
        db.session.add(app_user)
        db.session.add(community)
        db.session.add(post)
        db.session.commit()
        helpers.login(test_client, app_user.username, password)

        response = test_client.post(
            f"/community/{community.name}/post/{post.title}/downvote")

        assert response is not None
        assert response.status_code == 302
        post_vote = PostVote.query.filter_by(user_id=app_user.id,
                                             post_id=post.id).first()
        assert post_vote is not None
        assert post_vote.vote == -1
コード例 #2
0
ファイル: test_post.py プロジェクト: jstine/flaskeddit
    def test_post_create_post(self, test_client):
        """
        Test POST request to the /community/_/post/create route to assert the post is
        created successfully.
        """
        password = "******"
        hashed_password = bcrypt.generate_password_hash(password)
        app_user = AppUser(username="******", password=hashed_password)
        community = Community(name="mockcommunity",
                              description="mockdescription",
                              app_user=app_user)
        db.session.add(app_user)
        db.session.add(community)
        db.session.commit()
        helpers.login(test_client, app_user.username, password)

        response = test_client.post(
            f"/community/{community.name}/post/create",
            data={
                "title": "mockposttitle",
                "post": "mockpost"
            },
            follow_redirects=True,
        )

        assert response is not None
        assert response.status_code == 200
        assert b"Successfully created post" in response.data
コード例 #3
0
ファイル: test_reply.py プロジェクト: jstine/flaskeddit
    def test_post_delete_reply(self, test_client):
        """
        Test POST request to the /community/_/post/_/reply/_/delete route to assert the
        reply is successfully deleted.
        """
        password = "******"
        hashed_password = bcrypt.generate_password_hash(password)
        app_user = AppUser(username="******", password=hashed_password)
        community = Community(
            name="mockcommunity", description="mockdescription", app_user=app_user
        )
        post = Post(
            title="mockposttitle",
            post="mockpost",
            app_user=app_user,
            community=community,
        )
        reply = Reply(reply="mockreply", app_user=app_user, post=post)
        db.session.add(app_user)
        db.session.add(community)
        db.session.add(post)
        db.session.add(reply)
        db.session.commit()
        helpers.login(test_client, app_user.username, password)

        response = test_client.post(
            f"/community/{community.name}/post/{post.title}/reply/{reply.id}/delete",
            follow_redirects=True,
        )

        assert response is not None
        assert response.status_code == 200
        assert b"Successfully deleted reply" in response.data
コード例 #4
0
ファイル: test_post.py プロジェクト: jstine/flaskeddit
    def test_get_update_post(self, test_client):
        """
        Test GET request to the /community/_/post/_/update route to assert the post
        update page is displayed.
        """
        password = "******"
        hashed_password = bcrypt.generate_password_hash(password)
        app_user = AppUser(username="******", password=hashed_password)
        community = Community(name="mockcommunity",
                              description="mockdescription",
                              app_user=app_user)
        post = Post(
            title="mockposttitle",
            post="mockpost",
            app_user=app_user,
            community=community,
        )
        db.session.add(app_user)
        db.session.add(community)
        db.session.add(post)
        db.session.commit()
        helpers.login(test_client, app_user.username, password)

        response = test_client.get(
            f"/community/{community.name}/post/{post.title}/update")

        assert response is not None
        assert response.status_code == 200
        assert b"Update Post" in response.data
コード例 #5
0
    def test_get_feed(self, test_client):
        """
        Test GET request to the / route to assert posts from the users joined
        communities are displayed.
        """
        password = "******"
        hashed_password = bcrypt.generate_password_hash(password)
        app_user = AppUser(username="******", password=hashed_password)
        community = Community(name="mockcommunity",
                              description="mockdescription",
                              app_user=app_user)
        community_member = CommunityMember(app_user=app_user,
                                           community=community)
        post = Post(
            title="mockposttitle",
            post="mockpost",
            app_user=app_user,
            community=community,
        )
        db.session.add(app_user)
        db.session.add(community)
        db.session.add(community_member)
        db.session.add(post)
        db.session.commit()
        helpers.login(test_client, app_user.username, password)

        response = test_client.get("/")

        assert response is not None
        assert response.status_code == 200
        assert bytes(post.title, "utf-8") in response.data
コード例 #6
0
def register_user(username, password):
    """
    Hashes the given password and registers a new user in the database.
    """
    hashed_password = bcrypt.generate_password_hash(password).decode("utf-8")
    app_user = AppUser(username=username.lower(), password=hashed_password)
    db.session.add(app_user)
    db.session.commit()
コード例 #7
0
    def test_get_create_community(self, test_client):
        """
        Test GET request to the /community/create route to assert the community
        creation page is returned.
        """
        password = "******"
        hashed_password = bcrypt.generate_password_hash(password)
        app_user = AppUser(username="******", password=hashed_password)
        db.session.add(app_user)
        db.session.commit()
        helpers.login(test_client, app_user.username, password)

        response = test_client.get("/community/create")

        assert response is not None
        assert response.status_code == 200
        assert b"Create Community" in response.data
コード例 #8
0
ファイル: test_auth.py プロジェクト: jstine/flaskeddit
    def test_post_logout(self, test_client):
        """
        Test POST request to the /logout route to assert the user is successfully
        logged out.
        """
        password = "******"
        hashed_password = bcrypt.generate_password_hash(password)
        app_user = AppUser(username="******", password=hashed_password)
        db.session.add(app_user)
        db.session.commit()
        helpers.login(test_client, app_user.username, password)

        response = test_client.post("/logout", follow_redirects=True)

        assert response is not None
        assert response.status_code == 200
        assert b"Successfully logged out" in response.data
コード例 #9
0
    def test_post_create_community(self, test_client):
        """
        Test POST request to the /community/create route to assert the community is
        successfully created.
        """
        password = "******"
        hashed_password = bcrypt.generate_password_hash(password)
        app_user = AppUser(username="******", password=hashed_password)
        db.session.add(app_user)
        db.session.commit()
        helpers.login(test_client, app_user.username, password)

        response = test_client.post(
            "/community/create",
            data={"name": "mockcommunity", "description": "mockdescription"},
            follow_redirects=True,
        )

        assert response is not None
        assert response.status_code == 200
        assert b"Successfully created community" in response.data