Exemplo n.º 1
0
    def clear_vote_comment(self):
        """Clear the vote of a comment"""
        try:
            username = random.choice(list(self.contributors))
            comment_id = random.choice(self.comments)
        except IndexError:
            # this means that this started before creating contributors or posts
            return

        api = make_api_client(username)
        comment = api.get_comment(comment_id)
        # Force HTTP GET request
        with channel_api.request_name("/api/info?id=[comment_id]&raw_json=1"):
            likes = comment.likes

        if likes is not None:
            comment.clear_vote()

        # Due to the way the DRF view works we actually fetch API client twice
        api = make_api_client(username)
        comment = api.get_comment(comment_id)

        with channel_api.request_name("/api/info?id=[comment_id]&raw_json=1"):
            # Force HTTP get request
            _ = comment.likes
Exemplo n.º 2
0
    def upvote_post(self):
        """
        Upvotes a post
        """
        try:
            username = random.choice(list(self.contributors))
            post_id = random.choice(self.posts)
        except IndexError:
            # this means that this started before creating contributors or posts
            return
        api = make_api_client(username)
        post = api.get_post(post_id)
        # Force HTTP GET request
        with channel_api.request_name("/comments/[post_id]/?limit=2048&sort=best&raw_json=1"):
            already_upvoted = post.likes is True

        if not already_upvoted:
            post.upvote()

        # Due to the way the DRF view works we actually fetch API client twice
        api = make_api_client(username)
        post = api.get_post(post_id)

        with channel_api.request_name("/comments/[post_id]/?limit=2048&sort=best&raw_json=1"):
            # Force HTTP get request
            _ = post.title
Exemplo n.º 3
0
    def clear_vote_post(self):
        """Clear the vote on a post"""
        try:
            username = random.choice(list(self.contributors))
            post_id = random.choice(self.posts)
        except IndexError:
            # this means that this started before creating contributors or posts
            return
        api = make_api_client(username)
        post = api.get_post(post_id)
        # Force HTTP GET request
        with channel_api.request_name("/comments/[post_id]/?limit=2048&sort=best&raw_json=1"):
            # Technically this should never be False, just True or None, but just in case
            not_already_upvoted = post.likes is not True

        if not not_already_upvoted:
            post.clear_vote()

        # Due to the way the DRF view works we actually fetch API client twice
        api = make_api_client(username)
        post = api.get_post(post_id)

        with channel_api.request_name("/comments/[post_id]/?limit=2048&sort=best&raw_json=1"):
            # Force HTTP get request
            _ = post.title
Exemplo n.º 4
0
    def create_channel(self):
        """Create a channel"""
        api = make_api_client(settings.OPEN_DISCUSSIONS_API_USERNAME)

        name = "channel_{}".format(uuid.uuid4().hex)[:20]

        api.create_channel(
            title=' '.join(fake.paragraph().split(' ')[:2]),
            name=name,
            public_description=fake.paragraph(),
            channel_type='private',
        )
        with channel_api.request_name("/r/[channel_name]/about/?raw_json=1"):
            # access title to force an HTTP request
            _ = api.get_channel(name).title
        self.discussion_channels.append(name)
Exemplo n.º 5
0
 def create_post(self):
     """
     creates a post for an user
     """
     try:
         username = random.choice(list(self.contributors))
     except IndexError:
         # this means that this started before creating contributors
         return
     api = make_api_client(username)
     post = api.create_post(
         channel_name=self.channel,
         title=' '.join(fake.paragraph().split(' ')[:2]),
         text=fake.paragraph(),
     )
     # Force HTTP GET request
     with channel_api.request_name("/comments/[post_id]/?limit=2048&sort=best&raw_json=1"):
         _ = post.title
     self.posts.append(post.id)