Ejemplo n.º 1
0
def esgf_mock(url, request):
    """Mock an esgf request."""
    global last_host, last_query
    last_host = url.netloc
    last_query = parse.parse_qs(url.query)

    limit = int(last_query.get('limit', [10])[0])
    content = None

    if limit == 1:
        content = open(TestCase.data_path('esgf_search_limit1.json')).read()
    elif limit == 0:
        content = '{}'
    elif last_query.get('fields') is not None:
        if last_query['fields'][0] == 'variable':
            content = open(
                TestCase.data_path('esgf_search_variables.json')
            ).read()
        else:
            content = open(
                TestCase.data_path('esgf_search_fields.json')
            ).read()

    if six.PY3 and content is not None:
        content = bytes(content, 'utf-8')

    if content is not None:
        return {
            'content': content,
            'status_code': 200
        }
    else:
        return {
            'status_code': 400
        }
Ejemplo n.º 2
0
 def setUp(self):  # noqa
     """Read a small geojson file."""
     TestCase.setUp(self)
     self.reader = GeopandasReader()
     self.reader.file_name = self.data_path('geopoints.json')