Exemple #1
0
def test_find(mongo_collection):
    """This test is kinda lame.

    If I had more time I would play around with Ming, which provides an
    in-memory instance of Mongo for testing.
    """
    mongo_collection.find().limit.return_value = []

    with mock.patch('parkit.db.dedupe') as dedupe:
        db.find(
            lat=mock.sentinel.LAT,
            lng=mock.sentinel.LNG,
            type=mock.sentinel.TYPE,
            within=mock.sentinel.WITHIN,
            limit=mock.sentinel.LIMIT,
            collection=mongo_collection,
        )
        assert dedupe.called

    mongo_collection.find.assert_called_with(
        {
            'loc': {
                '$near': {
                    '$geometry': {
                        'coordinates': [mock.sentinel.LNG, mock.sentinel.LAT],
                        'type': 'Point'
                    },
                    '$maxDistance': mock.sentinel.WITHIN
                }
            },
            'type': mock.sentinel.TYPE
        },
        {'_id': False}
    )
Exemple #2
0
def test_find(mongo_collection):
    """This test is kinda lame.

    If I had more time I would play around with Ming, which provides an
    in-memory instance of Mongo for testing.
    """
    mongo_collection.find().limit.return_value = []

    with mock.patch("parkit.db.dedupe") as dedupe:
        db.find(
            lat=mock.sentinel.LAT,
            lng=mock.sentinel.LNG,
            type=mock.sentinel.TYPE,
            within=mock.sentinel.WITHIN,
            limit=mock.sentinel.LIMIT,
            collection=mongo_collection,
        )
        assert dedupe.called

    mongo_collection.find.assert_called_with(
        {
            "loc": {
                "$near": {
                    "$geometry": {"coordinates": [mock.sentinel.LNG, mock.sentinel.LAT], "type": "Point"},
                    "$maxDistance": mock.sentinel.WITHIN,
                }
            },
            "type": mock.sentinel.TYPE,
        },
        {"_id": False},
    )
Exemple #3
0
def get_search():
    schema = SearchRequestSchema()

    try:
        params = schema.deserialize(request.args.items())
    except colander.Invalid:
        # TODO: need more helpful errors here!
        return abort(httplib.BAD_REQUEST)

    results = db.find(**params)

    return jsonify({'results': results})
Exemple #4
0
def get_search():
    schema = SearchRequestSchema()

    try:
        params = schema.deserialize(request.args.items())
    except colander.Invalid:
        # TODO: need more helpful errors here!
        return abort(httplib.BAD_REQUEST)

    results = db.find(**params)

    return jsonify({'results': results})