예제 #1
0
 def test_tweet_not_mentioning_twitterbot(self):
     self.tweet['entities']['user_mentions'] = []
     handler = OfficerTweetHandler(event_data=self.tweet,
                                   for_user_id=123,
                                   original_event=None)
     handler.handle()
     self.send_tweet.assert_not_called()
예제 #2
0
    def test_save_log(self):
        self.tweet['text'] = '@CPDPbot Jerome Finnigan'
        self.refresh_index()
        original_event = {
            'tweet_create_events': [{
                'text': '@CPDPbot Jerome Finnigan'
            }],
            'for_user_id': 123
        }
        handler = OfficerTweetHandler(event_data=self.tweet,
                                      for_user_id=123,
                                      original_event=original_event)
        handler.handle()

        response_log = TwitterBotResponseLog.objects.all().first()
        entity_url = f'http://foo.com/officer/1/?twitterbot_log_id={response_log.id}'
        expect(response_log.sources).to.eq('text')
        expect(response_log.entity_url).to.eq(entity_url)
        expect(response_log.tweet_content).to.eq(
            f'@abc Jerome Finnigan has 1 complaints {entity_url}')
        expect(response_log.created_at).to.eq(
            datetime(2017, 8, 3, 12, 0, 1, tzinfo=pytz.utc))
        expect(response_log.incoming_tweet_username).to.eq('abc')
        expect(response_log.incoming_tweet_url).to.eq(
            'https://twitter.com/abc/status/1/')
        expect(response_log.incoming_tweet_content).to.eq(
            '@CPDPbot Jerome Finnigan')
        expect(response_log.original_tweet_username).to.eq('abc')
        expect(response_log.original_tweet_url).to.eq(
            'https://twitter.com/abc/status/1/')
        expect(response_log.original_tweet_content).to.eq(
            '@CPDPbot Jerome Finnigan')
        expect(response_log.original_event_object).to.eq(original_event)
        expect(response_log.status).to.eq(TwitterBotResponseLog.SENT)
예제 #3
0
 def test_tweet_mention_recipients(self, _):
     self.tweet['entities']['user_mentions'] = [{
         'id':
         123,
         'screen_name':
         self.screen_name
     }, {
         'id': 124,
         'screen_name': 'def'
     }]
     self.refresh_index()
     handler = OfficerTweetHandler(event_data=self.tweet,
                                   for_user_id=123,
                                   original_event=None)
     handler.handle()
     entity = {
         'allegation_count': 1,
         'percentiles': [],
         'id': 1,
         'full_name': u'Jerome Finnigan'
     }
     expect(self.send_tweet).to.be.any_call(
         '@abc Jerome Finnigan has 1 complaints http://foo.com/officer/1/?twitterbot_log_id=10',
         in_reply_to=1,
         entity=entity)
     expect(self.send_tweet).to.be.any_call(
         '@def Jerome Finnigan has 1 complaints http://foo.com/officer/1/?twitterbot_log_id=20',
         in_reply_to=1,
         entity=entity)
예제 #4
0
 def test_retweet_twitterbot_status(self):
     self.tweet['retweeted_status'] = {'user': {'id': 123}}
     self.refresh_index()
     handler = OfficerTweetHandler(event_data=self.tweet,
                                   for_user_id=123,
                                   original_event=None)
     handler.handle()
     self.send_tweet.assert_not_called()
예제 #5
0
 def test_tweet_not_found(self, _):
     handler = OfficerTweetHandler(event_data=self.tweet,
                                   for_user_id=123,
                                   original_event=None)
     handler.handle()
     self.send_tweet.assert_called_with(
         'Sorry, @abc, the bot finds nothing http://foo.com?twitterbot_log_id=5',
         in_reply_to=1,
         entity=None)
예제 #6
0
    def test_match_tweet(self, tweet_context):
        handler = OfficerTweetHandler(event_data=None,
                                      for_user_id=123,
                                      original_event=None)
        tweet_context_mock = tweet_context()
        tweet_context_mock.is_unfollow_tweet = False

        expect(handler.match_tweet()).to.be.true()

        tweet_context_mock.is_unfollow_tweet = True

        expect(handler.match_tweet()).to.be.false()
