def test_if_args_keys_are_the_same(): app = Cezve() client = Client(app, Response) app.route('/test/<key1>/<key2>', lambda a, b: 'ignore') with pytest.raises(ArgumentValidationError, match='function arguments invalid'): client.get('/test/hello/world')
def test_if_arg_key_is_the_same(): app = Cezve() client = Client(app, Response) app.route('/test/<key>', lambda e: e) with pytest.raises(TypeError, match="got an unexpected keyword argument 'key'"): client.get('/test/hello')
def test_if_request_and_args_values_are_ok(): app = Cezve() client = Client(app, Response) app.route('/test/<a>/<b>', lambda r, a, b: { 'r': type(r).__name__, 'a': a, 'b': b }) resp = client.get('/test/hello/world') assert resp.json == {'r': Request.__name__, 'a': 'hello', 'b': 'world'}
def test_app_simple_route(): def action(): return 'test' app = Cezve() app.route('/test', action) client = Client(app, Response) resp = client.get('/test') assert resp.data == b'test'
def test_html_response(): app = Cezve() router = app.router router.route('/test', lambda: 'test') client = Client(app, Response) resp = client.get('/test') assert resp.content_type == 'text/plain; charset=utf-8' assert resp.data == b'test'
def test_response(): app = Cezve() response = Response('test') router = app.router router.route('/test', lambda: response) client = Client(app, Response) resp = client.get('/test') assert resp.data == response.data
def test_json_response(): app = Cezve() router = app.router router.route('/test', lambda: {'test': 'valid'}) client = Client(app, Response) resp = client.get('/test') assert resp.is_json assert resp.json == {'test': 'valid'}
def test_app_decorated_route(): app = Cezve() @app.route('/test') def action(): return 'test' client = Client(app, Response) resp = client.get('/test') assert resp.data == b'test'
def test_if_head_and_get_method_works(): app = Cezve() client = Client(app, Response) app.route('/get', lambda: 'get', methods=['get'], endpoint='get') app.route('/head', lambda: 'head', methods=['head'], endpoint='head') resp = client.get('/get') assert resp.data == b'get' resp = client.head('/get') assert resp.status_code == 200 resp = client.get('/head') assert resp.data == b'head' resp = client.head('/head') assert resp.status_code == 200
def test_if_has_request(): app = Cezve() client = Client(app, Response) app.route('/test', lambda req: 'test') resp = client.get('/test') assert resp.data == b'test'
def test_if_request_and_arg_values_are_ok(): app = Cezve() client = Client(app, Response) app.route('/test/<a>', lambda r, a: {'r': type(r).__name__, 'a': a}) resp = client.get('/test/hello') assert resp.json == {'r': Request.__name__, 'a': 'hello'}
def test_if_args_values_are_ok(): app = Cezve() client = Client(app, Response) app.route('/test/<a>/<b>', lambda a, b: {'values': [a, b]}) resp = client.get('/test/hello/world') assert resp.json == {'values': ['hello', 'world']}
def test_if_arg_value_is_ok(): app = Cezve() client = Client(app, Response) app.route('/test/<a>', lambda a: a) resp = client.get('/test/hello') assert resp.data == b'hello'
def test_if_has_request_and_arg(): app = Cezve() client = Client(app, Response) app.route('/test/<a>', lambda r, a: 'test') resp = client.get('/test/hello') assert resp.data == b'test'