示例#1
0
def test_fail_bad_type():
    clis = _client_mocks()

    clis.dfu().get_objects.return_value = {
        'data': [{
            'info': [
                3, 'myobj', 'KBaseGenomes.GenomeComparison-2.1',
                'ignored time', 7, 'someuser', 34567, 'some_workspace',
                'md5 here', 416467216, {}
            ],
            'data': {
                'items': [{
                    'ref': '1/2/3'
                }, {
                    'ref': '4/5/6'
                }]
            }
        }]
    }

    with raises(Exception) as got:
        download_sequence('34567/3/7', Path('somepath/or/other'), clis)
    assert_exception_correct(
        got.value,
        ValueError('KBaseGenomes.GenomeComparison type is not supported'))
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 _sample_node_build_fail_metadata(meta, expected):
    with raises(Exception) as got:
        SampleNode('n', SubSampleType.BIOLOGICAL_REPLICATE, controlled_metadata=meta)
    assert_exception_correct(got.value, IllegalParameterError(expected.format('Controlled')))
    with raises(Exception) as got:
        SampleNode('n', SubSampleType.BIOLOGICAL_REPLICATE, user_metadata=meta)
    assert_exception_correct(got.value, IllegalParameterError(expected.format('User')))
示例#4
0
def test_check_string_control_characters():
    for string in ['foo \b  bar', 'foo\u200bbar', 'foo\0bar', 'foo\bbar']:
        with raises(Exception) as got:
            check_string(string, 'var name')
        assert_exception_correct(
            got.value,
            IllegalParameterError('var name contains control characters'))
示例#5
0
def test_falsy_fail():
    for f in ['', 0, False, [], dict(), {}]:
        with raises(Exception) as got:
            not_falsy(f, 'my name')
        assert_exception_correct(
            got.value,
            ValueError('my name cannot be a value that evaluates to false'))
示例#6
0
def test_check_string_long_fail():
    for string, length in {'123456789': 8, 'ab': 1, 'a' * 100: 99}.items():
        with raises(Exception) as got:
            check_string(string, 'var name', max_len=length)
        assert_exception_correct(
            got.value,
            IllegalParameterError(
                f'var name exceeds maximum length of {length}'))
def _prefix_key_metadata_fail_(vals, keys, expected):
    mv = MetadataValidatorSet(vals)
    with raises(Exception) as got:
        mv.prefix_key_metadata(keys)
    assert_exception_correct(got.value, expected)

    with raises(Exception) as got:
        mv.prefix_key_metadata(keys, exact_match=True)
    assert_exception_correct(got.value, expected)
def _sample_build_fail(nodes, name, expected):
    with raises(Exception) as got:
        Sample(nodes, name)
    assert_exception_correct(got.value, expected)

    id_ = uuid.UUID('1234567890abcdef1234567890abcdef')
    with raises(Exception) as got:
        SavedSample(id_, UserID('u'), nodes, dt(8), name)
    assert_exception_correct(got.value, expected)
def _get_user_workspaces_fail(user, expected):
    wsc = create_autospec(Workspace, spec_set=True, instance=True)

    ws = WS(wsc)

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

    with raises(Exception) as got:
        ws.get_user_workspaces(user)
    assert_exception_correct(got.value, expected)
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'))
示例#11
0
def test_config_get_validators_fail_bad_file(temp_dir):
    tf = _write_validator_config({}, temp_dir)
    os.remove(tf)
    with raises(Exception) as got:
        get_validators('file://' + tf)
    assert_exception_correct(
        got.value,
        ValueError(
            f"Failed to open validator configuration file at file://{tf}: " +
            f"[Errno 2] No such file or directory: '{tf}'"))
def _sample_node_build_fail_source_metadata(meta, expected, cmeta=None):
    if cmeta is None:
        cmeta = {sm.key: {'x': 'y'} for sm in meta if sm is not None}
    with raises(Exception) as got:
        SampleNode(
            'n',
            SubSampleType.BIOLOGICAL_REPLICATE,
            controlled_metadata=cmeta,
            source_metadata=meta)
    assert_exception_correct(got.value, expected)
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'))
示例#14
0
def test_falsy_in_iterable_false_insides():
    for item, pos in [[['', 'bar'], 0], [['foo', 0], 1],
                      [[True, True, False, True], 2], [[[]], 0], [[dict()], 0],
                      [[{}], 0]]:
        with raises(Exception) as got:
            not_falsy_in_iterable(item, 'my name')
        assert_exception_correct(
            got.value,
            ValueError(
                f'Index {pos} of iterable my name cannot be a value that evaluates to false'
            ))
