-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemitter_test.py
76 lines (52 loc) · 2.21 KB
/
emitter_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
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
import unittest
import requests
import httpretty
from emitter import Emitter
targetHost = "http://localhost"
suiteId = "test_suite"
apiPath = targetHost + "/tf/v1/suites/" + suiteId + "/runs"
class EmitterTest(unittest.TestCase):
def setUp(self):
httpretty.enable()
self.emitter = Emitter(suiteId, targetHost, True)
def tearDown(self):
httpretty.disable()
httpretty.reset()
def get_full_dict(self):
dict = {}
dict['id'] = 's1'
dict['longname'] = 'a-very-long-suite-name'
dict['doc'] = 'this is where the suite documentation goes'
dict['metadata'] = []
dict['source'] = 'path_to_file'
dict['suites'] = []
dict['tests'] = []
dict['totaltests'] = 17
dict['starttime'] = "20161210 00:00:00.000"
dict['endtime'] = "20161210 02:02:03.004"
return dict
def test_start_suite(self):
httpretty.register_uri(httpretty.POST, apiPath, body='{ "id": 1}')
self.emitter.start_suite("start_suite", self.get_full_dict())
result = httpretty.last_request().parsed_body
self.assertEqual(17, result['tests'], 17)
self.assertEqual("2016-12-09T23:00:00.000Z", result['startTime'])
self.assertEqual(2, len(result))
def test_start_suite_is_ignored_if_not_persistent(self):
self.emitter = Emitter(suiteId, targetHost, False)
self.emitter.start_suite("start_suite", self.get_full_dict())
# if a call was made, we would get an connection error here
def test_end_suite(self):
runId = "2"
httpretty.register_uri(httpretty.PUT, apiPath + "/" + runId)
self.emitter.runId = runId
self.emitter.end_suite("end_suite", self.get_full_dict())
result = httpretty.last_request().parsed_body
self.assertEqual("2016-12-10T01:02:03.004Z", result['endTime'])
self.assertEqual(1, len(result))
def test_end_suite_is_ignored_if_not_persistent(self):
self.emitter = Emitter(suiteId, targetHost, False)
self.emitter.end_suite("end_suite", self.get_full_dict())
# if a call was made, we would get an connection error here
if __name__ == '__main__':
unittest.main()