-
Notifications
You must be signed in to change notification settings - Fork 0
/
utest.py
executable file
·556 lines (460 loc) · 30.8 KB
/
utest.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
import unittest
import PyParsingSdpDefs as grammar
import Sdp as objects
def verify_line(test_obj, parsed_res, expected_line_data):
#print("verifying:\npyparsing object:\n%s\nexpected_data:\n%s" % (parsed_res.dump(), expected_line_data))
expected_field_value_tuples = expected_line_data["fields"]
for field, value in expected_field_value_tuples:
#print("looking at field %s with value %s" % (field, value))
if isinstance(value, dict):
#print("meta-field, re-calling")
verify_line(test_obj, parsed_res[field], value)
else:
test_obj.assertIn(field, parsed_res, "Couldn't find %s in\n%s" % (field, parsed_res.dump()))
if isinstance(value, list):
#print("repeated field")
# If it's a repeated field (instance of list) grab it asList so we get the raw list instead of the
# ParseResults object
test_obj.assertEqual(parsed_res[field].asList(), value)
else:
test_obj.assertEqual(parsed_res[field], value)
def verify_multi_line(test_obj, parsed_results, expected_lines_data):
test_obj.assertEqual(len(parsed_results), len(expected_lines_data))
for parsed_res, expected_line_data in zip(parsed_results, expected_lines_data):
verify_line(test_obj, parsed_res, expected_line_data)
def verify_section(test_obj, parsed_res, expected_section_data):
expected_field_value_tuples = expected_section_data["fields"]
for field, line in expected_field_value_tuples:
test_obj.assertIn(field, parsed_res, "Couldn't find %s in\n%s" % (field, parsed_res.dump()))
if isinstance(line, list):
verify_multi_line(test_obj, parsed_res[field], line)
else:
verify_line(test_obj, parsed_res[field], line)
def build_line_str(line_data):
prefix = line_data["prefix"]
fields = line_data["fields"]
join_token = line_data["join_token"] if "join_token" in line_data else " "
str = prefix
first = True
for field_name, field_value in fields:
if isinstance(field_value, dict):
# meta field
if first:
str += build_line_str(field_value)
first = False
else:
str += (join_token + build_line_str(field_value))
elif isinstance(field_value, list):
# repeated field
if first:
str += " ".join(field_sub_value for field_sub_value in field_value)
first = False
else:
str += (join_token + " ".join(field_sub_value for field_sub_value in field_value))
else:
if first:
str += field_value
first = False
else:
str += (join_token + field_value)
return str
#prefix = line_data["prefix"]
#fields = line_data["fields"]
#join_token = line_data["join_token"] if "join_token" in line_data else " "
# We may have a line that has a 'meta-field' (a "line within a line"). Mainly this is the case for a= lines
# TODO: for now we'll assume the presence of at least one meta-field implies that there are no normal fields
# (so far that's all I've seen)
#meta_fields = [field_value for field_name, field_value in fields if isinstance(field_value, dict)]
#if meta_fields:
# return prefix + (join_token.join(build_line_str(sub_field) for sub_field in meta_fields))
#else:
# # A line may have a repeated sub-field, if so: detect it and join the values with spaces
# def check_for_repeated(field):
# if isinstance(field, list):
# return " ".join(field_sub_value for field_sub_value in field)
# else:
# return field
# # Check each value and call check_for_repeated to check if one of them is a repeated field, if so,
# # check_for_repeated will detect it and concatenate it into a single string for us
# return prefix + join_token.join(map(check_for_repeated, [field[1] for field in fields]))
def build_section_str(section_data):
fields = section_data["fields"]
str = ""
for field_name, field_value in fields:
if isinstance(field_value, list):
# multi-line field
str += "\n".join(build_line_str(sub_field) for sub_field in field_value)
else:
str += build_line_str(field_value)
str += "\n"
return str
def parse_and_verify_line(test_obj, line_grammar, line_data):
line_str = build_line_str(line_data)
#print("got line str %s" % line_str)
res = line_grammar.parseString(line_str)
res = res[0]
verify_line(test_obj, res, line_data)
def parse_and_test_section(test_obj, section_grammar, section_data):
res = section_grammar.parseString(build_section_str(section_data))
verify_section(test_obj, res, section_data)
# Some sample values for each of the line types
class SampleData(object):
vline_data = {"prefix": "v=",
"fields": [("VERSION_NUMBER", "0")]
}
oline_data = {"prefix": "o=",
"fields": [("USERNAME", "-"),
("SESSION_ID", "4143029973181426116"),
("SESSION_VERSION", "2"),
("NETTYPE", "IN"),
("ADDRTYPE", "IP4"),
("IP_ADDR", "127.0.0.1")]}
sline_data = {"prefix": "s=",
"fields": [("SESSION_NAME", "-")]}
iline_data = {"prefix": "i=",
"fields": [("SESSION_INFORMATION", "Test Session")]}
cline_data = {"prefix": "c=",
"fields": [("NETTYPE", "IN"),
("ADDRTYPE", "IP4"),
("IP_ADDR", "127.0.0.1")]}
bline_data = {"prefix": "b=",
"join_token": ":",
"fields": [("BWTYPE", "AS"),
("BW", "128")]}
tline_data = {"prefix": "t=",
"fields": [("START_TIME", "1234567"),
("STOP_TIME", "2345678")]}
mline_data = {"prefix": "m=",
"fields": [("MEDIA_TYPE", "audio"),
("PORT", "0"),
("PROTO", "RTP/SAVPF"),
("FORMATS", ["111", "222", "333", "444"])]}
class TestLineParsing(unittest.TestCase):
def test_parse_version_line(self):
parse_and_verify_line(self, grammar.version_line, SampleData.vline_data)
def test_parse_originator_line(self):
parse_and_verify_line(self, grammar.originator_line, SampleData.oline_data)
def test_parse_session_name_line(self):
parse_and_verify_line(self, grammar.session_name_line, SampleData.sline_data)
def test_parse_session_information_line(self):
parse_and_verify_line(self, grammar.session_information_line, SampleData.iline_data)
def test_parse_connection_information_line(self):
parse_and_verify_line(self, grammar.connection_information_line, SampleData.cline_data)
def test_parse_bandwidth_information_line(self):
parse_and_verify_line(self, grammar.bandwidth_information_line, SampleData.bline_data)
def test_parse_time_description_line(self):
parse_and_verify_line(self, grammar.time_description_line, SampleData.tline_data)
def test_parse_generic_application_line(self):
aline_data = {"prefix": "a=",
"fields": [("GENERIC_APPLICATION_LINE", {"prefix": "",
"fields": [("CONTENT", "some unknown generic line")]})]}
parse_and_verify_line(self, grammar.application_line, aline_data)
def test_parse_direction_application_line(self):
aline_data = {"prefix": "a=",
"fields": [("DIRECTION_APPLICATION_LINE", {"prefix": "",
"fields": [("DIRECTION", "sendrecv")]})]}
parse_and_verify_line(self, grammar.application_line, aline_data)
def test_parse_rtcp_application_line(self):
aline_data = {"prefix": "a=",
"fields": [("RTCP_APPLICATION_LINE", {"prefix": "rtcp:",
"fields": [("PORT", "1"),
("NETTYPE", "IN"),
("ADDRTYPE", "IP4"),
("IP_ADDR", "127.0.0.1")]})]}
parse_and_verify_line(self, grammar.application_line, aline_data)
def test_parse_ice_ufrag_application_line(self):
aline_data = {"prefix": "a=",
"fields": [("ICE_UFRAG_APPLICATION_LINE", {"prefix": "ice-ufrag:",
"fields": [("USERNAME", "abcdefghi1234+ab")]})]}
parse_and_verify_line(self, grammar.application_line, aline_data)
def test_parse_ice_pwd_application_line(self):
aline_data = {"prefix": "a=",
"fields": [("ICE_PWD_APPLICATION_LINE", {"prefix": "ice-pwd:",
"fields": [("PASSWORD", "abcdefghi1234+ab")]})]}
parse_and_verify_line(self, grammar.application_line, aline_data)
def test_parse_group_application_line(self):
aline_data = {"prefix": "a=",
"fields": [("GROUP_APPLICATION_LINE", {"prefix": "group:",
"fields": [("PURPOSE", "LS"),
("IDS", ["1", "2"])]})]}
parse_and_verify_line(self, grammar.application_line, aline_data)
def test_parse_mid_application_line(self):
aline_data = {"prefix": "a=",
"fields": [("MID_APPLICATION_LINE", {"prefix": "mid:",
"fields": [("ID", "audio")]})]}
parse_and_verify_line(self, grammar.application_line, aline_data)
def test_parse_rtcp_mux_application_line(self):
aline_data = {"prefix": "a=",
"fields": [("RTCP_MUX_APPLICATION_LINE", {"prefix": "",
"fields": [("RTCP_MUX", "rtcp-mux")]})]}
parse_and_verify_line(self, grammar.application_line, aline_data)
def test_parse_rtpmap_application_line(self):
aline_data = {"prefix": "a=",
"fields": [("RTPMAP_APPLICATION_LINE", {"prefix": "rtpmap:",
"fields": [("PT", "111"),
("RTPMAP_CODEC_INFO", {"prefix": "",
"join_token": "/",
"fields": [("ENCODING_NAME", "OPUS"),
("CLOCK_RATE", "48000"),
("ENCODING_PARAMETERS", "2")]})]})]}
parse_and_verify_line(self, grammar.application_line, aline_data)
def test_parse_media_description_line(self):
parse_and_verify_line(self, grammar.media_description_line, SampleData.mline_data)
class TestSectionParsing(unittest.TestCase):
def test_parse_session_section(self):
generic_aline_data = {"prefix": "a=",
"fields": [("GENERIC_APPLICATION_LINE", {"prefix": "",
"fields": [("CONTENT", "some unknown generic line")]})]}
direction_aline_data = {"prefix": "a=",
"fields": [("DIRECTION_APPLICATION_LINE", {"prefix": "",
"fields": [("DIRECTION", "sendrecv")]})]}
rtcp_aline_data = {"prefix": "a=",
"fields": [("RTCP_APPLICATION_LINE", {"prefix": "rtcp:",
"fields": [("PORT", "1"),
("NETTYPE", "IN"),
("ADDRTYPE", "IP4"),
("IP_ADDR", "127.0.0.1")]})]}
session_section_data = {"fields": [("VERSION_LINE", SampleData.vline_data),
("ORIGINATOR_LINE", SampleData.oline_data),
("SESSION_NAME_LINE", SampleData.sline_data),
("SESSION_INFORMATION_LINE", SampleData.iline_data),
("CONNECTION_INFORMATION_LINE", SampleData.cline_data),
("BANDWIDTH_INFORMATION_LINES", [SampleData.bline_data]),
("TIME_DESCRIPTION_LINES", [SampleData.tline_data]),
("APPLICATION_LINES", [generic_aline_data, direction_aline_data, rtcp_aline_data])]}
parse_and_test_section(self, grammar.session_section, session_section_data)
def test_parse_media_section(self):
mline_data = {"prefix": "m=",
"fields": [("MEDIA_TYPE", "audio"),
("PORT", "0"),
("PROTO", "RTP/SAVPF"),
("FORMATS", ["111", "222", "333", "444"])]}
iline_data = {"prefix": "i=",
"fields": [("SESSION_INFORMATION", "Test Session")]}
cline_data = {"prefix": "c=",
"fields": [("NETTYPE", "IN"),
("ADDRTYPE", "IP4"),
("IP_ADDR", "127.0.0.1")]}
bline_data = {"prefix": "b=",
"join_token": ":",
"fields": [("BWTYPE", "AS"),
("BW", "128")]}
generic_aline_data = {"prefix": "a=",
"fields": [("GENERIC_APPLICATION_LINE", {"prefix": "",
"fields": [("CONTENT", "some unknown generic line")]})]}
direction_aline_data = {"prefix": "a=",
"fields": [("DIRECTION_APPLICATION_LINE", {"prefix": "",
"fields": [("DIRECTION", "sendrecv")]})]}
rtcp_aline_data = {"prefix": "a=",
"fields": [("RTCP_APPLICATION_LINE", {"prefix": "rtcp:",
"fields": [("PORT", "1"),
("NETTYPE", "IN"),
("ADDRTYPE", "IP4"),
("IP_ADDR", "127.0.0.1")]})]}
media_section_data = {"fields": [("MEDIA_DESCRIPTION_LINE", mline_data),
("SESSION_INFORMATION_LINE", iline_data),
("BANDWIDTH_INFORMATION_LINES", [bline_data]),
("APPLICATION_LINES", [generic_aline_data, direction_aline_data, rtcp_aline_data])]}
parse_and_test_section(self, grammar.media_section, media_section_data)
def verify_line_object(test_obj, line_object, expected_data):
#print("verifying line ===\n%s\n===" % line_object.to_string())
for field_name, field_value in expected_data["fields"]:
#print("looking at field %s with value %s" % (field_name, field_value))
# Meta-line
if isinstance(field_value, dict):
#print("meta field, re-call")
verify_line_object(test_obj, getattr(line_object, field_name.lower()), field_value)
else:
#print("normal field")
test_obj.assertEqual(field_value, getattr(line_object, field_name.lower()))
def build_and_verify_line_object(test_obj, line_obj_type, line_grammar, line_data):
line_str = build_line_str(line_data)
#print("got line string: %s" % line_str)
res = line_grammar.parseString(line_str)
res = res[0]
#print("got result: %s" % res.dump())
obj = line_obj_type(res)
verify_line_object(test_obj, obj, line_data)
class TestLineObjectCreation(unittest.TestCase):
def test_create_version_line_object(self):
build_and_verify_line_object(self, objects.VersionLine, grammar.version_line, SampleData.vline_data)
def test_create_originator_line_object(self):
build_and_verify_line_object(self, objects.OriginatorLine, grammar.originator_line, SampleData.oline_data)
def test_create_session_name_line_object(self):
build_and_verify_line_object(self, objects.SessionNameLine, grammar.session_name_line, SampleData.sline_data)
def test_create_session_information_line_object(self):
build_and_verify_line_object(self, objects.SessionInformationLine, grammar.session_information_line, SampleData.iline_data)
def test_create_connection_information_line_object(self):
build_and_verify_line_object(self, objects.ConnectionInformationLine, grammar.connection_information_line, SampleData.cline_data)
def test_create_bandwidth_information_line_object(self):
build_and_verify_line_object(self, objects.BandwidthInformationLine, grammar.bandwidth_information_line, SampleData.bline_data)
def test_create_time_description_line_object(self):
build_and_verify_line_object(self, objects.TimeDescriptionLine, grammar.time_description_line, SampleData.tline_data)
def test_create_generic_application_line_object(self):
aline_data = {"prefix": "a=",
"fields": [("GENERIC_APPLICATION_LINE", {"prefix": "",
"fields": [("CONTENT", "some unknown generic line")]})]}
build_and_verify_line_object(self, objects.ApplicationLine, grammar.application_line, aline_data)
def test_create_direction_application_line_object(self):
aline_data = {"prefix": "a=",
"fields": [("DIRECTION_APPLICATION_LINE", {"prefix": "",
"fields": [("DIRECTION", "sendrecv")]})]}
build_and_verify_line_object(self, objects.ApplicationLine, grammar.application_line, aline_data)
def test_create_rtcp_application_line_object(self):
aline_data = {"prefix": "a=",
"fields": [("RTCP_APPLICATION_LINE", {"prefix": "rtcp:",
"fields": [("PORT", "123"),
("NETTYPE", "IN"),
("ADDRTYPE", "IP4"),
("IP_ADDR", "127.0.0.1")]})]}
build_and_verify_line_object(self, objects.ApplicationLine, grammar.application_line, aline_data)
def test_create_ice_ufrag_application_line_object(self):
aline_data = {"prefix": "a=",
"fields": [("ICE_UFRAG_APPLICATION_LINE", {"prefix": "ice-ufrag:",
"fields": [("USERNAME", "abcdefghi1234+ab")]})]}
build_and_verify_line_object(self, objects.ApplicationLine, grammar.application_line, aline_data)
def test_create_ice_pwd_application_line_object(self):
aline_data = {"prefix": "a=",
"fields": [("ICE_PWD_APPLICATION_LINE", {"prefix": "ice-pwd:",
"fields": [("PASSWORD", "abcdefghi1234+ab")]})]}
build_and_verify_line_object(self, objects.ApplicationLine, grammar.application_line, aline_data)
def test_create_group_application_line_object(self):
aline_data = {"prefix": "a=",
"fields": [("GROUP_APPLICATION_LINE", {"prefix": "group:",
"fields": [("PURPOSE", "LS"),
("IDS", ["1", "2"])]})]}
build_and_verify_line_object(self, objects.ApplicationLine, grammar.application_line, aline_data)
def test_create_mid_application_line_object(self):
aline_data = {"prefix": "a=",
"fields": [("MID_APPLICATION_LINE", {"prefix": "mid:",
"fields": [("ID", "audio")]})]}
build_and_verify_line_object(self, objects.ApplicationLine, grammar.application_line, aline_data)
def test_create_rtcp_mux_application_line_object(self):
aline_data = {"prefix": "a=",
"fields": [("RTCP_MUX_APPLICATION_LINE", {"prefix": "",
"fields": [("RTCP_MUX", "rtcp-mux")]})]}
build_and_verify_line_object(self, objects.ApplicationLine, grammar.application_line, aline_data)
def test_create_rtpmap_application_line_object(self):
aline_data = {"prefix": "a=",
"fields": [("RTPMAP_APPLICATION_LINE", {"prefix": "rtpmap:",
"fields": [("PT", "111"),
("RTPMAP_CODEC_INFO", {"prefix": "",
"join_token": "/",
"fields": [("ENCODING_NAME", "OPUS"),
("CLOCK_RATE", "48000"),
("ENCODING_PARAMETERS", "2")]})]})]}
build_and_verify_line_object(self, objects.ApplicationLine, grammar.application_line, aline_data)
def test_create_media_description_line_object(self):
build_and_verify_line_object(self, objects.MediaDescriptionLine, grammar.media_description_line, SampleData.mline_data)
def verify_multi_line_object(test_obj, multi_line_obj, expected_data):
for sub_line, expected_line in zip(multi_line_obj.sub_lines, expected_data):
verify_line_object(test_obj, sub_line, expected_line)
def verify_section_object(test_obj, session_object, expected_data):
for field_name, field_value in expected_data["fields"]:
if isinstance(field_value, list):
verify_multi_line_object(test_obj, getattr(session_object, field_name.lower()), field_value)
else:
verify_line_object(test_obj, getattr(session_object, field_name.lower()), field_value)
def build_and_verify_section_object(test_obj, section_obj_type, section_grammar, section_data):
res = section_grammar.parseString(build_section_str(section_data))
section = section_obj_type(res)
verify_section_object(test_obj, section, section_data)
class TestSectionObjectCreation(unittest.TestCase):
def test_create_session_section_object(self):
generic_aline_data = {"prefix": "a=",
"fields": [("GENERIC_APPLICATION_LINE", {"prefix": "",
"fields": [("CONTENT", "some unknown generic line")]})]}
direction_aline_data = {"prefix": "a=",
"fields": [("DIRECTION_APPLICATION_LINE", {"prefix": "",
"fields": [("DIRECTION", "sendrecv")]})]}
rtcp_aline_data = {"prefix": "a=",
"fields": [("RTCP_APPLICATION_LINE", {"prefix": "rtcp:",
"fields": [("PORT", "1"),
("NETTYPE", "IN"),
("ADDRTYPE", "IP4"),
("IP_ADDR", "127.0.0.1")]})]}
session_section_data = {"fields": [("VERSION_LINE", SampleData.vline_data),
("ORIGINATOR_LINE", SampleData.oline_data),
("SESSION_NAME_LINE", SampleData.sline_data),
("SESSION_INFORMATION_LINE", SampleData.iline_data),
("CONNECTION_INFORMATION_LINE", SampleData.cline_data),
("BANDWIDTH_INFORMATION_LINES", [SampleData.bline_data]),
("TIME_DESCRIPTION_LINES", [SampleData.tline_data]),
("APPLICATION_LINES", [generic_aline_data, direction_aline_data, rtcp_aline_data])]}
build_and_verify_section_object(self, objects.SessionSection, grammar.session_section, session_section_data)
def test_create_media_section_object(self):
generic_aline_data = {"prefix": "a=",
"fields": [("GENERIC_APPLICATION_LINE", {"prefix": "",
"fields": [("CONTENT", "some unknown generic line")]})]}
direction_aline_data = {"prefix": "a=",
"fields": [("DIRECTION_APPLICATION_LINE", {"prefix": "",
"fields": [("DIRECTION", "sendrecv")]})]}
rtcp_aline_data = {"prefix": "a=",
"fields": [("RTCP_APPLICATION_LINE", {"prefix": "rtcp:",
"fields": [("PORT", "1"),
("NETTYPE", "IN"),
("ADDRTYPE", "IP4"),
("IP_ADDR", "127.0.0.1")]})]}
media_section_data = {"fields": [("MEDIA_DESCRIPTION_LINE", SampleData.mline_data),
("SESSION_INFORMATION_LINE", SampleData.iline_data),
("CONNECTION_INFORMATION_LINE", SampleData.cline_data),
("BANDWIDTH_INFORMATION_LINES", [SampleData.bline_data]),
("APPLICATION_LINES", [generic_aline_data, direction_aline_data, rtcp_aline_data])]}
build_and_verify_section_object(self, objects.MediaSection, grammar.media_section, media_section_data)
def build_sdp_str(sdp_data):
fields = sdp_data["fields"]
str = ""
for field_name, field_value in fields:
if isinstance(field_value, list):
str += "\n".join(build_section_str(sub_field) for sub_field in field_value)
else:
str += build_section_str(field_value)
return str
def verify_multi_section_object(test_obj, multi_section_obj, expected_data):
for sub_section, expected_section_data in zip(multi_section_obj.sub_sections, expected_data):
verify_section_object(test_obj, sub_section, expected_section_data)
def verify_sdp_object(test_obj, sdp_object, expected_data):
for field_name, field_value in expected_data["fields"]:
if isinstance(field_value, list):
verify_multi_section_object(test_obj, getattr(sdp_object, field_name.lower()), field_value)
else:
verify_section_object(test_obj, getattr(sdp_object, field_name.lower()), field_value)
def build_and_verify_sdp_object(test_obj, sdp_obj_type, sdp_data):
sdp_str = build_sdp_str(sdp_data)
sdp_obj = sdp_obj_type(sdp_str)
verify_sdp_object(test_obj, sdp_obj, sdp_data)
class TestSdpObjectCreation(unittest.TestCase):
def test_create_sdp_object(self):
generic_aline_data = {"prefix": "a=",
"fields": [("GENERIC_APPLICATION_LINE", {"prefix": "",
"fields": [("CONTENT", "some unknown generic line")]})]}
direction_aline_data = {"prefix": "a=",
"fields": [("DIRECTION_APPLICATION_LINE", {"prefix": "",
"fields": [("DIRECTION", "sendrecv")]})]}
rtcp_aline_data = {"prefix": "a=",
"fields": [("RTCP_APPLICATION_LINE", {"prefix": "rtcp:",
"fields": [("PORT", "1"),
("NETTYPE", "IN"),
("ADDRTYPE", "IP4"),
("IP_ADDR", "127.0.0.1")]})]}
session_section_data = {"fields": [("VERSION_LINE", SampleData.vline_data),
("ORIGINATOR_LINE", SampleData.oline_data),
("SESSION_NAME_LINE", SampleData.sline_data),
("SESSION_INFORMATION_LINE", SampleData.iline_data),
("CONNECTION_INFORMATION_LINE", SampleData.cline_data),
("BANDWIDTH_INFORMATION_LINES", [SampleData.bline_data]),
("TIME_DESCRIPTION_LINES", [SampleData.tline_data]),
("APPLICATION_LINES", [generic_aline_data, direction_aline_data, rtcp_aline_data])]}
media_section_data = {"fields": [("MEDIA_DESCRIPTION_LINE", SampleData.mline_data),
("SESSION_INFORMATION_LINE", SampleData.iline_data),
("CONNECTION_INFORMATION_LINE", SampleData.cline_data),
("BANDWIDTH_INFORMATION_LINES", [SampleData.bline_data]),
("APPLICATION_LINES", [generic_aline_data, direction_aline_data, rtcp_aline_data])]}
sdp_data = {"fields": [("SESSION_SECTION", session_section_data),
("MEDIA_SECTIONS", [media_section_data])]}
#build_and_verify_sdp_object(self, objects.Sdp, sdp_data)
sdp = objects.Sdp(build_sdp_str(sdp_data))
print(sdp.to_string())
print(sdp.audio.direction)
if __name__ == '__main__':
unittest.main()