def handle(self, interpreted_tweet): state = messages.NOT_FOUND_STATE if post_type.id_to_label(interpreted_tweet.event_type()) != 'delete': state = messages.CURRENT_STATE event_message = messages.create_event_message( 'twitter', self.author_service_map.author_id, state, self.author_service_map.service_author_id, interpreted_tweet.event_id(), interpreted_tweet.json, []) self._send_message(event_message) if self.write_date: self._update_database( self.author_service_map.id, datetime.datetime.utcnow(), interpreted_tweet.event_id(), interpreted_tweet.created_time()) else: self.last_update_time = datetime.datetime.utcnow() self.most_recent_event_id = interpreted_tweet.event_id() self.most_recent_event_timestamp = interpreted_tweet.created_time()
def test_create_event_message(self): services = ['facebook', 'twitter', 'instagram', 'foursquare', 'linkedin'] tim_author_id = 1234 service_user_id = 'service_user_id' service_event_id = '987654321' service_link_name = 'instagram' service_link_event_id = '543216789' json_dict = {'key': 'value'} for service in services: message = messages.create_event_message( service, tim_author_id, messages.CURRENT_STATE, service_user_id, service_event_id, json_dict, [messages.create_event_link(service_link_name, service_link_event_id)]) self.assertEqual(message['header']['type'], service + '.event') self.assertEqual(message['message']['tim_author_id'], tim_author_id) self.assertEqual(message['message']['state'], messages.CURRENT_STATE) self.assertEqual(message['message']['service_author_id'], service_user_id) self.assertEqual(message['message']['service_event_id'], service_event_id) self.assertEqual(message['message']['service_event_json'], json_dict) self.assertEqual(message['message']['links'][0]['service_id'], service_link_name) self.assertEqual(message['message']['links'][0]['service_event_id'], service_link_event_id)