1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
import unittest
from unittest import mock
from ...management.jobs import Jobs
class TestJobs(unittest.TestCase):
def test_init_with_optionals(self):
t = Jobs(domain="domain", token="jwttoken", telemetry=False, timeout=(10, 2))
self.assertEqual(t.client.options.timeout, (10, 2))
telemetry_header = t.client.base_headers.get("Auth0-Client", None)
self.assertEqual(telemetry_header, None)
@mock.patch("auth0.management.jobs.RestClient")
def test_get(self, mock_rc):
mock_instance = mock_rc.return_value
j = Jobs(domain="domain", token="jwttoken")
j.get("an-id")
mock_instance.get.assert_called_with(
"https://domain/api/v2/jobs/an-id",
)
@mock.patch("auth0.management.jobs.RestClient")
def test_get_failed_job(self, mock_rc):
mock_instance = mock_rc.return_value
j = Jobs(domain="domain", token="jwttoken")
j.get_failed_job("an-id")
mock_instance.get.assert_called_with(
"https://domain/api/v2/jobs/an-id/errors",
)
@mock.patch("auth0.management.jobs.RestClient")
def test_export_users(self, mock_rc):
mock_instance = mock_rc.return_value
j = Jobs(domain="domain", token="jwttoken")
j.export_users({"connection_id": "cxn_id", "format": "json"})
mock_instance.post.assert_called_with(
"https://domain/api/v2/jobs/users-exports",
data={"connection_id": "cxn_id", "format": "json"},
)
@mock.patch("auth0.management.jobs.RestClient")
def test_import_users(self, mock_rc):
mock_instance = mock_rc.return_value
j = Jobs(domain="domain", token="jwttoken")
j.import_users(connection_id="1234", file_obj={})
mock_instance.file_post.assert_called_with(
"https://domain/api/v2/jobs/users-imports",
data={
"connection_id": "1234",
"upsert": "false",
"send_completion_email": "true",
"external_id": None,
},
files={"users": {}},
)
j.import_users(
connection_id="1234",
file_obj={},
upsert=True,
send_completion_email=False,
external_id="ext-id-123",
)
mock_instance.file_post.assert_called_with(
"https://domain/api/v2/jobs/users-imports",
data={
"connection_id": "1234",
"upsert": "true",
"send_completion_email": "false",
"external_id": "ext-id-123",
},
files={"users": {}},
)
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",
"send_completion_email": "true",
"external_id": None,
},
files={"users": {}},
)
@mock.patch("auth0.management.jobs.RestClient")
def test_verification_email(self, mock_rc):
mock_instance = mock_rc.return_value
j = Jobs(domain="domain", token="jwttoken")
j.send_verification_email({"a": "b", "c": "d"})
mock_instance.post.assert_called_with(
"https://domain/api/v2/jobs/verification-email", data={"a": "b", "c": "d"}
)
|