Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add send_completion_email to users import job #220

Merged
merged 1 commit into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions auth0/v3/management/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def export_users(self, body):
"""
return self.client.post(self._url('users-exports'), data=body)

def import_users(self, connection_id, file_obj, upsert=False):
def import_users(self, connection_id, file_obj, upsert=False, send_completion_email=True):
"""Imports users to a connection from a file.

Args:
Expand All @@ -82,10 +82,21 @@ def import_users(self, connection_id, file_obj, upsert=False):
file_obj (file): A file-like object to upload. The format for
this file is explained in: https://auth0.com/docs/bulk-import

upsert (bool): When set to False, pre-existing users that match on email address, user ID, or username
will fail. When set to True, pre-existing users that match on any of these fields will be updated, but
only with upsertable attributes. Defaults to False.
For a list of user profile fields that can be upserted during import, see the following article
https://auth0.com/docs/users/references/user-profile-structure#user-profile-attributes

send_completion_email (bool): When set to True, an email will be sent to notify the completion of this job.
When set to False, no email will be sent. Defaults to True.

See: https://auth0.com/docs/api/management/v2#!/Jobs/post_users_imports
"""
return self.client.file_post(self._url('users-imports'),
data={'connection_id': connection_id, 'upsert': str(upsert).lower()},
data={'connection_id': connection_id,
'upsert': str(upsert).lower(),
'send_completion_email': str(send_completion_email).lower()},
files={'users': file_obj})

def send_verification_email(self, body):
Expand Down
10 changes: 5 additions & 5 deletions auth0/v3/test/management/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,21 @@ def test_import_users(self, mock_rc):

mock_instance.file_post.assert_called_with(
'https://domain/api/v2/jobs/users-imports',
data={'connection_id': '1234', 'upsert': 'false'},
data={'connection_id': '1234', 'upsert': 'false', 'send_completion_email': 'true'},
files={'users': {}}
)

j.import_users(connection_id='1234', file_obj={}, upsert=True)
j.import_users(connection_id='1234', file_obj={}, upsert=True, send_completion_email=False)
mock_instance.file_post.assert_called_with(
'https://domain/api/v2/jobs/users-imports',
data={'connection_id': '1234', 'upsert': 'true'},
data={'connection_id': '1234', 'upsert': 'true', 'send_completion_email': 'false'},
files={'users': {}}
)

j.import_users(connection_id='1234', file_obj={}, upsert=False)
j.import_users(connection_id='1234', file_obj={}, upsert=False, send_completion_email=True)
mock_instance.file_post.assert_called_with(
'https://domain/api/v2/jobs/users-imports',
data={'connection_id': '1234', 'upsert': 'false'},
data={'connection_id': '1234', 'upsert': 'false', 'send_completion_email': 'true'},
files={'users': {}}
)

Expand Down