Exemplo n.º 1
0
def test_has_permission():
    _has_permission(UserID('a'), None, UPA('42/65/3'), WorkspaceAccessType.READ, 42)
    _has_permission(UserID('b'), 24, UPA('67/2/92'), WorkspaceAccessType.READ, 24)
    _has_permission(UserID('c'), 1, None, WorkspaceAccessType.READ, 1)
    _has_permission(UserID('a'), None, UPA('7/45/789'), WorkspaceAccessType.WRITE, 7)
    _has_permission(UserID('c'), None, UPA('1/1/1'), WorkspaceAccessType.WRITE, 1)
    _has_permission(UserID('c'), 301, None, WorkspaceAccessType.ADMIN, 301)
    _has_permission(UserID('none'), 301, None, WorkspaceAccessType.NONE, 301)
def test_duid_hash():
    # string hashes will change from instance to instance of the python interpreter, and therefore
    # tests can't be written that directly test the hash value. See
    # https://docs.python.org/3/reference/datamodel.html#object.__hash__
    assert hash(DataUnitID(UPA('1/1/1'))) == hash(DataUnitID(UPA('1/1/1')))
    assert hash(DataUnitID(UPA('1/1/1'), 'foo')) == hash(DataUnitID(UPA('1/1/1'), 'foo'))

    assert hash(DataUnitID(UPA('1/1/1'))) != hash(DataUnitID(UPA('2/1/1')))
    assert hash(DataUnitID(UPA('1/1/1'), 'foo')) != hash(DataUnitID(UPA('2/1/1'), 'foo'))
    assert hash(DataUnitID(UPA('1/1/1'), 'foo')) != hash(DataUnitID(UPA('1/1/1'), 'fooo'))
def test_hash():
    # hashes will change from instance to instance of the python interpreter, and therefore
    # tests can't be written that directly test the hash value. See
    # https://docs.python.org/3/reference/datamodel.html#object.__hash__
    lid1 = uuid.UUID('1234567890abcdef1234567890abcdee')
    lid1a = uuid.UUID('1234567890abcdef1234567890abcdee')
    lid2 = uuid.UUID('1234567890abcdef1234567890abcdec')
    lid2a = uuid.UUID('1234567890abcdef1234567890abcdec')
    d1 = DataUnitID(UPA('1/1/1'))
    d1a = DataUnitID(UPA('1/1/1'))
    d2 = DataUnitID(UPA('1/1/2'))
    d2a = DataUnitID(UPA('1/1/2'))
    id_ = uuid.UUID('1234567890abcdef1234567890abcdef')
    s1 = SampleNodeAddress(SampleAddress(id_, 1), 'foo')
    s1a = SampleNodeAddress(SampleAddress(id_, 1), 'foo')
    s2 = SampleNodeAddress(SampleAddress(id_, 2), 'foo')
    s2a = SampleNodeAddress(SampleAddress(id_, 2), 'foo')
    t1 = dt(500)
    t1a = dt(500)
    t2 = dt(600)
    t2a = dt(600)
    u1 = UserID('u')
    u1a = UserID('u')
    u2 = UserID('y')
    u2a = UserID('y')

    assert hash(DataLink(lid1, d1, s1, t1,
                         u1)) == hash(DataLink(lid1a, d1a, s1a, t1a, u1a))
    assert hash(DataLink(lid1, d1, s1, t1, u1, None)) == hash(
        DataLink(lid1a, d1a, s1a, t1a, u1a, None))
    assert hash(DataLink(lid2, d2, s2, t1, u2, t2, u1)) == hash(
        DataLink(lid2a, d2a, s2a, t1a, u2a, t2a, u1a))

    assert hash(DataLink(lid1, d1, s1, t1, u1)) != hash(
        DataLink(lid2, d1a, s1a, t1a, u1a))
    assert hash(DataLink(lid1, d1, s1, t1, u1)) != hash(
        DataLink(lid1a, d2, s1a, t1a, u1a))
    assert hash(DataLink(lid1, d1, s1, t1, u1)) != hash(
        DataLink(lid1a, d1a, s2, t1a, u1a))
    assert hash(DataLink(lid1, d1, s1, t1, u1)) != hash(
        DataLink(lid1a, d1a, s1a, t2, u1a))
    assert hash(DataLink(lid1, d1, s1, t1, u1)) != hash(
        DataLink(lid1a, d1a, s1a, t1a, u2))
    assert hash(DataLink(lid1, d1, s1, t1, u1, t2, u2)) != hash(
        DataLink(lid1a, d1a, s1a, t1a, u1a, t1, u2a))
    assert hash(DataLink(lid1, d1, s1, t1, u1, t2, u2)) != hash(
        DataLink(lid1a, d1a, s1a, t1a, u1a, t2a, u1a))
    assert hash(DataLink(lid1, d1, s1, t1, u1, t1, u2)) != hash(
        DataLink(lid1a, d1a, s1a, t1a, u1a))
    assert hash(DataLink(lid1, d1, s1, t1, u1)) != hash(
        DataLink(lid1a, d1a, s1a, t1a, u1a, t1a, u2a))
