Пример #1
0
    def test_init_no_id(self):
        twitter = Twitter(last_direct_message_id='1', last_status_id='2')

        self.assertIsNotNone(twitter)
        self.assertIsNone(twitter.id)
        self.assertEqual('1', twitter.last_direct_message_id)
        self.assertEqual('2', twitter.last_status_id)
        self.assertEqual({
            'last_direct_message_id': '1',
            'last_status_id': '2'
        }, twitter.to_document())
Пример #2
0
 def test_repr_no_id(self):
     twitter1 = Twitter.from_document({
         'last_direct_message_id': '1',
         'last_status_id': '2'
     })
     self.assertEquals(
         "<Twitter(id='n/a', last_direct_message_id='1', last_status_id='2')>",
         str(twitter1))
Пример #3
0
 def test_from_document_no_id(self):
     twitter1 = Twitter.from_document({
         'last_direct_message_id': '1',
         'last_status_id': '2'
     })
     self.assertIsNone(twitter1.id)
     self.assertEqual('1', twitter1.last_direct_message_id)
     self.assertEqual('2', twitter1.last_status_id)
Пример #4
0
 def test_repr_with_id(self):
     twitter2 = Twitter.from_document({
         '_id': '666',
         'last_direct_message_id': '1',
         'last_status_id': '2'
     })
     self.assertEquals(
         "<Twitter(id='666', last_direct_message_id='1', last_status_id='2')>",
         str(twitter2))
Пример #5
0
 def test_from_document_with_id(self):
     twitter2 = Twitter.from_document({
         '_id': '666',
         'last_direct_message_id': '1',
         'last_status_id': '2'
     })
     self.assertIsNotNone(twitter2)
     self.assertIsNotNone(twitter2.id)
     self.assertEqual('666', twitter2.id)
     self.assertEqual('1', twitter2.last_direct_message_id)
     self.assertEqual('2', twitter2.last_status_id)
Пример #6
0
    def store_last_message_ids(self, last_direct_message_id, last_status_id):
        YLogger.info(self, "Storing last message ids (%s, %s) to Mongo",
                     last_direct_message_id, last_status_id)

        collection = self.collection()
        twitter = collection.find_one({})
        if twitter is not None:
            twitter.last_direct_message_id = last_direct_message_id
            twitter.last_status_id = last_status_id
            collection.update(twitter)
        else:
            twitter = Twitter(last_direct_message_id, last_status_id)
            self.add_document(twitter)
Пример #7
0
    def store_last_message_ids(self, last_direct_message_id, last_status_id):
        YLogger.info(self, "Storing last message ids (%s, %s) to Mongo",
                     last_direct_message_id, last_status_id)

        collection = self.collection()
        twitter = collection.find_one({})
        if twitter is not None:
            twitter['last_direct_message_id'] = last_direct_message_id
            twitter['last_status_id'] = last_status_id
            result = collection.replace_one({'_id': twitter['_id']}, twitter)
            return bool(result.modified_count > 0)

        else:
            twitter = Twitter(last_direct_message_id, last_status_id)
            return self.add_document(twitter)