コード例 #1
0
 def test_process_post_text_no_fr(self, rpush_mock, set_post_mock,
         incr_mock):
     self.trends.db = db.Db()
     self.trends.stats_last_update = 0
     post = {'text': 'par the test'}
     self.trends.process_post(post)
     self.assertFalse(rpush_mock.called)
     self.assertFalse(set_post_mock.called)
     self.assertFalse(incr_mock.called)
コード例 #2
0
 def test_update_stats_key_not_exists(self, exists_mock, set_mock,
         fill_stats_mock, time_mock):
     exists_mock.return_value = False
     t = 1339987262.1
     time_mock.return_value = t
     self.trends.db = db.Db()
     self.trends.update_stats()
     fill_stats_mock.assert_called_once_with(1)
     self.assertEqual(self.trends.stats_last_update, 1339984800)
     set_mock.assert_called_once_with('statsFirstUpdate', 1339984800)
コード例 #3
0
 def test_update_person_stats(self, lset_mock):
     self.trends.db = db.Db()
     person = {'id': 2}
     posts_count_key = 'person:%d:posts_count' % (person['id'])
     rel_key = 'person:1:rel'
     self.trends.first_person = {'id': 1}
     self.trends.update_person_stats(person)
     self.assertEqual(lset_mock.call_args_list,
         [call(posts_count_key, -1, '2'),
          call(rel_key, -1, json.dumps({'2': 3, '3': 3}))])
コード例 #4
0
 def test_update_person_stats_first_person_none(self, lindex_mock,
         lset_mock):
     self.trends.db = db.Db()
     person = {'id': 1}
     key = 'person:%d:posts_count' % (person['id'])
     lindex_mock.return_value = 1
     self.trends.first_person = None
     self.trends.update_person_stats(person)
     lindex_mock.assert_called_once_with(key, -1)
     lset_mock.assert_called_once_with(key, -1, '2')
     self.assertIs(self.trends.first_person, person)
コード例 #5
0
 def test_update_stats_key_exists(self, exists_mock, get_mock,
         fill_stats_mock, time_mock):
     exists_mock.return_value = True
     t = 1.1
     get_mock.return_value = t
     time_mock.return_value = t + 3600
     key = 'statsLastUpdate'
     self.trends.db = db.Db()
     self.trends.update_stats()
     get_mock.assert_called_once_with(key)
     fill_stats_mock.assert_called_once_with(2)
     self.assertEqual(self.trends.stats_last_update, int(t))
コード例 #6
0
 def setUp(self):
     self.db = db.Db()
     self.cfg_mysql_host = 'test_mysql_host'
     self.cfg_mysql_user = '******'
     self.cfg_mysql_password = '******'
     self.cfg_mysql_db = 'test_mysql_db'
     self.cfg_twitter_userid = 'test_twitter_userid'
     self.cfg_twitter_password = '******'
     self.cfg_redis_host = 'test_redis_host'
     self.cfg_redis_port = 1
     self.cfg_rabbitmq_host = 'test_rabbitmq_host'
     self.cfg_rabbitmq_userid = 'test_rabbitmq_userid'
     self.cfg_rabbitmq_password = '******'
コード例 #7
0
 def test_process_post_names_not_found(self, rpush_mock, set_post_mock,
         incr_mock):
     self.trends.persons = [
         {'name': 'name_1', 'first_name': 'first_name_1',
          'nickname': 'nickname_1', 'id': 2, 'words': ()},
         {'name': 'name_2', 'first_name': 'first_name_2',
          'nickname': 'nickname_2', 'id': 2, 'words': ()}]
     self.trends.db = db.Db()
     self.trends.stats_last_update = 0
     post = {'text': 'test'}
     self.trends.process_post(post)
     self.assertFalse(rpush_mock.called)
     self.assertFalse(set_post_mock.called)
     self.assertFalse(incr_mock.called)
コード例 #8
0
 def test_fill_stats(self, rpush_mock, set_mock):
     periods = 2
     self.trends.persons = [{'id': 2}, {'id': 3}]
     self.trends.stats_last_update = 0
     self.trends.db = db.Db()
     self.trends.fill_stats(periods)
     self.assertEqual(rpush_mock.call_args_list,
         [call('person:2:posts_count', 0),
          call('person:2:rel', json.dumps({})),
          call('person:3:posts_count', 0),
          call('person:3:rel', json.dumps({})),
          call('person:2:posts_count', 0),
          call('person:2:rel', json.dumps({})),
          call('person:3:posts_count', 0),
          call('person:3:rel', json.dumps({}))])
     self.assertEqual = self.trends.stats_last_update = 7200
     set_mock.assert_called_once_with('statsLastUpdate', 7200)
コード例 #9
0
 def test_process_post_names_found_1(self, rpush_mock, set_post_mock,
         incr_mock, time_mock, update_person_stats_mock):
     incr_mock.return_value = 3
     time_mock.return_value = 3600
     self.trends.persons = [
         {'name': 'name_1', 'first_name': 'first_name_1',
          'nickname': 'nickname_1', 'id': 2, 'words': ()},
         {'name': 'name_2', 'first_name': 'first_name_2',
          'nickname': 'nickname_2', 'id': 2, 'words': ()}]
     self.trends.db = db.Db()
     self.trends.stats_last_update = 0
     post = {'text': 'a name_2 worda b', 'msg': 'msg'}
     self.trends.process_post(post)
     incr_mock.assert_called_once_with('nextPostId')
     update_person_stats_mock.assert_called_once_with(
         self.trends.persons[1])
     self.assertEqual(rpush_mock.call_args_list,
         [call('person:2:posts:0', 3),
          call('posts:0', 3)])
     set_post_mock.assert_called_once_with(3,
         '{"msg": "msg", "text": "a name_2 worda b"}')