示例#1
0
    def test_session_kwargs(self, mock):
        mock.get('{0}/endpoint/'.format(self.host), status_code=200)
        response = self.service.remote_call(method='GET',
                                            api='endpoint/',
                                            session_kw={"timeout": 2000})

        self.assertEqual(response.status_code, 200)
示例#2
0
    def test_get_json_from_url(self, mock):

        mock.get("http://123-fake-api.com", text=json.dumps(JSON_DATA))

        response = get_json_from_url("http://123-fake-api.com", headers=None, params=None, proxy=None)

        assert response == {"key": "value"}
示例#3
0
    def test_get_ipinfo_calls_correct_url(self, mock):
        mock.get(requests_mock.ANY, json={})
        ipinfo.get_ipinfo()

        expected_url = '%s/json' % self.baseurl
        req = mock.last_request
        url = '%s://%s/%s' % (req.scheme, req.netloc, 'json')
        self.assertEquals(url, expected_url)
示例#4
0
    def test_get_ipinfo_calls_correct_url_with_ip(self, mock):
        mock.get(requests_mock.ANY, json={})
        ip_address = '8.8.8.8'
        ipinfo.get_ipinfo(ip=ip_address)

        expected_url = '%s/%s/json' % (self.baseurl, ip_address)
        req = mock.last_request
        url = '%s://%s/%s/json' % (req.scheme, req.netloc, ip_address)
        self.assertEquals(url, expected_url)
示例#5
0
    def test_get_ipinfo_calls_correct_url_with_param(self, mock):
        mock.get(requests_mock.ANY, json={})
        parameter = 'region'
        ipinfo.get_ipinfo(param=parameter)

        expected_url = '%s/%s' % (self.baseurl, parameter)
        req = mock.last_request
        url = '%s://%s/%s' % (req.scheme, req.netloc, parameter)
        self.assertEquals(url, expected_url)
示例#6
0
    def test_get_forecast_calls_correct_url(self, mock):
        mock.get(requests_mock.ANY, json={})
        forecastio.get_forecast(self.apikey, self.latitude, self.longitude)

        expected_url = '%s/%s/%s,%s' % (
            self.baseurl, self.apikey, self.latitude, self.longitude)
        req = mock.last_request
        url = '%s://%s%s' % (req.scheme, req.netloc, req.path)
        self.assertEquals(url, expected_url)
示例#7
0
    def test_get_forecast_calls_correct_url(self, mock):
        mock.get(requests_mock.ANY, json={})
        forecastio.get_forecast(self.apikey, self.latitude, self.longitude)

        expected_url = '%s/%s/%s,%s' % (self.baseurl, self.apikey,
                                        self.latitude, self.longitude)
        req = mock.last_request
        url = '%s://%s%s' % (req.scheme, req.netloc, req.path)
        self.assertEquals(url, expected_url)
示例#8
0
    def test_request_kwargs(self, mock):
        header = {'ContentType': 'application/json'}

        mock.get('{0}/endpoint/'.format(self.host), status_code=200)
        response = self.service.remote_call(method='GET',
                                            api='endpoint/',
                                            request_kw={"headers": header})

        self.assertEqual(response.status_code, 200)
示例#9
0
    def test_cookies(self, mock):
        cookies = {
            'randomcookie': 'qwertzuiop'
        }

        mock.get('{0}/endpoint/'.format(self.host), status_code=200, cookies=cookies)
        response = self.service.remote_call(method='GET', api='endpoint/', cookies=cookies)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.cookies, cookies)
示例#10
0
    def test_get_forecast_calls_correct_url_with_multi_argument(self, mock):
        mock.get(requests_mock.ANY, json={})
        kwargs = odict({'unit': 'si', 'lang': 'en'})
        forecastio.get_forecast(
            self.apikey, self.latitude, self.longitude, **kwargs)

        expected_url = '%s/%s/%s,%s?%s' % (
            self.baseurl, self.apikey, self.latitude,
            self.longitude, _urlq(kwargs.items()))
        req = mock.last_request
        url = '%s://%s%s?%s' % (req.scheme, req.netloc, req.path, req.query)
        self.assertEquals(url, expected_url)
示例#11
0
    def test_get_forecast_calls_correct_url_with_multi_argument(self, mock):
        mock.get(requests_mock.ANY, json={})
        kwargs = odict({'unit': 'si', 'lang': 'en'})
        forecastio.get_forecast(self.apikey, self.latitude, self.longitude,
                                **kwargs)

        expected_url = '%s/%s/%s,%s?%s' % (self.baseurl, self.apikey,
                                           self.latitude, self.longitude,
                                           _urlq(kwargs.items()))
        req = mock.last_request
        url = '%s://%s%s?%s' % (req.scheme, req.netloc, req.path, req.query)
        self.assertEquals(url, expected_url)
