Skip to content

Commit

Permalink
Fix neo4j_proxy get_user_detail api method and bump up version (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
youngyjd authored and feng-tao committed May 29, 2019
1 parent 7184471 commit 2b33102
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
8 changes: 5 additions & 3 deletions metadata_service/proxy/neo4j_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages

__version__ = '1.0.7'
__version__ = '1.0.8'


setup(
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/proxy/test_neo4j_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()

0 comments on commit 2b33102

Please sign in to comment.