def _has_permission_fail_ws_exception(ws_exception, expected):
    wsc = create_autospec(Workspace, spec_set=True, instance=True)

    ws = WS(wsc)

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

    wsc.administer.side_effect = ws_exception

    with raises(Exception) as got:
        ws.has_permission('foo', WorkspaceAccessType.READ, 22)
    assert_exception_correct(got.value, expected)
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 _get_user_workspaces_anonymous_fail_ws_exception(ws_exception, expected):
    wsc = create_autospec(Workspace, spec_set=True, instance=True)

    ws = WS(wsc)

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

    wsc.list_workspace_ids.side_effect = ws_exception

    wsc.administer.side_effect = ws_exception

    with raises(Exception) as got:
        ws.get_user_workspaces(None)
    assert_exception_correct(got.value, expected)
示例#19
0
def test_config_get_validators_fail_bad_yaml(temp_dir):
    # calling str() on ValidationErrors returns more detailed into about the error
    tf = tempfile.mkstemp('.tmp.cfg', 'config_test_bad_yaml', dir=temp_dir)
    os.close(tf[0])
    with open(tf[1], 'w') as temp:
        temp.write('[bad yaml')
    with raises(Exception) as got:
        get_validators('file://' + tf[1])
    assert_exception_correct(
        got.value,
        ValueError(
            f'Failed to open validator configuration file at file://{tf[1]}: while parsing a '
            +
            'flow sequence\n  in "<urllib response>", line 1, column 1\nexpected \',\' or \']\', '
            +
            'but got \'<stream end>\'\n  in "<urllib response>", line 1, column 10'
        ))
def test_prefix_key_metadata_fail_prefix_match():
    mv = MetadataValidatorSet([
        MetadataValidator('abcdef',
                          prefix_validators=[_noop],
                          metadata={'f': 'g'}),
        MetadataValidator('abcdefhi',
                          prefix_validators=[_noop],
                          metadata={'f': 'g'})
    ])

    with raises(Exception) as got:
        mv.prefix_key_metadata(None, exact_match=False)
    assert_exception_correct(got.value, ValueError('keys cannot be None'))

    with raises(Exception) as got:
        mv.prefix_key_metadata(['abcde'], exact_match=False)
    assert_exception_correct(
        got.value,
        IllegalParameterError('No prefix metadata keys matching key abcde'))
示例#21
0
def _ontology_has_ancestor_build_fail(cfg, expected):
    with raises(Exception) as got:
        builtin.ontology_has_ancestor(cfg)
    assert_exception_correct(got.value, expected)
示例#22
0
def _number_build_fail(cfg, expected):
    with raises(Exception) as got:
        builtin.number(cfg)
    assert_exception_correct(got.value, expected)
示例#23
0
def _units_build_fail(cfg, expected):
    with raises(Exception) as got:
        builtin.units(cfg)
    assert_exception_correct(got.value, expected)
示例#24
0
def _noop_fail_build(cfg, expected):
    with raises(Exception) as got:
        builtin.noop(cfg)
    assert_exception_correct(got.value, expected)
示例#25
0
def _string_fail_construct(d, expected):
    with raises(Exception) as got:
        builtin.string(d)
    assert_exception_correct(got.value, expected)
def _init_fail(lid, duid, sna, cr, cru, ex, eu, expected):
    with raises(Exception) as got:
        DataLink(lid, duid, sna, cr, cru, ex, eu)
    assert_exception_correct(got.value, expected)
示例#27
0
def _split_value_fail(d, k, expected):
    with raises(Exception) as got:
        split_value(d, k)
    assert_exception_correct(got.value, expected)
示例#28
0
def _config_get_validators_fail(cfg, temp_dir, expected):
    tf = _write_validator_config(cfg, temp_dir)
    with raises(Exception) as got:
        get_validators('file://' + tf)
    assert_exception_correct(got.value, expected)
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 test_error_root_no_error_type():
    with raises(Exception) as got:
        SampleError(None)
    assert_exception_correct(
        got.value, TypeError('error_type cannot be None'))