def test_decode_build_is_idempotent(self): u1 = urn.encode('component', owner__name='org%', name='name%', version='version%') m, f = urn.decode(u1) u3 = urn.encode(m, **f) self.assertEqual(u1, u3)
def test_decode_raise_exception_if_missing_object_type(self): with self.assertRaises(urn.URNValidationError): urn.decode('urn:dje::dsds')
def test_decode_raise_exception_if_too_long3(self): with self.assertRaises(urn.URNValidationError): urn.decode('urn:dje:license:key:junk')
def test_decode_raise_exception_if_too_long1(self): with self.assertRaises(urn.URNValidationError): urn.decode('urn:dje:component:o:n:v:junk')
def test_decode_raise_exception_if_too_short_license(self): with self.assertRaises(urn.URNValidationError): urn.decode('urn:dje:license')
def test_decode_raise_exception_if_incorrect_prefix(self): with self.assertRaises(urn.URNValidationError): urn.decode('arn:dje:a:a')
def test_decode_org(self): u = 'urn:dje:owner:name' parsed = ('owner', {'name': 'name'}) self.assertEqual(parsed, urn.decode(u))
def test_decode_component(self): u = 'urn:dje:component:name:version' parsed = ('component', {'name': 'name', 'version': 'version'}) self.assertEqual(parsed, urn.decode(u))
def test_decode_license(self): u = 'urn:dje:license:lic' parsed = ('license', {'key': 'lic'}) assert parsed == urn.decode(u)
def test_decode_component(self): u = 'urn:dje:component:name:version' parsed = ('component', {'name': 'name', 'version': 'version'}) assert parsed == urn.decode(u)
def test_decode_org(self): u = 'urn:dje:owner:name' parsed = ('owner', {'name': 'name'}) assert parsed == urn.decode(u)
def test_decode_raise_exception_if_incorrect_prefix_or_ns(self): with self.assertRaises(urn.URNValidationError): urn.decode('x:x:x:x')
def test_decode_license(self): u = 'urn:dje:license:lic' parsed = ('license', {'key': 'lic'}) self.assertEqual(parsed, urn.decode(u))
def test_decode_raise_exception_if_too_short_component(self): with self.assertRaises(urn.URNValidationError): urn.decode('urn:dje:component')
def test_decode_raise_exception_if_too_long2(self): with self.assertRaises(urn.URNValidationError): urn.decode('urn:dje:owner:org:junk')
def test_decode_raise_exception_if_unknown_object_type(self): with self.assertRaises(urn.URNValidationError): urn.decode('urn:dje:marshmallows:dsds')
def test_encode_decode_is_idempotent(self): object_type = 'component' fields = {'name': 'SIP Servlets (MSS)', 'version': 'v 1.4.0.FINAL'} encoded = 'urn:dje:component:SIP+Servlets+%28MSS%29:v+1.4.0.FINAL' assert encoded == urn.encode(object_type, **fields) assert object_type, fields == urn.decode(encoded)