Example #1
0
        def response_content(url, request):
            '''
            '''
            MHP = request.method, url.hostname, url.path
            response_headers = {
                'Content-Type': 'application/json; charset=utf-8'
            }

            if MHP == ('GET', 'mapzen.com',
                       '/developers/oauth_api/current_developer'):
                if request.headers[
                        'Authorization'] == 'Bearer working-access-token':
                    data = u'''{\r  "id": 631,\r  "email": "*****@*****.**",\r  "nickname": "user_github_handle",\r  "admin": false,\r  "keys": "https://mapzen.com/developers/oauth_api/current_developer/keys"\r}'''
                    return response(200,
                                    data.encode('utf8'),
                                    headers=response_headers)

            if MHP == ('GET', 'mapzen.com',
                       '/developers/oauth_api/current_developer/keys'):
                if request.headers[
                        'Authorization'] == 'Bearer working-access-token':
                    data = u'''[\r  {\r    "service": "odes",\r    "key": "odes-xxxxxxx",\r    "created_at": "2015-12-15T15:24:57.236Z",\r    "nickname": "Untitled",\r    "status": "created"\r  },\r  {\r    "service": "odes",\r    "key": "odes-yyyyyyy",\r    "created_at": "2015-12-15T15:24:59.320Z",\r    "nickname": "Untitled",\r    "status": "disabled"\r  }\r]'''
                    return response(200,
                                    data.encode('utf8'),
                                    headers=response_headers)

            if MHP == ('POST', 'odes.mapzen.com', '/extracts'):
                if url.query == 'api_key=odes-xxxxxxx':
                    bbox = dict(parse_qsl(request.body))
                    data = u'''{\r  "error": "can't have more than 5 extracts currently processing"\r}'''
                    return response(403,
                                    data.encode('utf8'),
                                    headers=response_headers)

            raise Exception(request.method, url, request.headers, request.body)
Example #2
0
        def response_content2(url, request):
            '''
            '''
            MHP = request.method, url.hostname, url.path
            response_headers = {
                'Content-Type': 'application/json; charset=utf-8'
            }

            if MHP == ('GET', 'mapzen.com',
                       '/developers/oauth_api/current_developer'):
                if request.headers[
                        'Authorization'] == 'Bearer working-access-token':
                    data = u'''{\r  "id": 631,\r  "email": "*****@*****.**",\r  "nickname": "user_github_handle",\r  "admin": false,\r  "keys": "https://mapzen.com/developers/oauth_api/current_developer/keys"\r}'''
                    return response(200,
                                    data.encode('utf8'),
                                    headers=response_headers)

            if MHP == ('GET', 'mapzen.com',
                       '/developers/oauth_api/current_developer/keys'):
                if request.headers[
                        'Authorization'] == 'Bearer working-access-token':
                    data = u'''[\r  {\r    "service": "odes",\r    "key": "odes-xxxxxxx",\r    "created_at": "2015-12-15T15:24:57.236Z",\r    "nickname": "Untitled",\r    "status": "created"\r  },\r  {\r    "service": "odes",\r    "key": "odes-yyyyyyy",\r    "created_at": "2015-12-15T15:24:59.320Z",\r    "nickname": "Untitled",\r    "status": "disabled"\r  }\r]'''
                    return response(200,
                                    data.encode('utf8'),
                                    headers=response_headers)

            if MHP == ('GET', 'odes.mapzen.com', '/extracts'):
                if url.query == 'api_key=odes-xxxxxxx':
                    data = u'''[\r{\r  "id": 999,\r  "status": "created",\r  "created_at": "2016-06-02T03:29:25.233Z",\r  "processed_at": "",\r  "bbox": {\r    "e": -122.24825,\r    "n": 37.81230,\r    "s": 37.79724,\r    "w": -122.26447\r  }\r}\r]'''
                    return response(200,
                                    data.encode('utf8'),
                                    headers=response_headers)

            raise Exception(request.method, url, request.headers, request.body)
Example #3
0
        def response_content2(url, request):
            '''
            '''
            MHP = request.method, url.hostname, url.path
            response_headers = {
                'Content-Type': 'application/json; charset=utf-8'
            }

            if MHP == ('POST', 'mapzen.com', '/oauth/token'):
                form = dict(parse_qsl(request.body))
                if form['code'] == codes.pop(0):
                    data = u'''{"access_token":"working-access-token", "expires_in":7200, "token_type":"bearer"}'''
                    return response(200,
                                    data.encode('utf8'),
                                    headers=response_headers)

            if MHP == ('GET', 'mapzen.com',
                       '/developers/oauth_api/current_developer'):
                if request.headers[
                        'Authorization'] == 'Bearer working-access-token':
                    data = u'''{\r  "id": 631,\r  "email": "*****@*****.**",\r  "nickname": "user_github_handle",\r  "admin": false,\r  "keys": "https://mapzen.com/developers/oauth_api/current_developer/keys"\r}'''
                    return response(200,
                                    data.encode('utf8'),
                                    headers=response_headers)

            raise Exception(request.method, url, request.headers, request.body)
