def test_get_articles_default_start(): collection = MongoClient().db.collection collection.insert_many([{ '_id': 'tw:abc', 'label': 's***e', 'added': datetime.utcnow() }, { '_id': 'ge:boo', 'added': datetime(1971, 1, 1) }]) assert len(list(get_articles(collection))) == 2
def test_get_articles_with_regex(): collection = MongoClient().db.collection collection.insert_many([{ '_id': 'tw:abc', 'added': datetime.utcnow(), 'foo': 'bar' }, { '_id': 'ge:dbc', 'added': datetime.utcnow(), 'foo': 'bar' }]) assert len(list(get_articles(collection, src='tw'))) == 1 assert len(list(get_articles(collection, src='ge'))) == 1 assert len(list(get_articles(collection))) == 2
def test_get_articles_with_label(): collection = MongoClient().db.collection collection.insert_many([{ '_id': 'tw:abc', 'label': 's***e', 'added': datetime.utcnow() }, { '_id': 'ge:dbc', 'added': datetime.utcnow() }, { '_id': 'ge:boo', 'added': datetime.utcnow() }]) assert len(list(get_articles(collection, False))) == 2 assert len(list(get_articles(collection, True))) == 1 assert len(list(get_articles(collection))) == 3
def test_get_articles_up_to_is_strictly_greater(): date_from = datetime.now() - timedelta(weeks=1) old_item = datetime.now() - timedelta(weeks=2) collection = MongoClient().db.collection collection.insert_many([{ '_id': 'tw:abc', 'label': 's***e', 'added': datetime.utcnow() }, { '_id': 'ge:boo', 'added': old_item }]) assert len(list(get_articles(collection, date_start=old_item))) == 2 assert len(list(get_articles(collection, date_end=old_item))) == 0 assert len( list(get_articles(collection, date_start=old_item, date_end=date_from))) == 1