def test_sort_by_date(self): data_1 = { 'text_norm': 'foo', 'created_at': create_utc_date(2017, 1, 1) } data_2 = { 'text_norm': 'foo bar', 'created_at': create_utc_date(2017, 1, 2) } self.db.tweets.insert_many([data_1, data_2]) self.assertEqual(['foo bar', 'foo'], [d['text_norm'] for d in self.search('foo')])
def test(self): subdoc_1 = {'foo': 1} subdoc_2 = {'bar': 2} doc_1 = { 'document': json.dumps(subdoc_1), 'created_at': create_utc_date(year=2017, month=1, day=1) } doc_2 = { 'document': json.dumps(subdoc_2), 'created_at': create_utc_date(year=2017, month=1, day=2) } self.db.tfidf_documents.insert_many([doc_1, doc_2]) result = database.get_documents( create_utc_date(year=2017, month=1, day=2)) self.assertEqual([subdoc_2], result)
def test_document_is_saved_as_json(self): document = {'.': 1} created_at = create_utc_date(year=2017, month=1, day=1) database.save_document(document, created_at) self.assertTrue( self.db.tfidf_documents.find({ 'document': json.dumps(document) }).count())
def test_timezone_converted(self): expected = create_utc_date(year=2017, month=1, day=1, hour=1, minute=1, second=1) self.assertEqual( expected, database.convert_tweet_date('Fri Jan 01 10:01:01 +0900 2017'))
def test_lower_case(self): self.db.tweets.insert_one({ 'text': 'bAr', 'text_norm': 'bar', 'user': {'name': 'qux'}, 'created_at': create_utc_date(2017, 1, 1)}) resp = self.app.post('/search', data={'search-query': 'bAR'}) result = json.loads(resp.data.decode('utf-8')) self.assertEqual(1, len(result)) self.assertEqual('bAr', result[0]['text'])
def test_search(self): self.db.tweets.insert_one({ 'text': '@foo bar', 'text_norm': 'bar', 'user': {'name': 'qux'}, 'created_at': create_utc_date(2017, 1, 1)}) resp = self.app.post('/search', data={'search-query': 'bar'}) result = json.loads(resp.data.decode('utf-8')) self.assertEqual(1, len(result)) self.assertEqual([{'user': '******', 'text': '@foo bar', 'created_at': 1483228800}], result)
def test_data_saved(self): database.save_tweet(self.data) t = self.db.tweets.find()[0] self.assertEqual('tweet_id', t['id']) self.assertEqual('@foo bar', t['text']) self.assertEqual('bar', t['text_norm']) self.assertEqual('bob', t['user']['name']) self.assertEqual('123456', t['user']['id']) self.assertEqual('realBob', t['user']['screen_name']) self.assertEqual('https://a.com', t['user']['profile_image_url']) self.assertEqual('<a>Twitter for iPhone</a>', t['source']) self.assertEqual(1, t['favorite_count']) self.assertEqual(2, t['retweet_count']) expected = create_utc_date(year=2017, month=7, day=7, hour=11, minute=35, second=39) self.assertEqual(expected, t['created_at'])
def test(self): data = {'text': 'foo bar baz', 'user': {'name': 'bob'}, 'created_at': create_utc_date(2017, 1, 1, 0, 0, 0)} expected = [{'text': 'foo bar baz', 'user': '******', 'created_at': 1483228800}] self.assertEqual(expected, web.prepare_search_results([data], 100))