コード例 #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}
    )
コード例 #2
0
ファイル: db_test.py プロジェクト: kevingnapoor/parkit
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},
    )
コード例 #3
0
ファイル: search.py プロジェクト: kevingnapoor/parkit
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})
コード例 #4
0
ファイル: search.py プロジェクト: blampe/parkit
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})