-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathtest.py
25 lines (22 loc) · 958 Bytes
/
test.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
import json, pytest
from mock import patch
@pytest.mark.it("requests.get has to be called for the random-status.php url")
def test_url_call(capsys, app):
with patch('requests.get') as mock_request:
app()
mock_request.assert_called_once_with("https://assets.breatheco.de/apis/fake/sample/random-status.php")
@pytest.mark.it("Testing for 200: Ok")
def test_url_200(capsys, app):
with patch('requests.get') as mock_request:
mock_request.return_value.status_code = 200
mock_request.return_value.text = "something"
app()
captured = capsys.readouterr()
assert "something\n" == captured.out
@pytest.mark.it("Testing for any other code: Something went wrong")
def test_url_404(capsys, app):
with patch('requests.get') as mock_request:
mock_request.return_value.status_code = 404
app()
captured = capsys.readouterr()
assert "Something went wrong\n" == captured.out