Exemple #1
0
    def testReplicate(self):
        """Tests replicating a post to a topic shard."""
        shard = models.Shard(id='my-shard-name')
        shard.put()

        # This post was before the topic change and won't be replicated
        first_post = posts.insert_post(
            shard.shard_id,
            archive_type=models.Post.CHAT,
            nickname='My name',
            user_id='abc',
            body='This will not be replicated')
        posts.apply_posts(shard.shard_id)

        topic_shard_id, change_topic_post = topics.start_topic(
            shard.shard_id, 'my-user-id', 'my-post-id', 'my name',
            'topic title', 'topic description')

        after_shard = shard.key.get()
        self.assertEquals(None, after_shard.current_topic)

        posts.apply_posts(shard.shard_id)

        after_shard = shard.key.get()
        self.assertEquals(topic_shard_id, after_shard.current_topic)

        # The post that caused the topic change will be replicated
        shard_ref_list = list(models.PostReference.query(ancestor=shard.key))
        shard_post_ids = [r.post_id for r in shard_ref_list]
        self.assertEquals([first_post.id(), change_topic_post.id()],
                          shard_post_ids)

        topic_shard = models.Shard.get_by_id(topic_shard_id)
        self.assertEquals(
            None, models.PostReference.query(ancestor=topic_shard.key).get())

        posts.apply_posts(topic_shard_id)

        topic_ref_list = list(models.PostReference.query(
            ancestor=topic_shard.key))
        topic_post_ids = [r.post_id for r in topic_ref_list]
        self.assertEquals([change_topic_post.id()], topic_post_ids)

        # This post is after the topic change and will be replicated
        replicated_post = post_key = posts.insert_post(
            shard.shard_id,
            archive_type=models.Post.CHAT,
            nickname='My name',
            user_id='abc',
            body='Here is my message')

        posts.apply_posts(shard.shard_id)
        posts.apply_posts(topic_shard_id)

        topic_ref_list = list(models.PostReference.query(
            ancestor=topic_shard.key))
        topic_post_ids = [r.post_id for r in topic_ref_list]
        self.assertEquals([change_topic_post.id(), replicated_post.id()],
                          topic_post_ids)
Exemple #2
0
    def start_topic(self, url, nickname, description, shard_id=None):
        """Makes a test topic."""
        if shard_id is None:
            shard_id = self.shard.shard_id

        topic_shard_id, _ = topics.start_topic(
            shard_id,
            self.user_id,
            'my-post-id-%f' % time.time(),
            nickname,
            url,
            description)
        posts.apply_posts(shard_id)
        posts.apply_posts(topic_shard_id)
        return topic_shard_id