예제 #1
0
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
예제 #2
0
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']})
예제 #3
0
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']})
예제 #4
0
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})
예제 #5
0
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})
예제 #6
0
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 == []
예제 #7
0
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
예제 #8
0
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
예제 #9
0
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 == []