Example #4
0
        def response_content(url, request):
            '''
            '''
            MHP = request.method, url.hostname, url.path
            response_headers = {
                'Content-Type': 'application/json; charset=utf-8'
            }

            if MHP == ('POST', 'odes.mapzen.com', '/extracts'):
                if url.query == 'api_key=odes-xxxxxxx':
                    body = dict(parse_qsl(request.body))
                    self.assertIn('ready', body['email_subject'])
                    self.assertIn(extract_name, body['email_body_text'])
                    self.assertIn(created.strftime('%b %d, %Y'),
                                  body['email_body_text'])
                    self.assertIn(extract_path, body['email_body_text'])
                    self.assertIn(extract_name, body['email_body_html'])
                    self.assertIn(created.strftime('%b %d, %Y'),
                                  body['email_body_html'])
                    self.assertIn(extract_path, body['email_body_html'])

                    data = u'''{\r  "id": 999,\r  "status": "created",\r  "created_at": "2016-06-02T03:29:25.233Z",\r  "processed_at": "2016-06-02T04:20:11.000Z",\r  "bbox": {\r    "e": -122.24825,\r    "n": 37.81230,\r    "s": 37.79724,\r    "w": -122.26447\r  }\r}'''
                    return response(200,
                                    data.encode('utf8'),
                                    headers=response_headers)

            raise Exception(request.method, url, request.headers, request.body)
Example #5
0
        def response_content(url, request):
            '''
            '''
            MHP = request.method, url.hostname, url.path
            response_headers = {'Content-Type': 'application/json; charset=utf-8'}

            if MHP == ('GET', 'mapzen.com', '/developers/oauth_api/current_developer'):
                if request.headers['Authorization'] == 'Bearer working-access-token':
                    data = u'''{\r  "id": 631,\r  "email": "*****@*****.**",\r  "nickname": "user_github_handle",\r  "admin": false,\r  "keys": "https://mapzen.com/developers/oauth_api/current_developer/keys"\r}'''
                    return response(200, data.encode('utf8'), headers=response_headers)

            if MHP == ('GET', 'mapzen.com', '/developers/oauth_api/current_developer/keys'):
                if request.headers['Authorization'] == 'Bearer working-access-token':
                    data = u'''[\r  {\r    "service": "odes",\r    "key": "odes-xxxxxxx",\r    "created_at": "2015-12-15T15:24:57.236Z",\r    "nickname": "Untitled",\r    "status": "created"\r  },\r  {\r    "service": "odes",\r    "key": "odes-yyyyyyy",\r    "created_at": "2015-12-15T15:24:59.320Z",\r    "nickname": "Untitled",\r    "status": "disabled"\r  }\r]'''
                    return response(200, data.encode('utf8'), headers=response_headers)

            raise Exception(request.method, url, request.headers, request.body)
Example #6
0
        def response_content2(url, request):
            '''
            '''
            MHP = request.method, url.hostname, url.path
            response_headers = {'Content-Type': 'application/json; charset=utf-8'}

            if MHP == ('POST', 'mapzen.com', '/oauth/token'):
                form = dict(parse_qsl(request.body))
                if form['code'] == codes.pop(0):
                    data = u'''{"access_token":"working-access-token", "expires_in":7200, "token_type":"bearer"}'''
                    return response(200, data.encode('utf8'), headers=response_headers)

            if MHP == ('GET', 'mapzen.com', '/developers/oauth_api/current_developer'):
                if request.headers['Authorization'] == 'Bearer working-access-token':
                    data = u'''{\r  "id": 631,\r  "email": "*****@*****.**",\r  "nickname": "user_github_handle",\r  "admin": false,\r  "keys": "https://mapzen.com/developers/oauth_api/current_developer/keys"\r}'''
                    return response(200, data.encode('utf8'), headers=response_headers)

            raise Exception(request.method, url, request.headers, request.body)
Example #7
0
            def response_content(url, request):
                '''
                '''
                MH = request.method, url.hostname
                response_headers = {'Content-Length': '0'}

                if MH == ('HEAD', 's3.amazonaws.com'):
                    return response(200, data.encode('utf8'), headers=response_headers)

                raise Exception(request.method, url, request.headers, request.body)
Example #8
0
            def response_content(url, request):
                '''
                '''
                MH = request.method, url.hostname
                response_headers = {'Content-Length': '0'}

                if MH == ('HEAD', 's3.amazonaws.com'):
                    return response(200,
                                    data.encode('utf8'),
                                    headers=response_headers)

                raise Exception(request.method, url, request.headers,
                                request.body)
