def test_track_updated_when_accessed(mock_pymongo): sampleDrop = get_sample_drop() mock_pymongo.dead.drop.find_one_and_delete.return_value = sampleDrop dead = DropHandler(mock_pymongo) val = dead.pickup(sampleDrop['key']) mock_pymongo.dead.track.update.assert_called_with({"key": sampleDrop['key']}, {"$set":{"pickedUp":datetime.datetime(2012, 1, 14)},"$unset":{"key":""}}) assert sampleDrop["data"] == val
def test_return_none_when_not_existing(mock_pymongo): sampleDrop = get_sample_drop() mock_pymongo.dead.drop.find_one_and_delete.return_value=[] dead = DropHandler(mock_pymongo) val = dead.pickup(sampleDrop['key']) assert val == [] mock_pymongo.dead.drop.find_one_and_delete.assert_called_with({"key": sampleDrop['key']})
def test_return_none_when_not_existing(mock_pymongo): """See if none is returned if drop doesn't exist.""" sample_drop = get_sample_drop() mock_pymongo.dead.drop.find_one_and_delete.return_value = [] dead = DropHandler(mock_pymongo) val = dead.pickup(sample_drop['key']) assert val == [] mock_pymongo.dead.drop.find_one_and_delete.assert_called_with( {'key': sample_drop['key']})
def test_drop_deleted_and_not_returned_when_24hours_old(mock_pymongo): key = "anything" sampleDrop = get_sample_drop() sampleDrop["createdDate"] = datetime.datetime(2012, 1, 12) mock_pymongo.dead.drop.find.return_value=[sampleDrop] dead = DropHandler(mock_pymongo) val = dead.pickup(key) assert val == [] mock_pymongo.dead.drop.find_one_and_delete.assert_called_with({"key": key})
def test_drop_deleted_and_not_returned_when_24hours_old(mock_pymongo): """See if drop is returned when it's more than 24 h old.""" key = "anything" sample_drop = get_sample_drop() sample_drop['createdDate'] = datetime.datetime(2012, 1, 12) mock_pymongo.dead.drop.find.return_value = [sample_drop] dead = DropHandler(mock_pymongo) val = dead.pickup(key) assert val == [] mock_pymongo.dead.drop.find_one_and_delete.assert_called_with({'key': key})
def test_drop_not_retruned_when_no_create_date(mock_pymongo): # to handle old drops sampleDrop = get_sample_drop() sampleDrop.pop('createdDate') mock_pymongo.dead.drop.find_one_and_delete.return_value=sampleDrop dead = DropHandler(mock_pymongo) val = dead.pickup(sampleDrop['key']) pprint.pprint(sampleDrop) pprint.pprint(val) mock_pymongo.dead.drop.find_one_and_delete.assert_called_with({"key": sampleDrop['key']}) assert val == []
def test_drop_deleted_when_accessed(mock_pymongo): sampleDrop = get_sample_drop() mock_pymongo.dead.drop.find_one_and_delete.return_value=sampleDrop dead = DropHandler(mock_pymongo) import pprint pprint.pprint("XXXXX") pprint.pprint(sampleDrop) val = dead.pickup(sampleDrop['key']) pprint.pprint(val) mock_pymongo.dead.drop.find_one_and_delete.assert_called_with({"key": sampleDrop['key']}) assert sampleDrop["data"] == val
def test_drop_deleted_when_accessed(mock_pymongo): """See if drop is deleted properly when accessed.""" sample_drop = get_sample_drop() mock_pymongo.dead.drop.find_one_and_delete.return_value = sample_drop dead = DropHandler(mock_pymongo) pprint.pprint("XXXXX") pprint.pprint(sample_drop) val = dead.pickup(sample_drop['key']) pprint.pprint(val) mock_pymongo.dead.drop.find_one_and_delete.assert_called_with( {'key': sample_drop['key']}) assert sample_drop['data'] == val
def test_drop_not_returned_when_no_create_date(mock_pymongo): """See if drop is returned when there's no create date.""" # (to handle old drops) sample_drop = get_sample_drop() sample_drop.pop('createdDate') mock_pymongo.dead.drop.find_one_and_delete.return_value = sample_drop dead = DropHandler(mock_pymongo) val = dead.pickup(sample_drop['key']) pprint.pprint(sample_drop) pprint.pprint(val) mock_pymongo.dead.drop.find_one_and_delete.assert_called_with( {'key': sample_drop['key']}) assert val == []