Commit 7871c0d2 authored by Wim Van de Meerssche's avatar Wim Van de Meerssche
Browse files

added URN.authority_parts and added missing __init__.py

parent f4957d35
......@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
setup(
name="wvdemeer-utils",
version="1.0.1",
version="1.1.0",
description="A collection of useful functions",
long_description=long_description,
......
import pytest
from wvdemeer_utils.urn_util import URN
TEST_URN_1 = 'urn:publicid:IDN+example.com+ttype1+tname1'
TEST_URN_2 = 'urn:publicid:IDN+example.com:sub1:sub2+ttype2+tname2'
def test_get_authority_parts1():
actual = URN(urn=TEST_URN_1).authority_parts
expected = ['example.com']
assert actual == expected, 'actual({}) != expected({})'.format(actual, expected)
def test_get_authority_parts2():
actual = URN(urn=TEST_URN_2).authority_parts
expected = ['example.com', 'sub1', 'sub2']
assert actual == expected, 'actual({}) != expected({})'.format(actual, expected)
def test_authority1():
actual = URN(urn=TEST_URN_1).authority
expected = 'example.com'
assert actual == expected, 'actual({}) != expected({})'.format(actual, expected)
def test_authority2():
actual = URN(urn=TEST_URN_2).authority
expected = 'example.com//sub1//sub2'
assert actual == expected, 'actual({}) != expected({})'.format(actual, expected)
def test_type1():
actual = URN(urn=TEST_URN_1).type
expected = 'ttype1'
assert actual == expected, 'actual({}) != expected({})'.format(actual, expected)
def test_type2():
actual = URN(urn=TEST_URN_2).type
expected = 'ttype2'
assert actual == expected, 'actual({}) != expected({})'.format(actual, expected)
def test_name1():
actual = URN(urn=TEST_URN_1).name
expected = 'tname1'
assert actual == expected, 'actual({}) != expected({})'.format(actual, expected)
def test_name2():
actual = URN(urn=TEST_URN_2).name
expected = 'tname2'
assert actual == expected, 'actual({}) != expected({})'.format(actual, expected)
def test_urn1a():
actual = URN(urn=TEST_URN_1).urn
expected = TEST_URN_1
assert actual == expected, 'actual({}) != expected({})'.format(actual, expected)
def test_urn2a():
actual = URN(urn=TEST_URN_2).urn
expected = TEST_URN_2
assert actual == expected, 'actual({}) != expected({})'.format(actual, expected)
def test_urn1b():
actual = URN(authority='example.com', type='ttype1', name='tname1').urn
expected = TEST_URN_1
assert actual == expected, 'actual({}) != expected({})'.format(actual, expected)
def test_urn2b():
actual = URN(authority='example.com//sub1//sub2', type='ttype2', name='tname2').urn
expected = TEST_URN_2
assert actual == expected, 'actual({}) != expected({})'.format(actual, expected)
from sentry_utils import find_sentry_release_id
from urn_util import URN, always_urn, always_optional_urn, check_valid_urn_bytype
from utils import normalize_depenv, datetime_now, any_to_opt_bool, any_to_bool, duration_string_to_seconds, \
deep_update_dict, strip_null_from_json_dict
from validation_utils import is_valid_email, is_valid_ssh_key, is_valid_uuid4, is_valid_uuid, ALLOWED_HOST_KEY_ALGOS
__all__ = [
find_sentry_release_id,
URN, always_urn, always_optional_urn, check_valid_urn_bytype,
normalize_depenv, datetime_now, any_to_opt_bool, any_to_bool, duration_string_to_seconds,
deep_update_dict, strip_null_from_json_dict,
is_valid_email, is_valid_ssh_key, is_valid_uuid4, is_valid_uuid, ALLOWED_HOST_KEY_ALGOS
]
......@@ -54,7 +54,7 @@ class URN(object):
Looks like urn:publicid:IDN+gcf:gpo:bbn:site1+node+LinuxBox23
"""
def __init__(self, authority=None, type=None, name=None, urn=None):
def __init__(self, *, authority=None, type=None, name=None, urn=None):
if not urn is None:
if not is_valid_urn(urn):
raise ValueError("Invalid URN %s" % urn)
......@@ -109,6 +109,10 @@ class URN(object):
'''Get the name in un-escaped publicid format'''
return self.name
@property
def authority_parts(self):
return self.authority.split('//')
# Translate publicids to URN format.
# The order of these rules matters
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment