Exemple #1
0
def test_app_unkown_path():

    app = App1({'foo': 'bar'})  # simple settings dict
    c = werkzeug.Client(app, werkzeug.BaseResponse)

    resp = c.post('/no')
    assert resp.status == "404 NOT FOUND"
Exemple #2
0
def test_app_wrong_method():

    app = App1({'foo': 'bar'})  # simple settings dict
    c = werkzeug.Client(app, werkzeug.BaseResponse)

    resp = c.post('/')
    assert resp.status == "405 METHOD NOT ALLOWED"
Exemple #3
0
    def test_editor_docstring(self, wiki):
        """Check the editor's docstring."""

        client = werkzeug.Client(wiki.application, hatta.WikiResponse)
        response = client.get('/+edit/Home')
        data = b''.join(response.response)
        assert data.startswith(self.docstring)
Exemple #4
0
def test_path_params():

    app = App1({'foo': 'bar'})  # simple settings dict
    c = werkzeug.Client(app, werkzeug.BaseResponse)

    resp = c.get('/post/33')
    assert resp.status == "200 OK"
    assert resp.data == "33"
Exemple #5
0
 def test_read_only_undo(self, wiki):
     client = werkzeug.Client(wiki.application, hatta.WikiResponse)
     wiki.read_only = True
     data = '52=Undo'
     response = client.post(
         '/+undo/readonly',
         data=data,
         content_type='application/x-www-form-urlencoded')
     assert response.status_code == 403
Exemple #6
0
 def test_read_only_edit(self, wiki):
     client = werkzeug.Client(wiki.application, hatta.WikiResponse)
     wiki.read_only = True
     data = 'text=test&parent=-1&comment=created&author=test&save=Save'
     response = client.post(
         '/+edit/readonly',
         data=data,
         content_type='application/x-www-form-urlencoded')
     assert response.status_code == 403
Exemple #7
0
 def call_wsgi(self, app: Any = None, headers: Optional[Dict[str, str]] = None, **kwargs: Any) -> WSGIResponse:
     application = app or self.app
     if application is None:
         raise RuntimeError(
             "WSGI application instance is required. "
             "Please, set `app` argument in the schema constructor or pass it to `call_wsgi`"
         )
     data = self.as_werkzeug_kwargs(headers)
     client = werkzeug.Client(application, WSGIResponse)
     with cookie_handler(client, self.cookies):
         return client.open(**data, **kwargs)
Exemple #8
0
    def test_front_page(self, wiki):
        """Check that Home page doesn't exist and redirects to editor."""

        client = werkzeug.Client(wiki.application, hatta.WikiResponse)
        response = client.get('/')
        assert response.status_code == 303
        assert response.headers['Location'] in (
            'http://localhost/+edit/Home',
            'http://localhost/%2Bedit/Home',
        )
        response = client.get('/+edit/Home')
        assert response.status_code == 404
Exemple #9
0
    def test_create_front_page(self, wiki):
        """Create a Home page and make sure it's created propely."""

        client = werkzeug.Client(wiki.application, hatta.WikiResponse)
        data = 'text=test&parent=-1&comment=created&author=test&save=Save'
        response = client.post(
            '/+edit/Home',
            data=data,
            content_type='application/x-www-form-urlencoded')
        assert response.status_code == 303
        response = client.get('/')
        assert response.status_code == 200
Exemple #10
0
def test_app_basics():

    app = App1({'foo': 'bar'})  # simple settings dict
    c = werkzeug.Client(app, werkzeug.BaseResponse)

    resp = c.get('/')
    assert resp.status == "200 OK"
    assert resp.data == "test1"

    resp = c.get('/huhu')
    assert resp.status == "200 OK"
    assert resp.data == "test2"
Exemple #11
0
    def test_page_docstring(self, wiki):
        """Check the page's docstring."""

        client = werkzeug.Client(wiki.application, hatta.WikiResponse)
        data = 'text=test&parent=-1&comment=created&author=test&save=Save'
        response = client.post(
            '/+edit/Home',
            data=data,
            content_type='application/x-www-form-urlencoded')
        assert response.status_code == 303
        response = client.get('/')
        assert response.status_code == 200
        data = b''.join(response.response)
        assert data.startswith(self.docstring)
