-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
33 lines (21 loc) · 792 Bytes
/
tests.py
File metadata and controls
33 lines (21 loc) · 792 Bytes
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
import requests
from app.app import is_alive_host
class MockResponse:
def __init__(self, status_code):
self.status_code = status_code
class MockGet:
def __init__(self, status_code):
self.status_code = status_code
def __call__(self, *args, **kwargs):
if self.status_code is None:
raise requests.ConnectionError
return MockResponse(self.status_code)
def test_up_host(monkeypatch):
monkeypatch.setattr(requests, "get", MockGet(200))
assert is_alive_host('???')
def test_down_host(monkeypatch):
monkeypatch.setattr(requests, "get", MockGet(400))
assert not is_alive_host('???')
def test_connection_failure(monkeypatch):
monkeypatch.setattr(requests, "get", MockGet(None))
assert not is_alive_host('???')