def test_upa_init_all_args():
    u = UPA(upa='6/3/9', wsid=7, objid=4, version=10)

    assert u.wsid == 6
    assert u.objid == 3
    assert u.version == 9
    assert str(u) == '6/3/9'
Exemplo n.º 5
0
def test_has_permission_fail_unauthorized():
    r = WorkspaceAccessType.READ
    w = WorkspaceAccessType.WRITE
    a = WorkspaceAccessType.ADMIN
    _has_permission_fail(UserID('d'), 1, None, r, UnauthorizedError(
        'User d cannot read workspace 1'))
    _has_permission_fail(UserID('d'), 34, None, w, UnauthorizedError(
        'User d cannot write to workspace 34'))
    _has_permission_fail(UserID('b'), None, UPA('6/7/8'), w, UnauthorizedError(
        'User b cannot write to upa 6/7/8'))
    _has_permission_fail(UserID('d'), 6, None, a, UnauthorizedError(
        'User d cannot administrate workspace 6'))
    _has_permission_fail(UserID('b'), 74, None, a, UnauthorizedError(
        'User b cannot administrate workspace 74'))
    _has_permission_fail(UserID('a'), None, UPA('890/44/1'), a, UnauthorizedError(
        'User a cannot administrate upa 890/44/1'))
def _upa_init_str(str_, wsid, objid, ver, outstr):
    u = UPA(str_)

    assert u.wsid == wsid
    assert u.objid == objid
    assert u.version == ver
    assert str(u) == outstr
def _upa_init_int(wsid, objid, ver, wside, objide, vere, outstr):
    u = UPA(wsid=wsid, objid=objid, version=ver)

    assert u.wsid == wside
    assert u.objid == objide
    assert u.version == vere
    assert str(u) == outstr
