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)
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)
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
def testNoTopics(self): """Tests sending the digest email when there are no topics.""" self.make_post('first', 'my message 1') 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(0, len(message_list))
def testRootShardOnly(self): """Tests when only the root shard has new data.""" self.login_user() self.make_post('first', 'my message 1') 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, 1 update", message.subject)
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)
def testMultipleRootShardsOnly(self): """Tests multiple root shards have new data with no topics.""" shard1 = models.Shard(id='my-shard-1') shard1.put() shard2 = models.Shard(id='my-shard-2') shard2.put() self.login_user(shard1.shard_id) self.login_user(shard2.shard_id) self.make_post('first', 'my message 1', shard_id=shard1.shard_id) self.make_post('second', 'my message 2', shard_id=shard2.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, 2 updates", message.subject)