Skip to content

Commit

Permalink
Merge pull request #16 from lyft/tfeng_update_user
Browse files Browse the repository at this point in the history
Update user model
  • Loading branch information
Tao Feng authored Mar 11, 2019
2 parents 3b89a78 + 545e43c commit 4af09d8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 38 deletions.
43 changes: 18 additions & 25 deletions databuilder/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,18 @@ def __init__(self,
then we will have a cron job to update the ex-employee nodes based on
the case if this timestamp hasn't been updated for two weeks.
"""
self.first_name = first_name
self.last_name = last_name
self.name = name
self.email = email
self.github_username = github_username
self.first_name = first_name.encode('utf-8')
self.last_name = last_name.encode('utf-8')
self.name = name.encode('utf-8')

self.email = email.encode('utf-8')
self.github_username = github_username.encode('utf-8')
# todo: team will be a separate node once Amundsen People supports team
self.team_name = team_name
self.manager_email = manager_email
self.employee_type = employee_type
self.team_name = team_name.encode('utf-8')
self.manager_email = manager_email.encode('utf-8')
self.employee_type = employee_type.encode('utf-8')
# this attr not available in team service, either update team service, update with FE
self.slack_id = slack_id
self.slack_id = slack_id.encode('utf-8')
self.is_active = is_active
self.updated_at = updated_at

Expand Down Expand Up @@ -113,22 +114,14 @@ def create_nodes(self):
User.USER_NODE_IS_ACTIVE: self.is_active,
}

if self.first_name:
result_node[User.USER_NODE_FIRST_NAME] = self.first_name
if self.last_name:
result_node[User.USER_NODE_LAST_NAME] = self.last_name
if self.name:
result_node[User.USER_NODE_FULL_NAME] = self.name
if self.github_username:
result_node[User.USER_NODE_GITHUB_NAME] = self.github_username
if self.team_name:
result_node[User.USER_NODE_TEAM] = self.team_name
if self.employee_type:
result_node[User.USER_NODE_EMPLOYEE_TYPE] = self.employee_type
if self.slack_id:
result_node[User.USER_NODE_SLACK_ID] = self.slack_id
if self.updated_at:
result_node[User.USER_NODE_UPDATED_AT] = self.updated_at
result_node[User.USER_NODE_FIRST_NAME] = self.first_name if self.first_name else ''
result_node[User.USER_NODE_LAST_NAME] = self.last_name if self.last_name else ''
result_node[User.USER_NODE_FULL_NAME] = self.name if self.name else ''
result_node[User.USER_NODE_GITHUB_NAME] = self.github_username if self.github_username else ''
result_node[User.USER_NODE_TEAM] = self.team_name if self.team_name else ''
result_node[User.USER_NODE_EMPLOYEE_TYPE] = self.employee_type if self.employee_type else ''
result_node[User.USER_NODE_SLACK_ID] = self.slack_id if self.slack_id else ''
result_node[User.USER_NODE_UPDATED_AT] = self.updated_at if self.updated_at else 0

return [result_node]

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages


__version__ = '1.0.6'
__version__ = '1.0.7'


setup(
Expand Down
24 changes: 12 additions & 12 deletions tests/unit/models/test_table_column_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ def test_serialize(self):
# type: () -> None

col_readers = [ColumnReader(database='db', cluster='gold', schema='scm', table='foo', column='*',
user_email='[email protected]'),
ColumnReader(database='db', cluster='gold', schema='scm', table='bar', column='*',
user_email='[email protected]')]
user_email='[email protected]')]
table_col_usage = TableColumnUsage(col_readers=col_readers)

node_row = table_col_usage.next_node()
Expand All @@ -22,14 +20,18 @@ def test_serialize(self):
actual.append(node_row)
node_row = table_col_usage.next_node()

expected = [{'is_active': True,
expected = [{'first_name': '',
'last_name': '',
'full_name': '',
'employee_type': '',
'is_active': True,
'updated_at': 0,
'LABEL': 'User',
'slack_id': '',
'KEY': '[email protected]',
'email': '[email protected]'},
{'is_active': True,
'LABEL': 'User',
'KEY': '[email protected]',
'email': '[email protected]'}]
'github_username': '',
'team_name': '',
'email': '[email protected]'}]
self.assertEqual(expected, actual)

rel_row = table_col_usage.next_relation()
Expand All @@ -39,9 +41,7 @@ def test_serialize(self):
rel_row = table_col_usage.next_relation()

expected = [{'read_count:UNQUOTED': 1, 'END_KEY': '[email protected]', 'START_LABEL': 'Table',
'END_LABEL': 'User', 'START_KEY': 'db://gold.scm/foo', 'TYPE': 'READ_BY', 'REVERSE_TYPE': 'READ'},
{'read_count:UNQUOTED': 1, 'END_KEY': '[email protected]', 'START_LABEL': 'Table',
'END_LABEL': 'User', 'START_KEY': 'db://gold.scm/bar', 'TYPE': 'READ_BY', 'REVERSE_TYPE': 'READ'}]
'END_LABEL': 'User', 'START_KEY': 'db://gold.scm/foo', 'TYPE': 'READ_BY', 'REVERSE_TYPE': 'READ'}]
self.assertEqual(expected, actual)


Expand Down

0 comments on commit 4af09d8

Please sign in to comment.