def test_upa_init_fail():
    with raises(Exception) as got:
        UPA()
    assert_exception_correct(got.value, IllegalParameterError('Illegal workspace ID: None'))

    _upa_init_str_fail('1', IllegalParameterError('1 is not a valid UPA'))
    _upa_init_str_fail('1/2', IllegalParameterError('1/2 is not a valid UPA'))
    _upa_init_str_fail('1/2/3/5', IllegalParameterError('1/2/3/5 is not a valid UPA'))
    _upa_init_str_fail('1/2/3/', IllegalParameterError('1/2/3/ is not a valid UPA'))
    _upa_init_str_fail('/1/2/3', IllegalParameterError('/1/2/3 is not a valid UPA'))
    _upa_init_str_fail('f/2/3', IllegalParameterError('f/2/3 is not a valid UPA'))
    _upa_init_str_fail('1/f/3', IllegalParameterError('1/f/3 is not a valid UPA'))
    _upa_init_str_fail('1/2/f', IllegalParameterError('1/2/f is not a valid UPA'))
    _upa_init_str_fail('0/2/3', IllegalParameterError('0/2/3 is not a valid UPA'))
    _upa_init_str_fail('1/0/3', IllegalParameterError('1/0/3 is not a valid UPA'))
    _upa_init_str_fail('1/2/0', IllegalParameterError('1/2/0 is not a valid UPA'))
    _upa_init_str_fail('-24/2/3', IllegalParameterError('-24/2/3 is not a valid UPA'))
    _upa_init_str_fail('1/-42/3', IllegalParameterError('1/-42/3 is not a valid UPA'))
    _upa_init_str_fail('1/2/-10677810', IllegalParameterError('1/2/-10677810 is not a valid UPA'))

    _upa_init_int_fail(None, 2, 3, IllegalParameterError('Illegal workspace ID: None'))
    _upa_init_int_fail(1, None, 3, IllegalParameterError('Illegal object ID: None'))
    _upa_init_int_fail(1, 2, None, IllegalParameterError('Illegal object version: None'))
    _upa_init_int_fail(0, 2, 3, IllegalParameterError('Illegal workspace ID: 0'))
    _upa_init_int_fail(1, 0, 3, IllegalParameterError('Illegal object ID: 0'))
    _upa_init_int_fail(1, 2, 0, IllegalParameterError('Illegal object version: 0'))
    _upa_init_int_fail(-98, 2, 3, IllegalParameterError('Illegal workspace ID: -98'))
    _upa_init_int_fail(1, -6, 3, IllegalParameterError('Illegal object ID: -6'))
    _upa_init_int_fail(1, 2, -87501, IllegalParameterError('Illegal object version: -87501'))
def test_init_fail():
    lid = uuid.UUID('1234567890abcdef1234567890abcdee')
    d = DataUnitID(UPA('1/1/1'))
    sid = uuid.UUID('1234567890abcdef1234567890abcdef')
    s = SampleNodeAddress(SampleAddress(sid, 1), 'a')
    t = dt(1)
    u = UserID('u')
    bt = datetime.datetime.now()
    n = None

    _init_fail(None, d, s, t, u, n, n,
               ValueError('id_ cannot be a value that evaluates to false'))
    _init_fail(lid, None, s, t, u, n, n,
               ValueError('duid cannot be a value that evaluates to false'))
    _init_fail(
        lid, d, None, t, u, n, n,
        ValueError(
            'sample_node_address cannot be a value that evaluates to false'))
    _init_fail(lid, d, s, None, u, n, n,
               ValueError('created cannot be a value that evaluates to false'))
    _init_fail(lid, d, s, bt, u, n, n,
               ValueError('created cannot be a naive datetime'))
    _init_fail(
        lid, d, s, t, None, n, n,
        ValueError('created_by cannot be a value that evaluates to false'))
    _init_fail(lid, d, s, t, u, bt, u,
               ValueError('expired cannot be a naive datetime'))
    _init_fail(
        lid, d, s, t, u, t, None,
        ValueError('expired_by cannot be a value that evaluates to false'))
    _init_fail(lid, d, s, dt(100), u, dt(99), u,
               ValueError('link cannot expire before it is created'))
