# Path: dopplr/solr/responsemapper.py
# def detailed_response_mapper(solr_response):
#     """
#     Response mapper that also extracts the returned facets into a dict. In
#     order to keep the sort order, a separate list contains the keys for the
#     facet dictionary in sorted order.
#     """
#     result = {
#         'docs': [],
#         'numFound': 0
#     }
# 
#     if 'response' in solr_response:
#         result['numFound'] = solr_response['response']['numFound']
#         result['docs'] = solr_response['response']['docs']
# 
#     if 'facet_counts' in solr_response:
# 
#         result['facet'] = {}
#         facets = solr_response['facet_counts']
# 
#         if 'facet_fields' in facets:
#             result['facet']['field'] = rf = {}
#             for field in facets['facet_fields']:
#                 rf[field] = _flatten_to_dict(facets['facet_fields'][field])
# 
#         if 'facet_queries' in facets:
#             result['facet']['query'] = rq = {}
#             for query in facets['facet_queries']:
#                 rq[query] = _flatten_to_dict(facets['facet_queries'][query])
# 
#         if 'facet_ranges' in facets:
#             result['facet']['range'] = rr = {}
#             for frange in facets['facet_ranges']:
#                 rr[frange] = \
#                     _flatten_to_dict(facets['facet_ranges'][frange]['counts'])
#                 rr[frange]['start'] = facets['facet_ranges'][frange]['start']
#                 rr[frange]['end'] = facets['facet_ranges'][frange]['end']
#                 rr[frange]['gap'] = facets['facet_ranges'][frange]['gap']
# 
#     return result


import os.path
import json
from pyvows import Vows, expect
from dopplr.solr.responsemapper import detailed_response_mapper
# vim: set fileencoding=utf-8 :
#
# Copyright (c) 2011 Daniel Truemper <truemped at googlemail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#




with open(os.path.join(os.path.dirname(__file__), 'sampleresult.json')) as f:
    SAMPLE_RESULT = json.loads(f.read())


@Vows.batch
class TheDetailedResponseMapper(Vows.Context):

    def topic(self):

# Path: dopplr/solr/responsemapper.py
# def detailed_response_mapper(solr_response):
#     """
#     Response mapper that also extracts the returned facets into a dict. In
#     order to keep the sort order, a separate list contains the keys for the
#     facet dictionary in sorted order.
#     """
#     result = {
#         'docs': [],
#         'numFound': 0
#     }
# 
#     if 'response' in solr_response:
#         result['numFound'] = solr_response['response']['numFound']
#         result['docs'] = solr_response['response']['docs']
# 
#     if 'facet_counts' in solr_response:
# 
#         result['facet'] = {}
#         facets = solr_response['facet_counts']
# 
#         if 'facet_fields' in facets:
#             result['facet']['field'] = rf = {}
#             for field in facets['facet_fields']:
#                 rf[field] = _flatten_to_dict(facets['facet_fields'][field])
# 
#         if 'facet_queries' in facets:
#             result['facet']['query'] = rq = {}
#             for query in facets['facet_queries']:
#                 rq[query] = _flatten_to_dict(facets['facet_queries'][query])
# 
#         if 'facet_ranges' in facets:
#             result['facet']['range'] = rr = {}
#             for frange in facets['facet_ranges']:
#                 rr[frange] = \
#                     _flatten_to_dict(facets['facet_ranges'][frange]['counts'])
#                 rr[frange]['start'] = facets['facet_ranges'][frange]['start']
#                 rr[frange]['end'] = facets['facet_ranges'][frange]['end']
#                 rr[frange]['gap'] = facets['facet_ranges'][frange]['gap']
# 
#     return result


# Path: vows/solr/responsemapper_vows.py
import os.path
import json
from pyvows import Vows, expect
from dopplr.solr.responsemapper import detailed_response_mapper

# vim: set fileencoding=utf-8 :
#
# Copyright (c) 2011 Daniel Truemper <truemped at googlemail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#




with open(os.path.join(os.path.dirname(__file__), 'sampleresult.json')) as f:
    SAMPLE_RESULT = json.loads(f.read())


@Vows.batch
class TheDetailedResponseMapper(Vows.Context):

    def topic(self):

        return (SAMPLE_RESULT, detailed_response_mapper(SAMPLE_RESULT))