Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Corey Bonnell committed Jan 2, 2024
1 parent 4ad739f commit 55201e3
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion tests/test_universal_constructed.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SequenceTest(univ.Sequence):
SequenceTest.componentType = namedtype.NamedTypes(
namedtype.NamedType('first', char.PrintableString()),
namedtype.OptionalNamedType('optional', char.UTF8String()),
namedtype.DefaultedNamedType('default', useful.UTCTime()),
namedtype.DefaultedNamedType('default', useful.UTCTime().subtype(value='251231235959Z')),
namedtype.NamedType('last', char.PrintableString()),
)

Expand Down Expand Up @@ -87,3 +87,40 @@ def test_setof_two_elements():
def test_setof_two_elements_out_order():
with pytest.raises(PyAsn1Error):
decoded, _ = _wrapper(b'3106130142130141', SetOfTest())


def test_sequence_no_default_or_optional():
decoded, _ = _wrapper(b'3006130141130142', SequenceTest())

assert str(decoded['first']) == 'A'
assert str(decoded['default']) == '251231235959Z'
assert not decoded['optional'].isValue
assert str(decoded['last']) == 'B'


def test_sequence_with_default_no_optional():
decoded, _ = _wrapper(b'3015130141170D3234303130313030303030305A130142', SequenceTest())

assert str(decoded['first']) == 'A'
assert str(decoded['default']) == '240101000000Z'
assert not decoded['optional'].isValue
assert str(decoded['last']) == 'B'


def test_sequence_with_default_and_optional():
decoded, _ = _wrapper(b'30181301410C0161170D3234303130313030303030305A130142', SequenceTest())

assert str(decoded['first']) == 'A'
assert str(decoded['optional']) == 'a'
assert str(decoded['default']) == '240101000000Z'
assert str(decoded['last']) == 'B'


def test_sequence_missing_element():
with pytest.raises(PyAsn1Error):
decoded, _ = _wrapper(b'30151301410C0161170D3234303130313030303030305A', SequenceTest())


def test_encoded_default_value():
with pytest.raises(PyAsn1Error):
decoded, _ = _wrapper(b'30181301410C0161170D3235313233313233353935395A130142', SequenceTest())

0 comments on commit 55201e3

Please sign in to comment.