def test_equals():
    lid1 = uuid.UUID('1234567890abcdef1234567890abcdee')
    lid1a = uuid.UUID('1234567890abcdef1234567890abcdee')
    lid2 = uuid.UUID('1234567890abcdef1234567890abcdec')
    lid2a = uuid.UUID('1234567890abcdef1234567890abcdec')
    d1 = DataUnitID(UPA('1/1/1'))
    d1a = DataUnitID(UPA('1/1/1'))
    d2 = DataUnitID(UPA('1/1/2'))
    d2a = DataUnitID(UPA('1/1/2'))
    sid = uuid.UUID('1234567890abcdef1234567890abcdef')
    s1 = SampleNodeAddress(SampleAddress(sid, 1), 'foo')
    s1a = SampleNodeAddress(SampleAddress(sid, 1), 'foo')
    s2 = SampleNodeAddress(SampleAddress(sid, 2), 'foo')
    s2a = SampleNodeAddress(SampleAddress(sid, 2), 'foo')
    t1 = dt(500)
    t1a = dt(500)
    t2 = dt(600)
    t2a = dt(600)
    u1 = UserID('u')
    u1a = UserID('u')
    u2 = UserID('y')
    u2a = UserID('y')

    assert DataLink(lid1, d1, s1, t1, u1) == DataLink(lid1a, d1a, s1a, t1a,
                                                      u1a)
    assert DataLink(lid1, d1, s1, t1, u1,
                    None) == DataLink(lid1a, d1a, s1a, t1a, u1a, None)
    assert DataLink(lid2, d2, s2, t1, u2, t2,
                    u1) == DataLink(lid2a, d2a, s2a, t1a, u2a, t2a, u1a)

    assert DataLink(lid1, d1, s1, t1, u1) != (lid1, d1, s1, t1, u1)
    assert DataLink(lid1, d1, s1, t1, u1, t2,
                    u2) != (lid1, d1, s1, t1, u1, t2, u2)

    assert DataLink(lid1, d1, s1, t1, u1) != DataLink(lid2, d1a, s1a, t1a, u1a)
    assert DataLink(lid1, d1, s1, t1, u1) != DataLink(lid1a, d2, s1a, t1a, u1a)
    assert DataLink(lid1, d1, s1, t1, u1) != DataLink(lid1a, d1a, s2, t1a, u1a)
    assert DataLink(lid1, d1, s1, t1, u1) != DataLink(lid1a, d1a, s1a, t2, u1a)
    assert DataLink(lid1, d1, s1, t1, u1) != DataLink(lid1a, d1a, s1a, t1, u2)
    assert DataLink(lid1, d1, s1, t1, u1, t2, u2) != DataLink(
        lid1a, d1a, s1a, t1a, u1a, t1, u2a)
    assert DataLink(lid1, d1, s1, t1, u1, t2, u2) != DataLink(
        lid1a, d1a, s1a, t1a, u1a, t2a, u1)
    assert DataLink(lid1, d1, s1, t1, u1, t1, u1) != DataLink(
        lid1a, d1a, s1a, t1a, u1a)
    assert DataLink(lid1, d1, s1, t1, u1) != DataLink(lid1a, d1a, s1a, t1a,
                                                      u1a, t1a, u1a)
def test_links_to_dicts():
    links = [
        DataLink(
            UUID('f5bd78c3-823e-40b2-9f93-20e78680e41e'),
            DataUnitID(UPA('1/2/3'), 'foo'),
            SampleNodeAddress(
                SampleAddress(UUID('f5bd78c3-823e-40b2-9f93-20e78680e41f'), 6), 'foo'),
            dt(0.067),
            UserID('usera'),
            dt(89),
            UserID('userb')
        ),
        DataLink(
            UUID('f5bd78c3-823e-40b2-9f93-20e78680e41a'),
            DataUnitID(UPA('4/9/10')),
            SampleNodeAddress(
                SampleAddress(UUID('f5bd78c3-823e-40b2-9f93-20e78680e41b'), 4), 'bar'),
            dt(1),
            UserID('userc'),
        ),
    ]
    assert links_to_dicts(links) == [
        {
            'upa': '1/2/3',
            'dataid': 'foo',
            'id': 'f5bd78c3-823e-40b2-9f93-20e78680e41f',
            'version': 6,
            'node': 'foo',
            'created': 67,
            'createdby': 'usera',
            'expired': 89000,
            'expiredby': 'userb'
            },
        {
            'upa': '4/9/10',
            'dataid': None,
            'id': 'f5bd78c3-823e-40b2-9f93-20e78680e41b',
            'version': 4,
            'node': 'bar',
            'created': 1000,
            'createdby': 'userc',
            'expired': None,
            'expiredby': None
            }
    ]