Exemple #12
0
    def test_search(self, wiki):
        """Test simple searching."""

        client = werkzeug.Client(wiki.application, hatta.WikiResponse)
        data = 'text=test&parent=-1&comment=created&author=test&save=Save'
        response = client.post(
            '/+edit/searching',
            data=data,
            content_type='application/x-www-form-urlencoded')
        assert response.status_code == 303
        response = client.get('/+search?q=test')
        assert response.status_code == 200
        data = ''.join(response.data)
        assert '>searching</a>' in data
Exemple #13
0
    def test_create_slash_page(self, wiki):
        """Create a page with slash in name."""

        client = werkzeug.Client(wiki.application, hatta.WikiResponse)
        data = 'text=test&parent=-1&comment=created&author=test&save=Save'
        response = client.post(
            '/+edit/1/2',
            data=data,
            content_type='application/x-www-form-urlencoded')
        assert response.status_code == 303
        response = client.get('/1/2')
        assert response.status_code == 200
        response = client.get('/+history/1/2/0')
        assert response.status_code == 200
 def call_wsgi(self, app: Any = None, headers: Optional[Dict[str, str]] = None, **kwargs: Any) -> WSGIResponse:
     application = app or self.app
     if application is None:
         raise RuntimeError(
             "WSGI application instance is required. "
             "Please, set `app` argument in the schema constructor or pass it to `call_wsgi`"
         )
     data = self.as_werkzeug_kwargs(headers)
     client = werkzeug.Client(application, WSGIResponse)
     with cookie_handler(client, self.cookies):
         response = client.open(**data, **kwargs)
     requests_kwargs = self.as_requests_kwargs(base_url=self.get_full_base_url(), headers=headers)
     response.request = requests.Request(**requests_kwargs).prepare()
     if self.feedback:
         self.store_response(response)
     return response
Exemple #15
0
def module_test_client1(request):
    """provides an app with a module for testing module templates and overrides"""
    from mods.testmodule import testmodule1

    class App(Application):
        """same as above but we configure the module dynamically"""

        defaults = {
            'testing' : True,
        }

        modules = [
            testmodule1()
        ]
    app = App(__name__)
    return werkzeug.Client(app, werkzeug.BaseResponse)
Exemple #16
0
def module_test_client2(request):
    """provides an app with a module for testing module templates and overrides.
    this uses a different template folder"""
    from mods.testmodule import testmodule2

    class App(Application):
        """same as above but we configure the module dynamically"""

        defaults = {
            'testing' : True,
        }

        modules = [
            testmodule2()
        ]
    fn = pkg_resources.resource_filename(__name__, 'testconfig.ini')
    app = App(__name__, {'module_config_file' : fn})
    return werkzeug.Client(app, werkzeug.BaseResponse)
Exemple #17
0
def client(request, app):
    return werkzeug.Client(app, werkzeug.BaseResponse)                                                                                                                                                                      
Exemple #18
0
                    data["password_confirm"] = currentpwd
                    return get_auth_token(client, data)

        assert r.status_code == 200
        assert content is not None

        headers: CaseInsensitiveDict[str] = CaseInsensitiveDict()
        headers["Authorization"] = f"Bearer {content}"
        return content, headers

    # No need to restore the logger after this test because
    # schemathesis test is the last one!
    # (just because in alphabetic order there are no other tests)
    set_logger("WARNING")
    app = create_app()
    client = werkzeug.Client(app, werkzeug.wrappers.Response)

    if Env.get_bool("AUTH_ENABLE"):
        BaseAuthentication.load_default_user()
        BaseAuthentication.load_roles()
        USER = BaseAuthentication.default_user
        PWD = BaseAuthentication.default_password
        data = {"username": USER, "password": PWD}
        token, auth_header = get_auth_token(client, data)

        # it does not handle custom headers => the endpoint will provide partial schema
        # due to missing authentication => skipping all private endpoints and schemas
        # schema = schemathesis.from_wsgi('/api/specs', app)
        r = client.get(f"/api/specs?access_token={token}")
    else:
        r = client.get("/api/specs")
def pytest_funcarg__client(request):
    app = request.getfuncargvalue('app')
    return werkzeug.Client(app, werkzeug.BaseResponse)
Exemple #20
0
def pytest_funcarg__client_mod_app3(request):
    app = request.getfuncargvalue('module_app3')
    return werkzeug.Client(app, werkzeug.BaseResponse)