1414def app ():
1515 """Create a basic jsweb application for testing."""
1616 from jsweb import App
17-
17+
1818 app = App (__name__ )
1919 app .config .TESTING = True
2020 return app
@@ -30,13 +30,14 @@ def client(app):
3030@pytest .fixture
3131def config ():
3232 """Provide a test configuration."""
33+
3334 class TestConfig :
3435 DEBUG = True
3536 TESTING = True
3637 SECRET_KEY = "test-secret-key"
3738 DATABASE_URL = "sqlite:///:memory:"
3839 SQLALCHEMY_ECHO = False
39-
40+
4041 return TestConfig ()
4142
4243
@@ -53,92 +54,88 @@ def sample_form_data():
5354@pytest .fixture
5455def sample_json_data ():
5556 """Provide sample JSON data for testing."""
56- return {
57- "name" : "Test User" ,
58- "email" : "test@example.com" ,
59- "age" : 30 ,
60- "active" : True
61- }
57+ return {"name" : "Test User" , "email" : "test@example.com" , "age" : 30 , "active" : True }
6258
6359
6460@pytest .fixture
6561def fake_environ ():
6662 """Provide a fake WSGI environ dict for request testing."""
63+
6764 def _make_environ (
68- method = ' GET' ,
69- path = '/' ,
70- query_string = '' ,
71- content_type = ' application/x-www-form-urlencoded' ,
65+ method = " GET" ,
66+ path = "/" ,
67+ query_string = "" ,
68+ content_type = " application/x-www-form-urlencoded" ,
7269 content_length = 0 ,
73- body = b'' ,
74- cookies = ''
70+ body = b"" ,
71+ cookies = "" ,
7572 ):
7673 return {
77- ' REQUEST_METHOD' : method ,
78- ' CONTENT_TYPE' : content_type ,
79- ' CONTENT_LENGTH' : str (content_length ),
80- ' PATH_INFO' : path ,
81- ' QUERY_STRING' : query_string ,
82- ' HTTP_COOKIE' : cookies ,
83- ' wsgi.input' : BytesIO (body ),
84- ' SERVER_NAME' : ' testserver' ,
85- ' SERVER_PORT' : '80' ,
86- ' wsgi.url_scheme' : ' http' ,
74+ " REQUEST_METHOD" : method ,
75+ " CONTENT_TYPE" : content_type ,
76+ " CONTENT_LENGTH" : str (content_length ),
77+ " PATH_INFO" : path ,
78+ " QUERY_STRING" : query_string ,
79+ " HTTP_COOKIE" : cookies ,
80+ " wsgi.input" : BytesIO (body ),
81+ " SERVER_NAME" : " testserver" ,
82+ " SERVER_PORT" : "80" ,
83+ " wsgi.url_scheme" : " http" ,
8784 }
88-
85+
8986 return _make_environ
9087
9188
9289@pytest .fixture
9390def json_request_environ (fake_environ ):
9491 """Create a JSON POST request environ."""
9592 import json
96-
93+
9794 data = {"key" : "value" , "number" : 42 }
98- body = json .dumps (data ).encode (' utf-8' )
99-
95+ body = json .dumps (data ).encode (" utf-8" )
96+
10097 return fake_environ (
101- method = ' POST' ,
102- path = ' /api/test' ,
103- content_type = ' application/json' ,
98+ method = " POST" ,
99+ path = " /api/test" ,
100+ content_type = " application/json" ,
104101 content_length = len (body ),
105- body = body
102+ body = body ,
106103 )
107104
108105
109106@pytest .fixture
110107def form_request_environ (fake_environ ):
111108 """Create a form POST request environ."""
112- body = b' username=testuser&email=test@example.com'
113-
109+ body = b" username=testuser&email=test@example.com"
110+
114111 return fake_environ (
115- method = ' POST' ,
116- path = ' /form' ,
117- content_type = ' application/x-www-form-urlencoded' ,
112+ method = " POST" ,
113+ path = " /form" ,
114+ content_type = " application/x-www-form-urlencoded" ,
118115 content_length = len (body ),
119- body = body
116+ body = body ,
120117 )
121118
122119
123120@pytest .fixture
124121def file_upload_environ (fake_environ ):
125122 """Create a file upload request environ."""
126- boundary = ' ----WebKitFormBoundary'
123+ boundary = " ----WebKitFormBoundary"
127124 body = (
128- f' --{ boundary } \r \n '
125+ f" --{ boundary } \r \n "
129126 f'Content-Disposition: form-data; name="file"; filename="test.txt"\r \n '
130- f' Content-Type: text/plain\r \n '
131- f' \r \n '
132- f' test file content\r \n '
133- f' --{ boundary } --\r \n '
134- ).encode (' utf-8' )
135-
127+ f" Content-Type: text/plain\r \n "
128+ f" \r \n "
129+ f" test file content\r \n "
130+ f" --{ boundary } --\r \n "
131+ ).encode (" utf-8" )
132+
136133 return fake_environ (
137- method = ' POST' ,
138- path = ' /upload' ,
139- content_type = f' multipart/form-data; boundary={ boundary } ' ,
134+ method = " POST" ,
135+ path = " /upload" ,
136+ content_type = f" multipart/form-data; boundary={ boundary } " ,
140137 content_length = len (body ),
141- body = body
138+ body = body ,
142139 )
143140
144141
@@ -149,23 +146,12 @@ def pytest_configure(config):
149146 "markers" , "unit: Unit tests that test individual components"
150147 )
151148 config .addinivalue_line (
152- "markers" , "integration: Integration tests that test multiple components together"
153- )
154- config .addinivalue_line (
155- "markers" , "slow: Tests that take a long time to run"
156- )
157- config .addinivalue_line (
158- "markers" , "asyncio: Async tests"
159- )
160- config .addinivalue_line (
161- "markers" , "forms: Form validation tests"
162- )
163- config .addinivalue_line (
164- "markers" , "routing: Routing tests"
165- )
166- config .addinivalue_line (
167- "markers" , "database: Database tests"
168- )
169- config .addinivalue_line (
170- "markers" , "security: Security tests"
149+ "markers" ,
150+ "integration: Integration tests that test multiple components together" ,
171151 )
152+ config .addinivalue_line ("markers" , "slow: Tests that take a long time to run" )
153+ config .addinivalue_line ("markers" , "asyncio: Async tests" )
154+ config .addinivalue_line ("markers" , "forms: Form validation tests" )
155+ config .addinivalue_line ("markers" , "routing: Routing tests" )
156+ config .addinivalue_line ("markers" , "database: Database tests" )
157+ config .addinivalue_line ("markers" , "security: Security tests" )
0 commit comments