def test_duid_init_fail():
    with raises(Exception) as got:
        DataUnitID(None)
    assert_exception_correct(got.value, ValueError(
        'upa cannot be a value that evaluates to false'))

    with raises(Exception) as got:
        DataUnitID(UPA('1/1/1'), 'a' * 257)
    assert_exception_correct(got.value, IllegalParameterError(
        'dataid exceeds maximum length of 256'))
Exemplo n.º 13
0
def get_upa_from_object(params: Dict[str, Any]) -> UPA:
    '''
    Get an UPA from a parameter object. Expects the UPA in the key 'upa'.

    :param params: the parameters.
    :returns: the UPA.
    :raises MissingParameterError: if the UPA is missing.
    :raises IllegalParameterError: if the UPA is illegal.
    '''
    _check_params(params)
    return UPA(_cast(str, _check_string_int(params, 'upa', True)))
def test_is_equivalent_fail():
    sid = uuid.UUID('1234567890abcdef1234567890abcdef')
    dl1 = DataLink(uuid.UUID('1234567890abcdef1234567890abcdee'),
                   DataUnitID(UPA('2/6/4'), 'whee'),
                   SampleNodeAddress(SampleAddress(sid, 8), 'bar'), dt(400),
                   UserID('myuserᚥnameisHank'), dt(400), UserID('yay'))
    with raises(Exception) as got:
        dl1.is_equivalent(None)
    assert_exception_correct(
        got.value,
        ValueError('link cannot be a value that evaluates to false'))
def test_init_with_expire1():
    sid = uuid.UUID('1234567890abcdef1234567890abcdef')

    dl = DataLink(uuid.UUID('1234567890abcdef1234567890abcdee'),
                  DataUnitID(UPA('2/6/4'), 'whee'),
                  SampleNodeAddress(SampleAddress(sid, 7), 'bar'), dt(400),
                  UserID('u'), dt(800), UserID('gotdam'))

    assert dl.id == uuid.UUID('1234567890abcdef1234567890abcdee')
    assert dl.duid == DataUnitID(UPA('2/6/4'), 'whee')
    assert dl.sample_node_address == SampleNodeAddress(SampleAddress(sid, 7),
                                                       'bar')
    assert dl.created == dt(400)
    assert dl.created_by == UserID('u')
    assert dl.expired == dt(800)
    assert dl.expired_by == UserID('gotdam')
    assert str(dl) == (
        'id=12345678-90ab-cdef-1234-567890abcdee ' + 'duid=[2/6/4:whee] ' +
        'sample_node_address=[12345678-90ab-cdef-1234-567890abcdef:7:bar] ' +
        'created=400.0 created_by=u expired=800.0 expired_by=gotdam')
def test_has_permission_fail_on_get_info_server_error():
    wsc = create_autospec(Workspace, spec_set=True, instance=True)

    ws = WS(wsc)
    wsc.administer.assert_called_once_with({'command': 'listModRequests'})

    wsc.administer.side_effect = [
        {'perms': [{'a': 'w', 'b': 'r', 'c': 'a'}]},
        ServerError('JSONRPCError', -32500, 'Thanks Obama')]

    with raises(Exception) as got:
        ws.has_permission(UserID('b'), WorkspaceAccessType.READ, upa=UPA('67/8/90'))
    assert_exception_correct(got.value, ServerError('JSONRPCError', -32500, 'Thanks Obama'))
def test_has_permission_fail_no_object():
    wsc = create_autospec(Workspace, spec_set=True, instance=True)

    ws = WS(wsc)
    wsc.administer.assert_called_once_with({'command': 'listModRequests'})

    wsc.administer.side_effect = [
        {'perms': [{'a': 'w', 'b': 'r', 'c': 'a'}]},
        {'infos': [None]}]

    with raises(Exception) as got:
        ws.has_permission(UserID('b'), WorkspaceAccessType.READ, upa=UPA('67/8/90'))
    assert_exception_correct(got.value, NoSuchWorkspaceDataError('Object 67/8/90 does not exist'))
