Exemplo n.º 1
0
    def setUp(self):
        """Test fixtures."""

        # The test HTTP server is started.
        self._server = TestServer()
        self._server.start()

        self._http_client = httpclient.HttpClient()
Exemplo n.º 2
0
    def testGetMethod(self):
        client = httpclient.HttpClient('www.npr.org', 80)

        response = client.doGet('/nonExistentPage')
        self.assertEquals(response.statusCode, 404)
        self.assertEquals(response.statusMessage.lower(), 'not found')

        response = client.doGet('/index.html')
        self.assertEquals(response.statusCode, 200)
        self.assertEquals(response.statusMessage, 'OK')
        self.assertEquals(response.headers['Content-Type'], 'text/html')
        self.assertTrue(response.body.find('National Public Radio') > 0)
Exemplo n.º 3
0
    def testGetMethod(self):
        client = httpclient.HttpClient('www.shilad.com', 80)

        response = client.doGet('/nonExistentPage')
        self.assertEquals(response.statusCode, 404)
        self.assertEquals(response.statusMessage.lower(), 'not found')

        response = client.doGet('/index.html')
        self.assertEquals(response.statusCode, 200)
        self.assertEquals(response.statusMessage, 'OK')
        self.assertEquals(response.headers['Content-Type'],
                          'text/html; charset=UTF-8')
        self.assertTrue(response.body.find('*****@*****.**') > 0)
Exemplo n.º 4
0
 def getlocation(self):
     try:
         self.url = getlocationurl()
         body = client.HttpClient(self.url).get_request()
         self.lat = body['latitude']
         self.lon = body['longitude']
         self.city = body['city']
         self.state_code = body['region_code']
         self.state_name = body['region_name']
         self.country_name = body['country_name']
         self.country_code = body['country_code']
         self.time_zone = body['time_zone']
         self.zip_code = body['zip_code']
         return self
     except TypeError as err:
         errors.Error("Location response could not be retrieved: ", err)
Exemplo n.º 5
0
    def __init__(self, dist_req, dist_res):

        try:
            client = httpclient.HttpClient()
            client.set_params(dist_req.get_params())
            client.set_url("%s%s%s" % (dist_req.get_url(), dist_req.get_api(),
                                       dist_req.get_format()))
            response = client.get_request()
            log.debug("Response returned : %s" % response)
            if response['status'] != 'OK':
                raise errors.Error('Http status returned is not valid.',
                                   response['status'])
            dist_res.set_status(response['status'])
            for row in response['rows'][0]['elements']:
                if row['status'] != 'OK':
                    raise errors.Error(
                        "Origin-Destination pairing returned invalid status.",
                        row['status'])
                dist_res.set_distance(row['distance']['text'])
                dist_res.set_duration(row['duration']['text'])
        except RuntimeError as err:
            raise errors.Error("Error while getting Remote response", err)
Exemplo n.º 6
0
    def __init__(self, req, res):

        request_url = (
            "%s/%s/%s.%s" %
            (req.get_url(), req.get_state(), req.get_city(), req.get_format()))
        log.debug("Weather request url: %s" % request_url)
        body = client.HttpClient(request_url).get_request()
        if operator.contains(body['response'], 'error'):
            raise errors.Error(
                'Query did not return any response.',
                '%s:: %s' % (body['response']['error']['type'],
                             body['response']['error']['description']))
        log.debug("Weather Response: " % (body['current_observation']))
        res.set_city(body['current_observation']['display_location']['city'])
        res.set_weather(body['current_observation']['weather'])
        res.set_temparature_string(
            body['current_observation']['temperature_string'])
        res.set_temperature_f(body['current_observation']['temp_f'])
        res.set_precip_today(
            body['current_observation']['precip_today_metric'])
        res.set_precip_1hr(body['current_observation']['precip_1hr_metric'])
        res.set_wind_name(body['current_observation']['wind_string'])
        res.set_wind_speed(body['current_observation']['wind_mph'])
Exemplo n.º 7
0
import dbwrapper
import flask
import httpclient
import config
import os

# DB
db = dbwrapper.DBWrapper(host=config.get(u'db', u'host'),
                         port=config.getint(u'db', u'port', 3306),
                         user=config.get(u'db', u'user'),
                         passwd=config.get(u'db', u'passwd', u''),
                         db=config.get(u'db', u'db'))

# Http client
wutong_client = httpclient.HttpClient(
    config.get(u'wutong', u'server', u'http://apitest.borqs.com'))

# WebApp
app = flask.Flask(u'IABMarket', static_folder=u'market')
upload_folder = os.path.join(os.path.dirname(__file__), u'upload')
if not os.path.exists(upload_folder):
    os.mkdir(upload_folder)
app.config[u'UPLOAD_FOLDER'] = upload_folder
app.secret_key = 'xHVGDBB1RDDWYlp5zApBcQ=='  # do not change
app.jinja_options = {'extensions': ['jinja2.ext.do']}


@app.route(u'/upload/<path:filename>')
def base_static(filename):
    return flask.send_from_directory(upload_folder, filename)
Exemplo n.º 8
0
def getclient(path, write_func, header_func):
    if cache.getcache().contains(path):
        return cacheclient.CacheClient(path, write_func, header_func)
    else:
        return httpclient.HttpClient(path, write_func, header_func)
Exemplo n.º 9
0
def send_command(username, password, host, url):
    c = http.HttpClient(username, password, host, url)
Exemplo n.º 10
0
 def setup(self):
     print("setup httpclient")
     self.hc = httpclient.HttpClient()
     self.hc.setParams(directory="/", method="GET")
Exemplo n.º 11
0
 def testPostWithParams(self):
     client = httpclient.HttpClient('httpbin.org')
     response = client.doPostWithParams('/post', {'Foo': 'Bar'})
     data = json.loads(response.body)
     self.assertEquals(data['form']['Foo'], 'Bar')
Exemplo n.º 12
0
 def testGetParamEncoding(self):
     client = httpclient.HttpClient('httpbin.org')
     response = client.doGetWithParams('/get', {'$foo': 'bar &z'})
     data = json.loads(response.body)
     self.assertEquals(data['args'], {'$foo': 'bar &z'})
Exemplo n.º 13
0
 def testPostMethod(self):
     client = httpclient.HttpClient('httpbin.org')
     response = client.doPost('/post', 'Foo=Bar')
     data = json.loads(response.body)
     self.assertEquals(data['form']['Foo'], 'Bar')
Exemplo n.º 14
0
 def __init__(self, url_list):
     super(Worker, self).__init__()
     self.url_list = url_list
     self._http = httpclient.HttpClient()