-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_hello.py
51 lines (35 loc) · 1.11 KB
/
test_hello.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import pytest
import hello_app
MOCK_ENCODING = "mock-encoding"
class MockEncodingResponse:
def __init__(self):
self.headers = {"Content-Encoding": MOCK_ENCODING}
def _mock_get(url):
assert url == "https://news.ycombinator.com"
return MockEncodingResponse()
@pytest.fixture
def mock_encoding_request(monkeypatch):
monkeypatch.setattr("requests.get", _mock_get)
@pytest.fixture
def app():
return hello_app.app
@pytest.fixture
def test_client(app):
return app.test_client()
def test_hello(test_client):
"""
GIVEN: A flask hello app
WHEN: I GET the hello/ route
THEN: The response should be "hello world"
"""
response = test_client.get("/hello")
assert response.data.decode("utf-8") == "hello world"
def test_encoding_header(test_client, mock_encoding_request):
"""
GIVEN: A flask hello app
A mock request handler
WHEN: I GET the /hacker_news_encoding route
THEN: The response should be the expected Content-Encoding
"""
response = test_client.get("/hacker_news_encoding")
assert response.data.decode("utf-8") == MOCK_ENCODING