Mikhail Korobov avatar Mikhail Korobov committed 942a4b7

Cookie tests for better test coverage

Comments (0)

Files changed (1)

tests/test_cookie.py

+import webtest
+from webob import Request
+
+def cookie_app(environ, start_response):
+    req = Request(environ)
+    status = '200 OK'
+    body = '<html><body><a href="/go/">go</a></body></html>'
+    headers = [
+        ('Content-Type', 'text/html'),
+        ('Content-Length', str(len(body))),
+    ]
+    if req.path_info != '/go/':
+        headers.extend([
+            ('Set-Cookie', 'spam=eggs'),
+            ('Set-Cookie', 'foo="bar;baz"'),
+        ])
+    start_response(status, headers)
+    return [body]
+
+def test_cookies():
+    app = webtest.TestApp(cookie_app)
+    assert not app.cookies, 'App should initially contain no cookies'
+    res = app.get('/')
+    cookies = app.cookies
+    assert cookies, 'Response should have set cookies'
+    assert cookies['spam'] == 'eggs'
+    assert cookies['foo'] == '"bar;baz"'
+
+def test_preserve_cookies():
+    app = webtest.TestApp(cookie_app)
+    res = app.get('/')
+    assert app.cookies
+    go_page = res.click('go')
+    assert app.cookies
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.