Example #1
0
 def test_get_comment(self):
     resp_key = ndb.Key('Response', 'tag:facebook.com,2013:xyz')
     FacebookEmail(id='_',
                   htmls=[COMMENT_EMAIL_USERNAME],
                   response=resp_key).put()
     self.assert_equals(EMAIL_COMMENT_OBJ_USERNAME,
                        self.fea.get_comment('xyz'))
Example #2
0
    def test_good(self):
        self.expect_requests_get(
            'http://foo.com/', """
    <html class="h-feed">
      <div class="h-entry">
        <a class="u-url" href="http://foo.com/post"></a>
        <a class="u-syndication" href="https://www.facebook.com/snarfed.org/posts/123"></a>
      </div>
    </html>""")
        self.mox.ReplayAll()

        self.handler.receive(self.mail)
        self.assert_equals(200, self.response.status_code)

        emails = list(FacebookEmail.query())
        self.assertEquals(1, len(emails))
        self.assert_equals('SMTP-123-xyz', emails[0].key.id())
        self.assert_equals(self.fea.key, emails[0].source)
        self.assert_equals([COMMENT_EMAIL_USERNAME], emails[0].htmls)
        resp_id = EMAIL_COMMENT_OBJ_USERNAME['id']
        self.assert_equals(ndb.Key('Response', resp_id), emails[0].response)

        expected = Response(
            id=resp_id,
            source=self.fea.key,
            type='comment',
            response_json=json.dumps(EMAIL_COMMENT_OBJ_USERNAME),
            activities_json=[
                json.dumps({
                    'id': '123',
                    'numeric_id': '123',
                    'url': 'https://www.facebook.com/212038/posts/123',
                    'author': {
                        'id': 'snarfed.org'
                    },
                })
            ],
            unsent=['http://foo.com/post'])
        self.assert_entities_equal([expected],
                                   list(Response.query()),
                                   ignore=('created', 'updated'))

        tasks = self.taskqueue_stub.GetTasks('propagate')
        self.assertEquals(1, len(tasks))
        self.assert_equals(expected.key.urlsafe(),
                           testutil.get_task_params(tasks[0])['response_key'])

        self.assert_equals(EMAIL_COMMENT_OBJ_USERNAME,
                           self.fea.get_comment('123_789'))
Example #3
0
 def test_get_like(self):
     resp_key = ndb.Key('Response', 'tag:facebook.com,2013:xyz')
     FacebookEmail(id='_', htmls=[LIKE_EMAIL], response=resp_key).put()
     self.assert_equals(EMAIL_LIKE_OBJ, self.fea.get_like('xyz'))