def _create_data_link_params_with_update(update, expected):
    params = {
        'id': '706fe9e1-70ef-4feb-bbd9-32295104a119',
        'version': 1,
        'node': 'm',
        'upa': '1/1/1',
        'update': update
    }

    assert create_data_link_params(params) == (
        DataUnitID(UPA('1/1/1')),
        SampleNodeAddress(
            SampleAddress(UUID('706fe9e1-70ef-4feb-bbd9-32295104a119'), 1), 'm'),
        expected
    )
def test_init_no_expire():
    sid = uuid.UUID('1234567890abcdef1234567890abcdef')

    dl = DataLink(
        uuid.UUID('1234567890abcdef1234567890abcdee'),
        DataUnitID(UPA('2/3/4')),
        SampleNodeAddress(SampleAddress(sid, 5), 'foo'),
        dt(500),
        UserID('usera'),
        expired_by=UserID('u')  # should be ignored
    )

    assert dl.id == uuid.UUID('1234567890abcdef1234567890abcdee')
    assert dl.duid == DataUnitID(UPA('2/3/4'))
    assert dl.sample_node_address == SampleNodeAddress(SampleAddress(sid, 5),
                                                       'foo')
    assert dl.created == dt(500)
    assert dl.created_by == UserID('usera')
    assert dl.expired is None
    assert dl.expired_by is None
    assert str(dl) == (
        'id=12345678-90ab-cdef-1234-567890abcdee ' + 'duid=[2/3/4] ' +
        'sample_node_address=[12345678-90ab-cdef-1234-567890abcdef:5:foo] ' +
        'created=500.0 created_by=usera expired=None expired_by=None')
def test_links_to_dicts_fail_bad_args():
    dl = DataLink(
            UUID('f5bd78c3-823e-40b2-9f93-20e78680e41e'),
            DataUnitID(UPA('1/2/3'), 'foo'),
            SampleNodeAddress(
                SampleAddress(UUID('f5bd78c3-823e-40b2-9f93-20e78680e41f'), 6), 'foo'),
            dt(0.067),
            UserID('usera'),
            dt(89),
            UserID('userb')
        )

    _links_to_dicts_fail(None, ValueError('links cannot be None'))
    _links_to_dicts_fail([dl, None], ValueError(
        'Index 1 of iterable links cannot be a value that evaluates to false'))
def test_create_data_link_params_missing_update_key():
    params = {
        'id': '706fe9e1-70ef-4feb-bbd9-32295104a119',
        'version': 78,
        'node': 'mynode',
        'upa': '6/7/29',
        'dataid': 'mydata'
    }

    assert create_data_link_params(params) == (
        DataUnitID(UPA('6/7/29'), 'mydata'),
        SampleNodeAddress(
            SampleAddress(UUID('706fe9e1-70ef-4feb-bbd9-32295104a119'), 78), 'mynode'),
        False
    )
def test_duid_init():
    duid = DataUnitID(UPA('1/2/3'))
    assert duid.upa == UPA('1/2/3')
    assert duid.dataid is None
    assert str(duid) == '1/2/3'

    duid = DataUnitID(UPA('1/2/3'), '')
    assert duid.upa == UPA('1/2/3')
    assert duid.dataid is None
    assert str(duid) == '1/2/3'

    duid = DataUnitID(UPA('1/2/3'), 'foo')
    assert duid.upa == UPA('1/2/3')
    assert duid.dataid == 'foo'
    assert str(duid) == '1/2/3:foo'

    duid = DataUnitID(UPA('1/2/3'), 'f' * 256)
    assert duid.upa == UPA('1/2/3')
    assert duid.dataid == 'f' * 256
    assert str(duid) == '1/2/3:' + 'f' * 256
