This repository has been archived by the owner on Apr 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_01_parsestring.py
53 lines (40 loc) · 1.68 KB
/
test_01_parsestring.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
from Message import Message
from MessageHeader import MessageHeader
from MessageQuestion import MessageQuestion
from ResourceRecord import ResourceRecord
from ParseString import *
def test_parse_header():
header = MessageHeader()
plain_header = header.to_string()
# reconstruct the header
lines = plain_header.splitlines()
header_id = lines[0]
header_flags = lines[1]
flags = parse_string_flag(header_flags)
print(flags)
parsed_header = MessageHeader(id=int(header_id),
qr=flags['qr'],
opcode=flags['opcode'],
aa=flags['aa'],
tc=flags['tc'],
rd=flags['rd'],
ra=flags['ra'],
rcode=flags['rcode'])
assert plain_header == parsed_header.to_string()
def test_parse_question():
question = MessageQuestion('www.google.com', 1, 1)
plain_question = question.to_string()
parsed_question = parse_string_question(plain_question)
assert plain_question == parsed_question.to_string()
def test_parse_resourcerecord():
rr = ResourceRecord('www.google.com', 1, 1, 100, '127.0.0.1')
plain_rr = rr.to_string()
parsed_rr = parse_string_resource_record(plain_rr)
assert plain_rr == parsed_rr.to_string()
def test_parse_string_msg():
header = MessageHeader()
question = MessageQuestion('www.google.com', 1, 1)
message = Message(header=header, question=question)
plain_message = message.to_string()
parsed_message = parse_string_msg(plain_message)
assert plain_message == parsed_message.to_string()