def test_namespace_id_slots(): assert NamespaceID('foo').__slots__ == ['id'] with raises(Exception) as got: NamespaceID('foo').attrib = 'whoops' assert_exception_correct( got.value, AttributeError("'NamespaceID' object has no attribute 'attrib'"))
def test_unparseable_duplicate_key_exception(idstorage): # this is a very naughty test reaching into the implementation with raises(Exception) as got: idstorage._get_duplicate_location( DuplicateKeyError('unmatchable dup key foo')) assert_exception_correct( got.value, IDMappingStorageError( 'unable to parse duplicate key error: unmatchable '))
def test_kb_config_get_env(): # to avoid dealing with files in the tests, we reach into the implementation here a little bit p = mock_path_to_file('path/place', ['[idmapping]', 'mongo-host=foo', 'mongo-db=bar']) c = KBaseConfig(p) os.environ['ID_MAPPING_CONFIG'] = 'some/path' os.environ['KB_DEPLOYMENT_CONFIG'] = 'some/other/path' assert c._get_cfg_from_env() == Path('some/path') del os.environ['ID_MAPPING_CONFIG'] assert c._get_cfg_from_env() == Path('some/other/path') del os.environ['KB_DEPLOYMENT_CONFIG'] with raises(Exception) as got: c._get_cfg_from_env() assert_exception_correct(got.value, IDMappingConfigError( 'Could not find deployment configuration file from either permitted environment ' + 'variable: ID_MAPPING_CONFIG, KB_DEPLOYMENT_CONFIG'))
def fail_remove_namespace_user(idstorage, namespace_id, user, expected): with raises(Exception) as got: idstorage.remove_user_from_namespace(namespace_id, user) assert_exception_correct(got.value, expected)
def fail_set_namespace_publicly_mappable(idstorage, namespace_id, expected): with raises(Exception) as got: idstorage.set_namespace_publicly_mappable(namespace_id, True) assert_exception_correct(got.value, expected)
def test_local_init_fail(): with raises(Exception) as got: LocalUserLookup(None) assert_exception_correct(got.value, TypeError('storage cannot be None'))
def fail_set_namespace_publicly_mappable(idmapper, auth_id, token, namespace_id, expected): with raises(Exception) as got: idmapper.set_namespace_publicly_mappable(auth_id, token, namespace_id, False) assert_exception_correct(got.value, expected)
def fail_init(handlers, admin_authsources, storage, expected): with raises(Exception) as got: IDMapper(handlers, admin_authsources, storage) assert_exception_correct(got.value, expected)
def fail_set_get_user(hset, authsource_id, token, expected): with raises(Exception) as got: hset.get_user(authsource_id, token) assert_exception_correct(got.value, expected)
def fail_set_local_user_as_admin(idstorage, user, expected): with raises(Exception) as got: idstorage.set_local_user_as_admin(user, True) assert_exception_correct(got.value, expected)
def fail_find_mappings(idstorage, oid, ns_filter, expected): with raises(Exception) as got: idstorage.find_mappings(oid, ns_filter) assert_exception_correct(got.value, expected)
def fail_update_user_token(idstorage, user, token, expected): with raises(Exception) as got: idstorage.update_local_user_token(user, token) assert_exception_correct(got.value, expected)
def fail_get_user(idstorage, token, expected): with raises(Exception) as got: idstorage.get_user(token) assert_exception_correct(got.value, expected)
def fail_startup(mongo, expected_msg): with raises(Exception) as got: IDMappingMongoStorage(mongo.client[TEST_DB_NAME]) assert_exception_correct(got.value, StorageInitException(expected_msg))
def fail_get_mappings(idm, oid, filters, expected): with raises(Exception) as got: idm.get_mappings(oid, filters) assert_exception_correct(got.value, expected)
def fail_remove_mapping(idm, authsource_id, token, oid1, oid2, expected): with raises(Exception) as got: idm.remove_mapping(authsource_id, token, oid1, oid2) assert_exception_correct(got.value, expected)
def fail_get_namespaces(idstorage, nids, expected): with raises(Exception) as got: idstorage.get_namespaces(nids) assert_exception_correct(got.value, expected)
def fail_get_user(kbuh, token, expected): with raises(Exception) as got: kbuh.get_user(token) assert_exception_correct(got.value, expected)
def fail_remove_mapping(idstorage, pOID, sOID, expected): with raises(Exception) as got: idstorage.remove_mapping(pOID, sOID) assert_exception_correct(got.value, expected)
def fail_init_with_builder(cfg, expected): with raises(Exception) as got: build_lookup(cfg) assert_exception_correct(got.value, expected)
def fail_init(url, token, kbase_admin_str, expected): with raises(Exception) as got: KBaseUserLookup(url, token, kbase_admin_str) assert_exception_correct(got.value, expected)
def fail_get_namespace(idm, namespace_id, authsource_id, token, expected): with raises(Exception) as got: idm.get_namespace(namespace_id, authsource_id, token) assert_exception_correct(got.value, expected)
def fail_is_valid_user(kbuh, username, expected): with raises(Exception) as got: kbuh.is_valid_user(username) assert_exception_correct(got.value, expected)
def test_fail_startup(): with raises(Exception) as got: IDMappingMongoStorage(None) assert_exception_correct(got.value, TypeError('db cannot be None'))
def fail_set_init(handlers, expected): with raises(Exception) as got: UserLookupSet(handlers) assert_exception_correct(got.value, expected)
def test_user_exists_fail(idstorage): with raises(Exception) as got: idstorage.user_exists(None) assert_exception_correct(got.value, TypeError('username cannot be None'))
def fail_set_is_valid_user(hset, user, expected): with raises(Exception) as got: hset.is_valid_user(user) assert_exception_correct(got.value, expected)
def fail_create_namespace(idstorage, namespace_id, expected): with raises(Exception) as got: idstorage.create_namespace(namespace_id) assert_exception_correct(got.value, expected)
def test_local_set_user_as_admin_fail(): storage = create_autospec(IDMappingStorage, spec_set=True, instance=True) with raises(Exception) as got: LocalUserLookup(storage).set_user_as_admin(None, True) assert_exception_correct(got.value, TypeError('username cannot be None'))
def fail_add_namespace_user(idstorage, namespace_id, user, expected): with raises(Exception) as got: idstorage.add_user_to_namespace(namespace_id, user) assert_exception_correct(got.value, expected)