def test_is_equivalent_link():
    sid = uuid.UUID('1234567890abcdef1234567890abcdef')

    _is_equivalent(DataUnitID(UPA('2/6/4'), 'whee'),
                   SampleNodeAddress(SampleAddress(sid, 7), 'bar'),
                   DataUnitID(UPA('2/6/4'), 'whee'),
                   SampleNodeAddress(SampleAddress(sid, 7), 'bar'), True)

    _is_equivalent(DataUnitID(UPA('2/6/4'), 'wheo'),
                   SampleNodeAddress(SampleAddress(sid, 7), 'bar'),
                   DataUnitID(UPA('2/6/4'), 'whee'),
                   SampleNodeAddress(SampleAddress(sid, 7), 'bar'), False)

    _is_equivalent(DataUnitID(UPA('2/6/4'), 'whee'),
                   SampleNodeAddress(SampleAddress(sid, 8), 'bar'),
                   DataUnitID(UPA('2/6/4'), 'whee'),
                   SampleNodeAddress(SampleAddress(sid, 7), 'bar'), False)
def test_get_data_unit_id_from_object():
    assert get_data_unit_id_from_object({'upa': '1/1/1'}) == DataUnitID(UPA('1/1/1'))
    assert get_data_unit_id_from_object({'upa': '8/3/2'}) == DataUnitID(UPA('8/3/2'))
    assert get_data_unit_id_from_object(
        {'upa': '8/3/2', 'dataid': 'a'}) == DataUnitID(UPA('8/3/2'), 'a')
def _upa_init_int_fail(wsid, objid, ver, expected):
    with raises(Exception) as got:
        UPA(wsid=wsid, objid=objid, version=ver)
    assert_exception_correct(got.value, expected)
def _upa_init_str_fail(upa, expected):
    with raises(Exception) as got:
        UPA(upa)
    assert_exception_correct(got.value, expected)
def test_get_upa_from_object():
    assert get_upa_from_object({'upa': '1/1/1'}) == UPA('1/1/1')
    assert get_upa_from_object({'upa': '8/3/2'}) == UPA('8/3/2')
def test_upa_hash():
    # string hashes will change from instance to instance of the python interpreter, and therefore
    # tests can't be written that directly test the hash value. See
    # https://docs.python.org/3/reference/datamodel.html#object.__hash__
    assert hash(UPA('1/2/3')) == hash(UPA(wsid=1, objid=2, version=3))
    assert hash(UPA('1/2/3')) == hash(UPA('1/2/3'))
    assert hash(UPA(wsid=56, objid=90, version=211)) == hash(UPA('56/90/211'))
    assert hash(UPA('56/90/211')) == hash(UPA('56/90/211'))

    assert hash(UPA('1/2/3')) != hash(UPA(wsid=2, objid=2, version=3))
    assert hash(UPA('1/3/3')) != hash(UPA('1/2/3'))
    assert hash(UPA(wsid=1, objid=2, version=3)) != hash(UPA(wsid=1, objid=2, version=4))
def test_upa_equals():
    assert UPA('1/2/3') == UPA(wsid=1, objid=2, version=3)
    assert UPA('1/2/3') == UPA('1/2/3')
    assert UPA(wsid=56, objid=90, version=211) == UPA('56/90/211')
    assert UPA('56/90/211') == UPA('56/90/211')

    assert UPA('1/2/3') != '1/2/3'

    assert UPA('1/2/3') != UPA(wsid=2, objid=2, version=3)
    assert UPA('1/3/3') != UPA('1/2/3')
    assert UPA(wsid=1, objid=2, version=3) != UPA(wsid=1, objid=2, version=4)
def test_duid_equals():
    assert DataUnitID(UPA('1/1/1')) == DataUnitID(UPA('1/1/1'))
    assert DataUnitID(UPA('1/1/1'), 'foo') == DataUnitID(UPA('1/1/1'), 'foo')

    assert DataUnitID(UPA('1/1/1')) != UPA('1/1/1')

    assert DataUnitID(UPA('1/1/1')) != DataUnitID(UPA('2/1/1'))
    assert DataUnitID(UPA('1/1/1'), 'foo') != DataUnitID(UPA('2/1/1'), 'foo')
    assert DataUnitID(UPA('1/1/1'), 'foo') != DataUnitID(UPA('1/1/1'), 'fooo')