示例#12
0
def test_connect_to_ss(mock):
    headers = {
        'authorization': 'abc',
        'X-SSC-Application-Name': 'qwe',
        'X-SSC-Application-Version': '1.2',
    }


    mock.get("http://123-fake-api.com", text=json.dumps(JSON_DATA))

    response = get_json_from_url("http://123-fake-api.com", headers=headers, params=None, proxy=None)

    assert response == {"key": "value"}
示例#13
0
def get_page(id):
    page = db.get(id)
    if page == None:
        # se non trovo la pagina errore 404
        return page_not_found(None)
    # recupero il menu
    menu = db.menu()
    # faccio il render
    return render_template("page.html", menu=menu, page=page)
示例#14
0
def test_request_journeys_should_raise_on_non_200():
    with requests_mock.Mocker() as mock:
        instant_system = InstantSystem(service_url='http://instant.sys', api_key='ApiKey', network='Network')

        mock.get('http://instant.sys', status_code=401, text='{this is the http response}')

        with pytest.raises(RidesharingServiceError) as e:
            instant_system._request_journeys(
                '1.2,3.4',
                '5.6,7.8',
                utils.PeriodExtremity(
                    datetime=utils.str_to_time_stamp("20171225T060000"), represents_start=True
                ),
                DummyInstance(),
            )

        exception_params = e.value.get_params().values()
        assert 401 in exception_params
        assert '{this is the http response}' in exception_params
示例#15
0
    def test_get_ipinfo_raises_server_error_503(self, mock):
        mock.get(requests_mock.ANY, status_code=503, json={})
        with self.assertRaises(requests.HTTPError) as e_cm:
            ipinfo.get_ipinfo()

        self.assertEquals(e_cm.exception.response.status_code, 503)
示例#16
0
    def test_get(self, mock):
        mock.get('{0}/endpoint/'.format(self.host), status_code=200)
        response = self.service.remote_call(method='GET', api='endpoint/')

        self.assertEqual(response.status_code, 200)
示例#17
0
 def test_get_config_from_url(self, mock):
     mock.get("mocked://microservice.io/service.json",
              status_code=200,
              json=self.configuration)
     refresh_service_configuration_data(
         "mocked://microservice.io/service.json")
示例#18
0
    def test_get_ipinfo_returns_object_model_for_field(self, mock):
        mock.get(requests_mock.ANY, text='')
        r = ipinfo.get_ipinfo(param='region')

        self.assertIsInstance(r, IpInfo)
示例#19
0
    def test_http_get_with_filename(self, mock, mock_open):
        """Test http_get with filename."""
        from pyarlo.utils import http_get

        mock.get(DEVICES_ENDPOINT, text=load_fixture('pyarlo_devices.json'))
        self.assertTrue(http_get(DEVICES_ENDPOINT, filename=TEST_FILE))
示例#20
0
    def test_get_forecast_returns_object_model(self, mock):
        mock.get(requests_mock.ANY, json={})
        r = forecastio.get_forecast(self.apikey, self.latitude, self.longitude)

        self.assertIsInstance(r, Forecast)
示例#21
0
    def test_get_forecast_raises_server_error_503(self, mock):
        mock.get(requests_mock.ANY, status_code=503, json={})
        with self.assertRaises(requests.HTTPError) as e_cm:
            forecastio.get_forecast(self.apikey, self.latitude, self.longitude)

        self.assertEquals(e_cm.exception.response.status_code, 503)
示例#22
0
    def test_get_forecast_raises_server_error_503(self, mock):
        mock.get(requests_mock.ANY, status_code=503, json={})
        with self.assertRaises(requests.HTTPError) as e_cm:
            forecastio.get_forecast(self.apikey, self.latitude, self.longitude)

        self.assertEquals(e_cm.exception.response.status_code, 503)
示例#23
0
    def test_http_get_errno_500(self, mock):
        """Test http_get with error 500."""
        from pyarlo.utils import http_get

        mock.get(DEVICES_ENDPOINT, json=MOCK_DATA, status_code=204)
        self.assertFalse(http_get(DEVICES_ENDPOINT))
示例#24
0
    def test_get_ipinfo_returns_object_model_for_json(self, mock):
        mock.get(requests_mock.ANY, json={})
        r = ipinfo.get_ipinfo()

        self.assertIsInstance(r, IpInfo)
示例#25
0
    def test_get_forecast_returns_object_model(self, mock):
        mock.get(requests_mock.ANY, json={})
        r = forecastio.get_forecast(self.apikey, self.latitude, self.longitude)

        self.assertIsInstance(r, Forecast)
示例#26
0
    def test_http_get_ok_200(self, mock):
        """Test http_get with code 200."""
        from pyarlo.utils import http_get

        mock.get(DEVICES_ENDPOINT, json=MOCK_DATA)
        self.assertIsInstance(http_get(DEVICES_ENDPOINT), bytes)