From 2b33102d3f9511537656f60f987e3e79caef0c72 Mon Sep 17 00:00:00 2001 From: Junda Yang Date: Wed, 29 May 2019 14:48:08 -0700 Subject: [PATCH] Fix neo4j_proxy get_user_detail api method and bump up version (#48) --- metadata_service/proxy/neo4j_proxy.py | 8 +++++--- setup.py | 2 +- tests/unit/proxy/test_neo4j_proxy.py | 7 +++++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/metadata_service/proxy/neo4j_proxy.py b/metadata_service/proxy/neo4j_proxy.py index d282c60f..ee85039f 100644 --- a/metadata_service/proxy/neo4j_proxy.py +++ b/metadata_service/proxy/neo4j_proxy.py @@ -699,16 +699,18 @@ def get_user_detail(self, *, user_id: str) -> Union[UserEntity, None]: query = textwrap.dedent(""" MATCH (user:User {key: $user_id}) - OPTIONAL MATCH (user)-[:manage_by]->(manager:User) + OPTIONAL MATCH (user)-[:MANAGE_BY]->(manager:User) RETURN user as user_record, manager as manager_record """) record = self._execute_cypher_query(statement=query, param_dict={'user_id': user_id}) - if not record: + single_result = record.single() + + if not single_result: raise NotFoundException('User {user_id} ' 'not found in the graph'.format(user_id=user_id)) - single_result = record.single() + record = single_result.get('user_record', {}) manager_record = single_result.get('manager_record', {}) if manager_record: diff --git a/setup.py b/setup.py index 2e994baa..9ffff800 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup, find_packages -__version__ = '1.0.7' +__version__ = '1.0.8' setup( diff --git a/tests/unit/proxy/test_neo4j_proxy.py b/tests/unit/proxy/test_neo4j_proxy.py index c241b7b8..425e58e4 100644 --- a/tests/unit/proxy/test_neo4j_proxy.py +++ b/tests/unit/proxy/test_neo4j_proxy.py @@ -11,6 +11,7 @@ from metadata_service.entity.table_detail import (Application, Column, Table, Tag, Watermark, Source, Statistics, User) from metadata_service.entity.tag_detail import TagDetail +from metadata_service.exception import NotFoundException from metadata_service.proxy.neo4j_proxy import Neo4jProxy from metadata_service.util import UserResourceRel @@ -580,6 +581,12 @@ def test_delete_resource_relation_by_user(self) -> None: self.assertEquals(mock_run.call_count, 1) self.assertEquals(mock_commit.call_count, 1) + def test_get_invalid_user(self) -> None: + with patch.object(GraphDatabase, 'driver'), patch.object(Neo4jProxy, '_execute_cypher_query') as mock_execute: + mock_execute.return_value.single.return_value = None + neo4j_proxy = Neo4jProxy(host='DOES_NOT_MATTER', port=0000) + self.assertRaises(NotFoundException, neo4j_proxy.get_user_detail, user_id='invalid_email') + if __name__ == '__main__': unittest.main()