コード例 #1
0
    def test_create_delete_comment(self):
        """ Test for comment creation and deletion """

        with self.client:
            # Create a mock user and login
            register_user(self)
            login_response = login_user(self)
            data = json.loads(login_response.data.decode())
            access_token = data["access_token"]

            # Create a mock post
            create_post_resp = create_post(self, access_token)
            create_post_resp_data = json.loads(create_post_resp.data.decode())

            post_public_id = create_post_resp_data["post"]["public_id"]

            # Create a comment
            create_comment_resp = create_comment(self, access_token, post_public_id)
            create_comment_resp_data = json.loads(create_comment_resp.data.decode())

            self.assertTrue(create_comment_resp_data["success"])
            self.assertEqual(create_comment_resp.status_code, 201)

            # Delete the comment
            comment_public_id = create_comment_resp_data["comment"]["public_id"]

            delete_response = delete_comment(self, access_token, comment_public_id)
            delete_response_data = json.loads(delete_response.data.decode())

            self.assertTrue(delete_response_data["success"])
            self.assertEqual(delete_response.status_code, 200)
コード例 #2
0
    def test_comment_update(self):
        """ Test for comment updating """

        with self.client:
            # Create a mock comment and update it
            register_user(self)
            login_response = login_user(self)
            data = json.loads(login_response.data.decode())
            access_token = data["access_token"]

            # Create a mock post
            create_post_resp = create_post(self, access_token)
            create_post_rest_data = json.loads(create_post_resp.data.decode())

            post_public_id = create_post_rest_data["post"]["public_id"]

            # Create a comment
            create_comment_resp = create_comment(self, access_token, post_public_id)
            create_comment_resp_data = json.loads(create_comment_resp.data.decode())

            # Update the comment
            comment_public_id = create_comment_resp_data["comment"]["public_id"]
            updated_content = {"content": "Updated content"}
            update_response = update_comment(
                self, comment_public_id, access_token, updated_content
            )
            update_response_data = json.loads(update_response.data.decode())

            self.assertTrue(update_response_data["success"])
            self.assertEqual(update_response.status_code, 200)
コード例 #3
0
    def test_post_like_unlike(self):
        """ Test for post liking and unliking """

        with self.client:
            # Create a mock user and login
            register_user(self)
            login_response = login_user(self)
            data = json.loads(login_response.data.decode())
            access_token = data["access_token"]

            # Post creation
            create_response = create_post(self, access_token)
            create_response_data = json.loads(create_response.data.decode())

            post = create_response_data["post"]
            post_public_id = post["public_id"]

            # Like the post
            like_response = like_post(self, access_token, post_public_id)
            json.loads(like_response.data.decode())

            self.assertEqual(like_response.status_code, 201)

            # Unlike the post
            unlike_response = unlike_post(self, access_token, post_public_id)
            json.loads(unlike_response.data.decode())

            self.assertEqual(unlike_response.status_code, 200)
コード例 #4
0
    def test_comment_get(self):
        """ Test for getting specific comment """

        with self.client:
            # Create a temporary user
            register_user(self)
            login_response = login_user(self)
            data = json.loads(login_response.data.decode())
            access_token = data["access_token"]

            # Create a mock post
            create_post_resp = create_post(self, access_token)
            create_post_rest_data = json.loads(create_post_resp.data.decode())

            post_public_id = create_post_rest_data["post"]["public_id"]

            # Create a comment
            create_comment_resp = create_comment(self, access_token, post_public_id)
            create_comment_resp_data = json.loads(create_comment_resp.data.decode())

            # Get that comment
            comment_public_id = create_comment_resp_data["comment"]["public_id"]
            get_comment_response = get_comment(self, comment_public_id, access_token)
            get_comment_response_data = json.loads(get_comment_response.data.decode())

            # Get the content for comparison
            original_content = create_comment_resp_data["comment"]["content"]
            received_content = get_comment_response_data["comment"]["content"]

            self.assertTrue(get_comment_response_data["success"])
            self.assertEqual(get_comment_response.status_code, 200)
            self.assertEqual(original_content, received_content)
コード例 #5
0
    def test_post_update(self):
        """ Test for post updating """

        with self.client:
            # Create a mock post and update it.
            register_user(self)
            login_response = login_user(self)
            data = json.loads(login_response.data.decode())
            access_token = data["access_token"]

            # Create a post
            create_response = create_post(self, access_token)
            create_response_data = json.loads(create_response.data.decode())

            # Update the post
            post_public_id = create_response_data["post"]["public_id"]
            updated_content = {"content": "Updated content"}
            update_response = update_post(self, updated_content, access_token,
                                          post_public_id)
            update_response_data = json.loads(update_response.data.decode())

            # Compare data
            original_content = create_response_data["post"]["content"]

            self.assertNotEqual(original_content, updated_content)
            self.assertEqual(update_response.status_code, 200)
            self.assertTrue(update_response_data["success"])
コード例 #6
0
    def test_get_info(self):
        """ Test for getting feed information """

        with self.client:
            # Create a mock user and login
            register_user(self)
            login_response = login_user(self)
            data = json.loads(login_response.data.decode())
            access_token = data["access_token"]

            # Post creation
            create_post(self, access_token)

            # Get the posts
            get_response = get_post_ids(self, access_token)
            get_response_data = json.loads(get_response.data.decode())

            id_array = get_response_data["post_ids"]

            # Get post information
            get_post_response = get_post_information(self, access_token, id_array)
            get_post_response_data = json.loads(get_post_response.data.decode())

            info_array = get_post_response_data["posts"]

            self.assertTrue(get_post_response_data["success"])
            self.assertFalse(info_array[0] is None)
            self.assertEqual(get_post_response.status_code, 200)
コード例 #7
0
    def test_update_user(self):
        """ Test for updating the user """

        with self.client:
            # User registration
            register_user(self)
            login_response = login_user(self)
            login_response_data = json.loads(login_response.data.decode())
            access_token = login_response_data["access_token"]

            # Update the user data
            updated_user = {"bio": "reEeeeEEEEEeEeeeee", "avatar": "test.png"}
            update_response = update_user(self, updated_user, access_token)
            update_response_data = json.loads(update_response.data.decode())

            self.assertTrue(update_response_data["success"])
コード例 #8
0
    def test_get_user(self):
        """ Get a specific user using its public id """

        with self.client:
            # User registration
            register_user(self)
            login_response = login_user(self)
            login_response_data = json.loads(login_response.data.decode())
            access_token = login_response_data["access_token"]

            # Get the user data
            username = login_response_data["user"]["username"]
            get_response = get_user(self, access_token, username)
            json.loads(get_response.data.decode())

            self.assertEqual(get_response.status_code, 200)
コード例 #9
0
    def test_registered_user_login(self):
        """ Test for login of registered-user login """

        with self.client:
            # User registration
            user_response = register_user(self)
            json.loads(user_response.data.decode())

            self.assertEqual(user_response.status_code, 201)

            # Registered user login
            login_response = login_user(self)
            data = json.loads(login_response.data.decode())

            self.assertTrue(data["access_token"])
            self.assertEqual(login_response.status_code, 200)