예제 #1
0
    def test_assignment_and_exceptions(self):
        """Check incorrect setter for implementation_class_uid raises"""
        primitive = ImplementationClassUIDNotification()

        ## Check assignment
        reference_uid = UID('1.2.826.0.1.3680043.9.3811.0.9.0')

        # bytes
        primitive.implementation_class_uid = (
            b'1.2.826.0.1.3680043.9.3811.0.9.0')
        assert primitive.implementation_class_uid == reference_uid

        # str
        primitive.implementation_class_uid = (
            '1.2.826.0.1.3680043.9.3811.0.9.0')
        assert primitive.implementation_class_uid == reference_uid

        # UID
        primitive.implementation_class_uid = UID(
            '1.2.826.0.1.3680043.9.3811.0.9.0')
        assert primitive.implementation_class_uid == reference_uid

        ## Check exceptions
        primitive = ImplementationClassUIDNotification()

        # No value set
        with pytest.raises(ValueError):
            item = primitive.from_primitive()

        # Non UID, bytes or str
        with pytest.raises(TypeError):
            primitive.implementation_class_uid = 45.2

        with pytest.raises(TypeError):
            primitive.implementation_class_uid = 100
예제 #2
0
    def test_uid_conformance_false(self):
        """Test UID conformance with ENFORCE_UID_CONFORMANCE = False"""
        _config.ENFORCE_UID_CONFORMANCE = False
        primitive = ImplementationClassUIDNotification()

        primitive.implementation_class_uid = 'abc'
        assert primitive.implementation_class_uid == 'abc'

        with pytest.raises(ValueError):
            primitive.implementation_class_uid = 'abc' * 22
예제 #3
0
    def test_uid_conformance_true(self):
        """Test UID conformance with ENFORCE_UID_CONFORMANCE = True"""
        _config.ENFORCE_UID_CONFORMANCE = True
        primitive = ImplementationClassUIDNotification()

        with pytest.raises(ValueError):
            primitive.implementation_class_uid = 'abc'
예제 #4
0
 def test_string(self):
     """Check the string output."""
     primitive = ImplementationClassUIDNotification()
     primitive.implementation_class_uid = UID(
         '1.2.826.0.1.3680043.9.3811.0.9.0'
     )
     assert '1.2.826.0.1.3680043.9.3811.0.9.0' in primitive.__str__()
예제 #5
0
    def test_conversion(self):
        """ Check converting to PDU item works correctly """
        primitive = ImplementationClassUIDNotification()
        primitive.implementation_class_uid = UID(
            '1.2.826.0.1.3680043.9.3811.0.9.0')
        item = primitive.from_primitive()

        assert item.encode() == (
            b"\x52\x00\x00\x20\x31\x2e\x32\x2e\x38\x32\x36\x2e\x30\x2e\x31"
            b"\x2e\x33\x36\x38\x30\x30\x34\x33\x2e\x39\x2e\x33\x38\x31\x31\x2e"
            b"\x30\x2e\x39\x2e\x30")