Пример #1
0
def test_deny_unverified_by_default(httpsserver):
    """Ensure that we throw an error by default for self-signed servers."""

    api = Api(domain=httpsserver.url)

    with pytest.raises(HttpCouldNotVerifyServerError):
        api.login('*****@*****.**', 'test')

    with pytest.raises(HttpCouldNotVerifyServerError):
        api.logout()

    with pytest.raises(HttpCouldNotVerifyServerError):
        api.refresh_token()

    # Also ensure that the RestResource works as well
    resource = api.event

    with pytest.raises(HttpCouldNotVerifyServerError):
        resource.get()

    with pytest.raises(HttpCouldNotVerifyServerError):
        resource.put()

    with pytest.raises(HttpCouldNotVerifyServerError):
        resource.patch()

    with pytest.raises(HttpCouldNotVerifyServerError):
        resource.post()

    with pytest.raises(HttpCouldNotVerifyServerError):
        resource.delete()
Пример #2
0
    def test_token_refresh(self, m):
        payload = {'token': 'new-token'}
        m.post('http://iotile.test/api/v1/auth/api-jwt-refresh/',
               text=json.dumps(payload))

        api = Api(domain='http://iotile.test')
        api.set_token('old-token')
        self.assertEqual(api.token, 'old-token')
        api.refresh_token()
        self.assertEqual(api.token, 'new-token')
Пример #3
0
def test_allow_unverified_option(httpsserver):
    """Ensure that we allow unverified servers if the user passes a flag."""

    api = Api(domain=httpsserver.url, verify=False)

    api.login('*****@*****.**', 'test')
    api.logout()
    api.refresh_token()

    # Also ensure that the RestResource works as well
    resource = api.event

    resource.get()
    resource.put()
    resource.patch()
    resource.post()
    resource.delete()