예제 #7
0
    def test_tweet_coaccused_pair(self):
        OfficerAllegationFactory(officer=OfficerFactory(id=2,
                                                        first_name='Raymond',
                                                        last_name='Piwnicki'),
                                 allegation=self.allegation)

        self.refresh_index()
        handler = OfficerTweetHandler(event_data=self.tweet,
                                      for_user_id=123,
                                      original_event=None)
        handler.handle()
        expect(self.send_tweet).to.be.called_with(
            '@abc Jerome Finnigan and Raymond Piwnicki were co-accused in 1 case',
            in_reply_to=1,
            entity=None)
예제 #8
0
 def test_tweet_officer_in_tweet_hashtags(self, _):
     self.tweet['entities']['hashtags'] = [{'text': 'jeromeFinnigan'}]
     self.refresh_index()
     handler = OfficerTweetHandler(event_data=self.tweet,
                                   for_user_id=123,
                                   original_event=None)
     handler.handle()
     expect(self.send_tweet).to.be.called_with(
         '@abc Jerome Finnigan has 1 complaints http://foo.com/officer/1/?twitterbot_log_id=10',
         in_reply_to=1,
         entity={
             'allegation_count': 1,
             'percentiles': [],
             'id': 1,
             'full_name': u'Jerome Finnigan'
         })
예제 #9
0
 def test_tweet_officer_in_retweet_tweet(self, _):
     retweeted_status = {
         'id': 2,
         'user': {
             'id': 456,
             'screen_name': 'def'
         },
         'text': '',
         'in_reply_to_status_id': None,
         'retweeted_status': None,
         'quoted_status': None,
         'quoted_status_id': None,
         'created_at': '2017-08-03T11:59:00Z',
         'entities': {
             'user_mentions': [{
                 'id': 123,
                 'screen_name': self.screen_name
             }],
             'hashtags': [],
             'urls': []
         }
     }
     self.tweet['retweeted_status'] = retweeted_status
     self.client.register(
         TweetContext(original_tweet=retweeted_status,
                      context={'client': self.client}))
     self.refresh_index()
     handler = OfficerTweetHandler(event_data=self.tweet,
                                   for_user_id=123,
                                   original_event=None)
     handler.handle()
     entity = {
         'allegation_count': 1,
         'percentiles': [],
         'id': 1,
         'full_name': u'Jerome Finnigan'
     }
     expect(self.send_tweet).to.be.any_call(
         '@abc Jerome Finnigan has 1 complaints http://foo.com/officer/1/?twitterbot_log_id=10',
         in_reply_to=2,
         entity=entity)
     expect(self.send_tweet).to.be.any_call(
         '@def Jerome Finnigan has 1 complaints http://foo.com/officer/1/?twitterbot_log_id=20',
         in_reply_to=2,
         entity=entity)
예제 #10
0
 def test_tweet_officer_in_tweet_text(self, _):
     self.tweet['text'] = '@CPDPbot Jerome Finnigan'
     self.refresh_index()
     handler = OfficerTweetHandler(event_data=self.tweet,
                                   for_user_id=123,
                                   original_event=None)
     handler.handle()
     expect(self.send_tweet).to.be.called_with(
         '@abc Jerome Finnigan has 1 complaints http://foo.com/officer/1/?twitterbot_log_id=10',
         in_reply_to=1,
         entity={
             'allegation_count': 1,
             'percentiles': [],
             'id': 1,
             'full_name': u'Jerome Finnigan'
         })
     expect(ActivityCard.objects.get(
         officer=self.officer).last_activity).to.eq(
             datetime(2017, 8, 3, 12, 0, 1, tzinfo=pytz.utc))
예제 #11
0
 def test_tweet_officer_in_tweet_link_content(self, _):
     self.tweet['entities']['urls'] = [{
         'expanded_url': 'http://fakeurl.com'
     }]
     with patch('twitterbot.utils.web_parsing.parse',
                return_value='Chicago Police Jerome Finnigan'):
         self.refresh_index()
         handler = OfficerTweetHandler(event_data=self.tweet,
                                       for_user_id=123,
                                       original_event=None)
         handler.handle()
         expect(self.send_tweet).to.be.called_with(
             '@abc Jerome Finnigan has 1 complaints http://foo.com/officer/1/?twitterbot_log_id=10',
             in_reply_to=1,
             entity={
                 'allegation_count': 1,
                 'percentiles': [],
                 'id': 1,
                 'full_name': u'Jerome Finnigan'
             })