Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AmendsenProject
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shaik Janipasha
AmendsenProject
Commits
7b6bf54f
Unverified
Commit
7b6bf54f
authored
Jun 24, 2019
by
Tao Feng
Committed by
GitHub
Jun 24, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extend user model to accept any KV attribute (#95)
parent
d302e673
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
1 deletion
+32
-1
user.py
databuilder/models/user.py
+12
-0
setup.py
setup.py
+1
-1
test_user.py
tests/unit/models/test_user.py
+19
-0
No files found.
databuilder/models/user.py
View file @
7b6bf54f
import
copy
from
typing
import
Union
,
Dict
,
Any
# noqa: F401
from
databuilder.models.neo4j_csv_serde
import
Neo4jCsvSerializable
,
NODE_KEY
,
\
...
...
@@ -40,6 +41,7 @@ class User(Neo4jCsvSerializable):
slack_id
=
''
,
# type: str
is_active
=
True
,
# type: bool
updated_at
=
0
,
# type: int
**
kwargs
# type: Dict
):
# type: (...) -> None
"""
...
...
@@ -57,6 +59,7 @@ class User(Neo4jCsvSerializable):
:param updated_at: everytime we update the node, we will push the timestamp.
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.
:param kwargs: Any K/V attributes we want to update the
"""
self
.
first_name
=
first_name
self
.
last_name
=
last_name
...
...
@@ -72,6 +75,9 @@ class User(Neo4jCsvSerializable):
self
.
slack_id
=
slack_id
self
.
is_active
=
is_active
self
.
updated_at
=
updated_at
self
.
attrs
=
None
if
kwargs
:
self
.
attrs
=
copy
.
deepcopy
(
kwargs
)
self
.
_node_iter
=
iter
(
self
.
create_nodes
())
self
.
_rel_iter
=
iter
(
self
.
create_relation
())
...
...
@@ -124,6 +130,12 @@ class User(Neo4jCsvSerializable):
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
if
self
.
attrs
:
print
(
self
.
attrs
)
for
k
,
v
in
self
.
attrs
.
items
():
if
k
not
in
result_node
:
result_node
[
k
]
=
v
return
[
result_node
]
def
create_relation
(
self
):
...
...
setup.py
View file @
7b6bf54f
from
setuptools
import
setup
,
find_packages
__version__
=
'1.3.
3
'
__version__
=
'1.3.
4
'
setup
(
...
...
tests/unit/models/test_user.py
View file @
7b6bf54f
...
...
@@ -33,6 +33,25 @@ class TestUser(unittest.TestCase):
nodes
=
self
.
user
.
create_nodes
()
self
.
assertEquals
(
len
(
nodes
),
1
)
def
test_create_node_additional_attr
(
self
):
test_user
=
User
(
first_name
=
'test_first'
,
last_name
=
'test_last'
,
name
=
'test_first test_last'
,
email
=
'test@email.com'
,
github_username
=
'github_test'
,
team_name
=
'test_team'
,
employee_type
=
'FTE'
,
manager_email
=
'test_manager@email.com'
,
slack_id
=
'slack'
,
is_active
=
True
,
updated_at
=
1
,
role
=
'SWE'
,
enable_notify
=
True
)
nodes
=
test_user
.
create_nodes
()
self
.
assertEqual
(
nodes
[
0
][
'email'
],
'test@email.com'
)
self
.
assertEqual
(
nodes
[
0
][
'role'
],
'SWE'
)
self
.
assertTrue
(
nodes
[
0
][
'enable_notify'
])
def
test_create_relation
(
self
):
# type: () -> None
relations
=
self
.
user
.
create_relation
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment