Exemplo n.º 1
0
def test_get_recomputation():
    log = logging.getLogger()
    mock_collection = mock.MagicMock()
    expected_recomputation = json.loads(FOO_RECOMPUTATION_STR)
    mock_collection.find_one.return_value = expected_recomputation
    results = recompute.get_recomputation(mock_collection, "551bdd701c8a97e78635a911", log)

    # Assert with a valid Object Id
    mock_collection.find_one.assert_called_with({'_id': ObjectId('551bdd701c8a97e78635a911')})
    assert results == expected_recomputation

    # Assert with invalid ObjectId and raised exception
    with pytest.raises(ValueError) as excinfo:
        recompute.get_recomputation(mock_collection, "33", log)
    assert 'Invalid Object Id used' in str(excinfo.value)
Exemplo n.º 2
0
def test_update_status():
    log = logging.getLogger()
    mock_collection = mock.MagicMock()
    timestamp = datetime.now()
    recompute.update_status(mock_collection, "551bdd701c8a97e78635a911", "FOO", timestamp, log)

    query_id = {'_id': ObjectId('551bdd701c8a97e78635a911')}
    query_update = {'$set': {'s': 'FOO'}, '$push': {'history': {'status': 'FOO', 'ts': timestamp}}}

    # Assert with a valid Object Id
    mock_collection.update.assert_called_with(query_id, query_update)

    # Assert with invalid ObjectId and raised exception
    with pytest.raises(ValueError) as excinfo:
        recompute.get_recomputation(mock_collection, "33", log)
    assert 'Invalid Object Id used' in str(excinfo.value)
Exemplo n.º 3
0
def test_get_recomputation():
    log = logging.getLogger()
    mock_collection = mock.MagicMock()
    expected_recomputation = json.loads(FOO_RECOMPUTATION_STR)
    mock_collection.find_one.return_value = expected_recomputation
    results = recompute.get_recomputation(mock_collection, "551bdd701c8a97e78635a911", log)

    # Assert with a valid Object Id
    mock_collection.find_one.assert_called_with({"id": "551bdd701c8a97e78635a911"})
    assert results == expected_recomputation