-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_wait.py
106 lines (78 loc) · 2.64 KB
/
test_wait.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import os
from unittest import TestCase, mock
import requests_mock
from requests import RequestException
import wait
class TestWait(TestCase):
@mock.patch.dict(os.environ, {'URL': 'http://test'})
@requests_mock.mock()
def test_is_up(self, m):
# Given
m.get('http://test/actuator/health', json={'status': 'UP'})
# When
is_up = wait.is_up(None)
# Then
self.assertTrue(is_up)
@mock.patch.dict(os.environ, {'URL': 'http://test'})
@requests_mock.mock()
def test_not_up(self, m):
# Given
m.get('http://test/actuator/health', json={'status': 'DOWN'})
# When
is_up = wait.is_up(None)
# Then
self.assertFalse(is_up)
@mock.patch.dict(os.environ, {'URL': 'http://test'})
@requests_mock.mock()
def test_up_non_200(self, m):
# Given
m.get('http://test/actuator/health', status_code=400)
# When
is_commit = wait.is_up(None)
# Then
self.assertFalse(is_commit)
@mock.patch.dict(os.environ, {'URL': 'http://test'})
@requests_mock.mock()
def test_up_network_exception(self, m):
# Given
m.get('http://test/actuator/health', exc=RequestException)
# When
is_up = wait.is_up(None)
# Then
self.assertFalse(is_up)
@mock.patch.dict(os.environ, {'URL': 'http://test', 'COMMIT': 'abc'})
@requests_mock.mock()
def test_is_on_commit(self, m):
# Given
m.get('http://test/actuator/info', json={'git': {'commit': {'id': 'abc'}}})
# When
is_commit = wait.is_on_commit(None, 'abc')
# Then
self.assertTrue(is_commit)
@mock.patch.dict(os.environ, {'URL': 'http://test', 'COMMIT': 'abc'})
@requests_mock.mock()
def test_not_on_commit(self, m):
# Given
m.get('http://test/actuator/info', json={'git': {'commit': {'id': 'abc'}}})
# When
is_commit = wait.is_on_commit(None, 'abd')
# Then
self.assertFalse(is_commit)
@mock.patch.dict(os.environ, {'URL': 'http://test'})
@requests_mock.mock()
def test_on_commit_non_200(self, m):
# Given
m.get('http://test/actuator/info', status_code=400)
# When
is_commit = wait.is_on_commit(None, 'abd')
# Then
self.assertFalse(is_commit)
@mock.patch.dict(os.environ, {'URL': 'http://test'})
@requests_mock.mock()
def test_on_commit_network_exception(self, m):
# Given
m.get('http://test/actuator/info', exc=RequestException)
# When
is_up = wait.is_on_commit(None, 'abc')
# Then
self.assertFalse(is_up)