示例#1
0
    def testManyTopicsManyPosts(self):
        """Tests when many topics have many new posts."""
        self.login_user()

        topic_shard_id = self.start_topic(
            'http://www.example.com/path/is/here',
            'cilantro',
            'This is my long winded topic description that surely will '
            'bore you to tears')

        self.make_post('first', 'my message 1')
        self.make_post('second', 'my other message')
        self.make_post('third', 'message number 3')
        posts.apply_posts(topic_shard_id)

        topic_shard_id = self.start_topic(
            'http://www.example.com/this/is/another/topic',
            'lime',
            'Wow I never thought I would be starting my own topic')

        self.make_post('red', 'this is for a new topic')
        self.make_post('green', 'and will continue')
        posts.apply_posts(topic_shard_id)

        send_email.send_digest_email('*****@*****.**', 1)

        message = self.get_email()

        self.assertEquals('8-bits of ephemera <test-app.appspotmail.com>',
                          message.sender)
        self.assertEquals("What's new: 2 topics, 7 updates",
                          message.subject)
示例#2
0
    def testMultipleShards(self):
        """Tests when the user is part of multiple shards."""
        shard1 = models.Shard(id='my-shard-1')
        shard1.put()
        shard2 = models.Shard(id='my-shard-2')
        shard2.put()

        self.login_user('my-shard-1')
        self.login_user('my-shard-2')

        topic_id = self.start_topic(
            'http://example.com/1', 'peanut', 'hi there',
            shard_id='my-shard-1')
        self.make_post('first', 'my message here', shard_id='my-shard-1')
        posts.apply_posts(topic_id)

        topic_id = self.start_topic(
            'http://example.com/2', 'cashew', 'this is nuts!',
            shard_id='my-shard-2')
        self.make_post('second', 'my second here', shard_id='my-shard-2')
        self.make_post('third', 'my third here', shard_id='my-shard-2')
        posts.apply_posts(topic_id)

        send_email.send_digest_email('*****@*****.**', 1)

        message = self.get_email()

        self.assertEquals('8-bits of ephemera <test-app.appspotmail.com>',
                          message.sender)
        self.assertEquals("What's new: 2 topics, 5 updates",
                          message.subject)
示例#3
0
    def testMultiple(self):
        """Tests inserting multiple posts and applying them together."""
        shard = models.Shard(id='my-shard-name')
        shard.put()

        post_key_list = []
        for i in xrange(5):
            post_key_list.append(posts.insert_post(
                shard.shard_id,
                post_id='my-id-%d' % i,
                archive_type=models.Post.CHAT,
                nickname='My name',
                user_id='abc',
                body='Here is my message %d' % i))

        self.assertEquals(5, models.Post.query().count())
        self.assertEquals(None, models.PostReference.query().get())

        posts.apply_posts(shard.shard_id)
        ref_list = list(models.PostReference.query())
        ref_ids = [r.key.id() for r in ref_list]
        self.assertEquals([1, 2, 3, 4, 5], ref_ids)

        receipt_list = list(models.Receipt.query())
        receipt_parents = [r.key.parent() for r in receipt_list]
        self.assertEquals(post_key_list, receipt_parents)

        shard_after = shard.key.get()
        self.assertEquals(6, shard_after.sequence_number)
示例#4
0
    def testNotifyTwiceNoChanges(self):
        """Tests that notifying when there are no changes sends no email."""
        self.login_user()

        topic_shard_id = self.start_topic(
            'http://www.example.com/path/is/here',
            'cilantro',
            'This is my long winded topic description that surely will '
            'bore you to tears')

        self.make_post('first', 'my message 1')
        posts.apply_posts(topic_shard_id)

        send_email.send_digest_email('*****@*****.**', 1)
        message = self.get_email()

        self.assertEquals('8-bits of ephemera <test-app.appspotmail.com>',
                          message.sender)
        self.assertEquals("What's new: 1 topic, 2 updates",
                          message.subject)

        send_email.send_digest_email('*****@*****.**', 1)

        mail_stub = self.testbed.get_stub(testbed.MAIL_SERVICE_NAME)
        message_list = mail_stub.get_sent_messages()
        self.assertEquals(1, len(message_list))  # One email, not two
