Skip to content

Commit 9cc6421

Browse files
authored
change server_name default to localhost.localdomain (#149) (#150)
1 parent 269bc67 commit 9cc6421

File tree

3 files changed

+29
-25
lines changed

3 files changed

+29
-25
lines changed

docs/changelog.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
Changelog
44
=========
55

6+
1.2.1
7+
------------------
8+
- Fix bug in ``:meth:pytest_flask.fixtures.live_server``
9+
where ``SESSION_COOKIE_DOMAIN`` was set to false due to
10+
``original_server_name`` defaulting to "localhost".
11+
The new default is "localhost.localdomain".
12+
613
1.2.0 (2021-02-26)
714
------------------
815

pytest_flask/fixtures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def test_server_is_up_and_running(live_server):
6969
host = pytestconfig.getvalue("live_server_host")
7070

7171
# Explicitly set application ``SERVER_NAME`` for test suite
72-
original_server_name = app.config["SERVER_NAME"] or "localhost"
72+
original_server_name = app.config["SERVER_NAME"] or "localhost.localdomain"
7373
final_server_name = _rewrite_server_name(original_server_name, str(port))
7474
app.config["SERVER_NAME"] = final_server_name
7575

tests/test_live_server.py

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
from urllib.request import urlopen
32

43
import pytest
54
from flask import url_for
@@ -18,20 +17,21 @@ def test_server_is_alive(self, live_server):
1817
assert live_server._process
1918
assert live_server._process.is_alive()
2019

21-
def test_server_listening(self, live_server):
22-
res = urlopen(url_for("ping", _external=True))
23-
assert res.code == 200
24-
assert b"pong" in res.read()
20+
def test_server_listening(self, client, live_server):
21+
res = client.get(url_for("ping", _external=True))
22+
assert res.status_code == 200
23+
assert b"pong" in res.data
2524

2625
def test_url_for(self, live_server):
2726
assert (
2827
url_for("ping", _external=True)
29-
== "http://localhost:%s/ping" % live_server.port
28+
== "http://localhost.localdomain:%s/ping" % live_server.port
3029
)
3130

3231
def test_set_application_server_name(self, live_server):
3332
assert (
34-
live_server.app.config["SERVER_NAME"] == "localhost:%d" % live_server.port
33+
live_server.app.config["SERVER_NAME"]
34+
== "localhost.localdomain:%d" % live_server.port
3535
)
3636

3737
def test_rewrite_application_server_name(self, appdir):
@@ -106,20 +106,19 @@ def mocked_stop_cleanly(*args, **kwargs):
106106
appdir.create_test_module(
107107
"""
108108
import pytest
109-
from urllib.request import urlopen
110109
111110
from flask import url_for
112111
113-
def test_a(live_server):
112+
def test_a(live_server, client):
114113
@live_server.app.route('/')
115114
def index():
116115
return 'got it', 200
117116
118117
live_server.start()
119118
120-
res = urlopen(url_for('index', _external=True))
121-
assert res.code == 200
122-
assert b'got it' in res.read()
119+
res = client.get(url_for('index', _external=True))
120+
assert res.status_code == 200
121+
assert b'got it' in res.data
123122
"""
124123
)
125124
args = [] if clean_stop else ["--no-live-server-clean-stop"]
@@ -134,20 +133,19 @@ def test_add_endpoint_to_live_server(self, appdir):
134133
appdir.create_test_module(
135134
"""
136135
import pytest
137-
from urllib.request import urlopen
138136
139137
from flask import url_for
140138
141-
def test_a(live_server):
139+
def test_a(live_server, client):
142140
@live_server.app.route('/new-endpoint')
143141
def new_endpoint():
144142
return 'got it', 200
145143
146144
live_server.start()
147145
148-
res = urlopen(url_for('new_endpoint', _external=True))
149-
assert res.code == 200
150-
assert b'got it' in res.read()
146+
res = client.get(url_for('new_endpoint', _external=True))
147+
assert res.status_code == 200
148+
assert b'got it' in res.data
151149
"""
152150
)
153151
result = appdir.runpytest("-v", "--no-start-live-server")
@@ -159,25 +157,24 @@ def test_concurrent_requests_to_live_server(self, appdir):
159157
appdir.create_test_module(
160158
"""
161159
import pytest
162-
from urllib.request import urlopen
163160
164161
from flask import url_for
165162
166-
def test_concurrent_requests(live_server):
163+
def test_concurrent_requests(live_server, client):
167164
@live_server.app.route('/one')
168165
def one():
169-
res = urlopen(url_for('two', _external=True))
170-
return res.read()
166+
res = client.get(url_for('two', _external=True))
167+
return res.data
171168
172169
@live_server.app.route('/two')
173170
def two():
174171
return '42'
175172
176173
live_server.start()
177174
178-
res = urlopen(url_for('one', _external=True))
179-
assert res.code == 200
180-
assert b'42' in res.read()
175+
res = client.get(url_for('one', _external=True))
176+
assert res.status_code == 200
177+
assert b'42' in res.data
181178
"""
182179
)
183180
result = appdir.runpytest("-v", "--no-start-live-server")

0 commit comments

Comments
 (0)