-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathtest_media.py
175 lines (154 loc) · 4.88 KB
/
test_media.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
"""Test log.py functions."""
import responses
import datetime
from .mocktestcase import MockTestCase
class TestMedia(MockTestCase):
"""Tests for media.py."""
@responses.activate
def test_download_file(self):
self.add_init_responses()
body = '*'.join([str(x) for x in range(17)])
responses.add(
responses.GET,
self.format_url('RPC_Loadfile//mnt/sd/test.dat'),
body=body,
status=200)
c = self.get_amcrest().camera
content = c.download_file('/mnt/sd/test.dat').decode('utf-8')
self.assertEqual(body, content)
@responses.activate
def test_log_find(self):
self.add_init_responses()
responses.add(
responses.GET,
self.format_url('mediaFileFind.cgi', {
'action': 'factory.create'}),
body='result=123\r\n',
status=200)
responses.add(
responses.GET,
self.format_url('mediaFileFind.cgi', {
'action': 'findFile',
'object': 123,
'condition.Channel': 0,
'condition.StartTime': datetime.datetime(2020, 1, 2, 3, 4, 5),
'condition.EndTime': datetime.datetime(2020, 1, 2, 3, 4, 10)}),
body='OK\r\n',
status=200)
url_next = self.format_url('mediaFileFind.cgi', {
'action': 'findNextFile',
'object': 123,
'count': 100})
responses.add(
responses.GET,
url_next,
body='\r\n'.join('''found=2
items[0].Channel=0
items[0].Cluster=0
items[0].Compressed=false
items[0].Disk=0
items[0].Duration=480
items[0].EndTime=2020-01-06 06:13:00
items[0].Events[0]=VideoMotion
items[0].FilePath=/mnt/sd/2020-01-06/001/dav/06/06.05.00-06.13.00[M][0@0][0].mp4
items[0].Flags[0]=Event
items[0].Length=248362892
items[0].Overwrites=0
items[0].Partition=0
items[0].Redundant=false
items[0].Repeat=0
items[0].StartTime=2020-01-06 06:05:00
items[0].Summary.TrafficCar.PlateColor=Yellow
items[0].Summary.TrafficCar.PlateNumber=
items[0].Summary.TrafficCar.PlateType=Yellow
items[0].Summary.TrafficCar.Speed=60
items[0].Summary.TrafficCar.VehicleColor=White
items[0].SummaryOffset=0
items[0].Type=dav
items[0].WorkDir=/mnt/sd
items[0].WorkDirSN=0
items[1].Channel=0
items[1].Cluster=0
items[1].Compressed=false
items[1].Disk=0
items[1].Duration=480
items[1].EndTime=2020-01-06 06:21:00
items[1].Events[0]=VideoMotion
items[1].FilePath=/mnt/sd/2020-01-06/001/dav/06/06.13.00-06.21.00[M][0@0][0].mp4
items[1].Flags[0]=Event
items[1].Length=241799877
items[1].Overwrites=0
items[1].Partition=0
items[1].Redundant=false
items[1].Repeat=0
items[1].StartTime=2020-01-06 06:13:00
items[1].Summary.TrafficCar.PlateColor=Yellow
items[1].Summary.TrafficCar.PlateNumber=
items[1].Summary.TrafficCar.PlateType=Yellow
items[1].Summary.TrafficCar.Speed=60
items[1].Summary.TrafficCar.VehicleColor=White
items[1].SummaryOffset=0
items[1].Type=dav
items[1].WorkDir=/mnt/sd
items[1].WorkDirSN=0
'''.splitlines()),
status=200)
responses.add(
responses.GET,
url_next,
body='\r\n'.join('''found=2
items[0].Channel=0
items[0].Cluster=0
items[0].Compressed=false
items[0].Disk=0
items[0].Duration=34
items[0].EndTime=2020-01-06 06:36:44
items[0].Events[0]=VideoMotion
items[0].FilePath=/mnt/sd/2020-01-06/001/dav/06/06.36.10-06.36.44[M][0@0][0].mp4
items[0].Flags[0]=Event
items[0].Length=17561629
items[0].Overwrites=0
items[0].Partition=0
items[0].Redundant=false
items[0].Repeat=0
items[0].StartTime=2020-01-06 06:36:10
items[0].Summary.TrafficCar.PlateColor=Yellow
items[0].Summary.TrafficCar.PlateNumber=
items[0].Summary.TrafficCar.PlateType=Yellow
items[0].Summary.TrafficCar.Speed=60
items[0].Summary.TrafficCar.VehicleColor=White
items[0].SummaryOffset=0
items[0].Type=dav
items[0].WorkDir=/mnt/sd
items[0].WorkDirSN=0
'''.splitlines()),
status=200)
responses.add(
responses.GET,
url_next,
body='\r\n'.join('''found=0
'''.splitlines()),
status=200)
responses.add(
responses.GET,
self.format_url('mediaFileFind.cgi', {
'action': 'factory.close',
'object': 123}),
body='\r\n'.join('''Error
ErrorID=2, Detail=Invalid Request!
'''.splitlines()),
status=200)
responses.add(
responses.GET,
self.format_url('mediaFileFind.cgi', {
'action': 'factory.destroy',
'object': 123}),
body='\r\n'.join('''Error
ErrorID=2, Detail=Invalid Request!
'''.splitlines()),
status=200)
c = self.get_amcrest().camera
time_start = datetime.datetime(2020, 1, 2, 3, 4, 5)
time_end = datetime.datetime(2020, 1, 2, 3, 4, 10)
media = list(c.find_files(time_start, time_end))
self.assertEqual(2, len(media))