Example #9
0
        def response_content(url, request):
            '''
            '''
            MHP = request.method, url.hostname, url.path
            response_headers = {'Content-Type': 'application/json; charset=utf-8'}

            if MHP == ('POST', 'odes.mapzen.com', '/extracts'):
                if url.query == 'api_key=odes-xxxxxxx':
                    body = dict(parse_qsl(request.body))
                    self.assertIn('ready', body['email_subject'])
                    self.assertIn(extract_name, body['email_body_text'])
                    self.assertIn(created.strftime('%b %d, %Y'), body['email_body_text'])
                    self.assertIn(extract_path, body['email_body_text'])
                    self.assertIn(extract_name, body['email_body_html'])
                    self.assertIn(created.strftime('%b %d, %Y'), body['email_body_html'])
                    self.assertIn(extract_path, body['email_body_html'])
                    
                    data = u'''{\r  "id": 999,\r  "status": "created",\r  "created_at": "2016-06-02T03:29:25.233Z",\r  "processed_at": "2016-06-02T04:20:11.000Z",\r  "bbox": {\r    "e": -122.24825,\r    "n": 37.81230,\r    "s": 37.79724,\r    "w": -122.26447\r  }\r}'''
                    return response(200, data.encode('utf8'), headers=response_headers)

            raise Exception(request.method, url, request.headers, request.body)
Example #10
0
        def response_content1(url, request):
            '''
            '''
            MHP = request.method, url.hostname, url.path
            response_headers = {'Content-Type': 'application/json; charset=utf-8'}

            if MHP == ('GET', 'mapzen.com', '/developers/oauth_api/current_developer'):
                if request.headers['Authorization'] == 'Bearer working-access-token':
                    data = u'''{\r  "id": 631,\r  "email": "*****@*****.**",\r  "nickname": "user_github_handle",\r  "admin": false,\r  "keys": "https://mapzen.com/developers/oauth_api/current_developer/keys"\r}'''
                    return response(200, data.encode('utf8'), headers=response_headers)

            if MHP == ('GET', 'mapzen.com', '/developers/oauth_api/current_developer/keys'):
                if request.headers['Authorization'] == 'Bearer working-access-token':
                    data = u'''[\r  {\r    "service": "odes",\r    "key": "odes-xxxxxxx",\r    "created_at": "2015-12-15T15:24:57.236Z",\r    "nickname": "Untitled",\r    "status": "created"\r  },\r  {\r    "service": "odes",\r    "key": "odes-yyyyyyy",\r    "created_at": "2015-12-15T15:24:59.320Z",\r    "nickname": "Untitled",\r    "status": "disabled"\r  }\r]'''
                    return response(200, data.encode('utf8'), headers=response_headers)

            if MHP == ('POST', 'odes.mapzen.com', '/extracts'):
                if url.query == 'api_key=odes-xxxxxxx':
                    bbox = dict(parse_qsl(request.body))
                    data = u'''{\r  "id": 999,\r  "status": "created",\r  "created_at": "2016-06-02T03:29:25.233Z",\r  "processed_at": "2016-06-02T04:20:11.000Z",\r  "bbox": {\r    "e": -122.24825,\r    "n": 37.81230,\r    "s": 37.79724,\r    "w": -122.26447\r  }\r}'''
                    return response(200, data.encode('utf8'), headers=response_headers)

            if MHP == ('GET', 'odes.mapzen.com', '/extracts/999'):
                if url.query == 'api_key=odes-xxxxxxx':
                    bbox = dict(parse_qsl(request.body))
                    data = u'''{\r  "id": 999,\r  "status": "created",\r  "created_at": "2016-06-02T03:29:25.233Z",\r  "processed_at": "2016-06-02T04:20:11.000Z",\r  "bbox": {\r    "e": -122.24825,\r    "n": 37.81230,\r    "s": 37.79724,\r    "w": -122.26447\r  }\r}'''
                    return response(200, data.encode('utf8'), headers=response_headers)

            if MHP == ('GET', 'odes.mapzen.com', '/extracts'):
                if url.query == 'api_key=odes-xxxxxxx':
                    data = u'''[\r{\r  "id": 999,\r  "status": "created",\r  "created_at": "2016-06-02T03:29:25.233Z",\r  "processed_at": "2016-06-02T04:20:11.000Z",\r  "bbox": {\r    "e": -122.24825,\r    "n": 37.81230,\r    "s": 37.79724,\r    "w": -122.26447\r  }\r}\r]'''
                    return response(200, data.encode('utf8'), headers=response_headers)

            if (request.method, url.hostname) == ('GET', 'odes.mapzen.com') and url.path.startswith('/extracts/'):
                if url.query == 'api_key=odes-xxxxxxx':
                    data = u'''{"error":"extract not found"}'''
                    return response(404, data.encode('utf8'), headers=response_headers)

            raise Exception(request.method, url, request.headers, request.body)