def test_read_dns_questions_no_questions(self): """ Test case to attempt to decode 0 questions. In other words, decode nothing and return an empty list. """ dns_questions: List[DNSQuestion] = DNSMessage._read_dns_questions( BytesIO(self.three_consecutive_dns_questions_encoded), BytesIO(self.three_consecutive_dns_questions_encoded), 0) self.assertEqual(len(dns_questions), 0)
def test_read_dns_questions(self): """ Test case to decode three consecutive dns questions. """ dns_questions: List[DNSQuestion] = DNSMessage._read_dns_questions( BytesIO(self.three_consecutive_dns_questions_encoded), BytesIO(self.three_consecutive_dns_questions_encoded), 3) # Check that the first question was properly decoded self.assertEqual(dns_questions[0].name, 'www.cs.ubc.ca') self.assertEqual(dns_questions[0].type, 1) self.assertEqual(dns_questions[0].response_class, 1) # Check that the second question was properly decoded self.assertEqual(dns_questions[1].name, 'hello.world.its.me') self.assertEqual(dns_questions[1].type, 2) self.assertEqual(dns_questions[1].response_class, 2) # Check that the third question was properly decoded self.assertEqual(dns_questions[2].name, 'oh.hi.there.stranger') self.assertEqual(dns_questions[2].type, 3) self.assertEqual(dns_questions[2].response_class, 3)