示例#5
0
    def testSingle(self):
        """Tests successfully inserting and applying a single Post."""
        shard = models.Shard(id='my-shard-name')
        shard.put()

        post_key = posts.insert_post(
            shard.shard_id,
            post_id='my-id-1234',
            archive_type=models.Post.CHAT,
            nickname='My name',
            user_id='abc',
            body='Here is my message')

        found_post = models.Post.query().get()
        self.assertEquals(post_key, found_post.key)

        self.assertEquals(None, models.PostReference.query().get())
        self.assertEquals(None, models.Receipt.query().get())

        posts.apply_posts(shard.shard_id)

        found_ref = models.PostReference.query().get()
        self.assertEquals(1, found_ref.key.id())
        self.assertEquals(found_post.post_id, found_ref.post_id)

        found_receipt = models.Receipt.query().get()
        self.assertEquals(post_key, found_receipt.key.parent())

        shard_after = shard.key.get()
        self.assertEquals(2, shard_after.sequence_number)
示例#6
0
    def testReceiptExists(self):
        """Tests that post receipts prevent duplicate PostReferences."""
        shard = models.Shard(id='my-shard-name')
        shard.put()

        already_posted_key = posts.insert_post(
            shard.shard_id,
            post_id='my-id-1234',
            archive_type=models.Post.CHAT,
            nickname='My name',
            user_id='abc',
            body='Here is my message')

        models.Receipt(id=shard.shard_id, parent=already_posted_key).put()

        new_post_key = posts.insert_post(
            shard.shard_id,
            post_id='my-id-7890',
            archive_type=models.Post.CHAT,
            nickname='My name',
            user_id='abc',
            body='My second message')

        posts.apply_posts(shard.shard_id)

        ref_list = list(models.PostReference.query())
        self.assertEquals(1, len(ref_list))
        found_ref = ref_list[0]
        self.assertEquals(new_post_key.id(), found_ref.post_id)
示例#7
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)
示例#8
0
    def make_post(self, post_id, message, shard_id=None):
        """Makes a test post."""
        if shard_id is None:
            shard_id = self.shard.shard_id

        post_key = posts.insert_post(
            shard_id,
            post_id=post_id,
            archive_type=models.Post.CHAT,
            nickname='My name',
            user_id=self.user_id,
            body=message)
        posts.apply_posts(shard_id)
        return post_key
示例#9
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
示例#10
0
    def testOneTopicNewPost(self):
        """Tests when a single topic has a new post."""
        self.login_user()

        topic_shard_id = self.start_topic(
            'http://www.example.com/path/is/here',
            'cilantro',
            'This is my long winded topic description that surely will '
            'bore you to tears')

        self.make_post('first', 'my message 1')
        posts.apply_posts(topic_shard_id)

        send_email.send_digest_email('*****@*****.**', 1)

        message = self.get_email()

        self.assertEquals('8-bits of ephemera <test-app.appspotmail.com>',
                          message.sender)
        self.assertEquals("What's new: 1 topic, 2 updates",
                          message.subject)
示例#11
0
    def testChannelMessage(self):
        """Tests that post and apply both send message updates."""
        shard = models.Shard(id='my-shard-name')
        shard.put()

        channel_stub = self.testbed.get_stub(testbed.CHANNEL_SERVICE_NAME)
        user_id = 'my-user-id'
        presence.user_logged_in(shard.shard_id, user_id)
        _, browser_token = presence.change_presence(
            shard.shard_id, user_id, 'name here', True, True, False)
        channel_stub.connect_channel(browser_token)

        # This clears the presence Post from change_presence()
        posts.apply_posts(shard.shard_id)
        channel_stub.pop_first_message(browser_token)

        post_key = posts.insert_post(
            shard.shard_id,
            archive_type=models.Post.CHAT,
            nickname='My name',
            user_id='abc',
            body='Here is my message')

        message = channel_stub.pop_first_message(browser_token)
        found_posts = json.loads(message)['posts']
        post = post_key.get()
        expected_posts = posts.marshal_posts(shard.shard_id, [post])
        self.assertEquals(expected_posts, found_posts)
        self.assertEquals(None, expected_posts[0]['sequenceId'])

        posts.apply_posts(shard.shard_id)
        post = post_key.get()
        message = channel_stub.pop_first_message(browser_token)
        found_posts = json.loads(message)['posts']
        self.assertEquals(2, found_posts[0]['sequenceId'])
        post = post_key.get()
        post.sequence = 2  # Pretend to do what apply_posts does
        expected_posts = posts.marshal_posts(shard.shard_id, [post])
        self.assertEquals(expected_posts, found_posts)