| 1 |
""" This is unittest file for scenario.py """ |
| 2 |
|
| 3 |
import pytest |
| 4 |
|
| 5 |
from pydnstest.scenario import Entry |
| 6 |
|
| 7 |
RCODE_FLAGS = ['NOERROR', 'FORMERR', 'SERVFAIL', 'NXDOMAIN', 'NOTIMP', 'REFUSED', 'YXDOMAIN', |
| 8 |
'YXRRSET', 'NXRRSET', 'NOTAUTH', 'NOTZONE', 'BADVERS'] |
| 9 |
OPCODE_FLAGS = ['QUERY', 'IQUERY', 'STATUS', 'NOTIFY', 'UPDATE'] |
| 10 |
FLAGS = ['QR', 'TC', 'AA', 'AD', 'RD', 'RA', 'CD'] |
| 11 |
|
| 12 |
|
| 13 |
def test_entry__get_flags(): |
| 14 |
"""Checks if all rcodes and opcodes are filtered out""" |
| 15 |
expected_flags = Entry.get_flags(FLAGS) |
| 16 |
for flag in RCODE_FLAGS + OPCODE_FLAGS: |
| 17 |
rcode_flags = Entry.get_flags(FLAGS + [flag]) |
| 18 |
assert rcode_flags == expected_flags, \ |
| 19 |
f'Entry._get_flags does not filter out "{flag}"' |
| 20 |
|
| 21 |
|
| 22 |
def test_entry__get_rcode(): |
| 23 |
""" |
| 24 |
Checks if the error is raised for multiple rcodes |
| 25 |
checks if None is returned for no rcode |
| 26 |
checks if flags and opcode are filtered out |
| 27 |
""" |
| 28 |
with pytest.raises(ValueError): |
| 29 |
Entry.get_rcode(RCODE_FLAGS[:2]) |
| 30 |
|
| 31 |
assert Entry.get_rcode(FLAGS) is None |
| 32 |
assert Entry.get_rcode([]) is None |
| 33 |
|
| 34 |
for rcode in RCODE_FLAGS: |
| 35 |
given_rcode = Entry.get_rcode(FLAGS + OPCODE_FLAGS + [rcode]) |
| 36 |
assert given_rcode is not None, f'Entry.get_rcode does not recognize {rcode}' |
| 37 |
|
| 38 |
|
| 39 |
def test_entry__get_opcode(): |
| 40 |
""" |
| 41 |
Checks if the error is raised for multiple opcodes |
| 42 |
checks if None is returned for no opcode |
| 43 |
checks if flags and opcode are filtered out |
| 44 |
""" |
| 45 |
with pytest.raises(ValueError): |
| 46 |
Entry.get_opcode(OPCODE_FLAGS[:2]) |
| 47 |
|
| 48 |
assert Entry.get_opcode(FLAGS) is None |
| 49 |
assert Entry.get_opcode([]) is None |
| 50 |
|
| 51 |
for opcode in OPCODE_FLAGS: |
| 52 |
given_rcode = Entry.get_opcode(FLAGS + RCODE_FLAGS + [opcode]) |
| 53 |
assert given_rcode is not None, f'Entry.get_opcode does not recognize {opcode}' |