-
Notifications
You must be signed in to change notification settings - Fork 171
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add more unit tests #164
Add more unit tests #164
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import unittest | ||
from ...management.auth0 import Auth0 | ||
from ...management.blacklists import Blacklists | ||
from ...management.clients import Clients | ||
from ...management.client_grants import ClientGrants | ||
from ...management.connections import Connections | ||
from ...management.device_credentials import DeviceCredentials | ||
from ...management.emails import Emails | ||
from ...management.email_templates import EmailTemplates | ||
from ...management.guardian import Guardian | ||
from ...management.jobs import Jobs | ||
from ...management.logs import Logs | ||
from ...management.resource_servers import ResourceServers | ||
from ...management.rules import Rules | ||
from ...management.stats import Stats | ||
from ...management.tenants import Tenants | ||
from ...management.tickets import Tickets | ||
from ...management.user_blocks import UserBlocks | ||
from ...management.users import Users | ||
from ...management.users_by_email import UsersByEmail | ||
|
||
|
||
class TestAuth0(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.domain = 'user.some.domain' | ||
self.token = 'a-token' | ||
self.a0 = Auth0(self.domain, self.token) | ||
|
||
def test_blacklists(self): | ||
self.assertIsInstance(self.a0.blacklists, Blacklists) | ||
|
||
def test_clients(self): | ||
self.assertIsInstance(self.a0.clients, Clients) | ||
|
||
def test_client_grants(self): | ||
self.assertIsInstance(self.a0.client_grants, ClientGrants) | ||
|
||
def test_connections(self): | ||
self.assertIsInstance(self.a0.connections, Connections) | ||
|
||
def test_device_credentials(self): | ||
self.assertIsInstance(self.a0.device_credentials, DeviceCredentials) | ||
|
||
def test_emails(self): | ||
self.assertIsInstance(self.a0.emails, Emails) | ||
|
||
def test_email_templates(self): | ||
self.assertIsInstance(self.a0.email_templates, EmailTemplates) | ||
|
||
def test_guardian(self): | ||
self.assertIsInstance(self.a0.guardian, Guardian) | ||
|
||
def test_jobs(self): | ||
self.assertIsInstance(self.a0.jobs, Jobs) | ||
|
||
def test_logs(self): | ||
self.assertIsInstance(self.a0.logs, Logs) | ||
|
||
def test_resource_servers(self): | ||
self.assertIsInstance(self.a0.resource_servers, ResourceServers) | ||
|
||
def test_rules(self): | ||
self.assertIsInstance(self.a0.rules, Rules) | ||
|
||
def test_stats(self): | ||
self.assertIsInstance(self.a0.stats, Stats) | ||
|
||
def test_tenants(self): | ||
self.assertIsInstance(self.a0.tenants, Tenants) | ||
|
||
def test_tickets(self): | ||
self.assertIsInstance(self.a0.tickets, Tickets) | ||
|
||
def test_user_blocks(self): | ||
self.assertIsInstance(self.a0.user_blocks, UserBlocks) | ||
|
||
def test_users(self): | ||
self.assertIsInstance(self.a0.users, Users) | ||
|
||
def test_users_by_email(self): | ||
self.assertIsInstance(self.a0.users_by_email, UsersByEmail) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,11 +17,11 @@ def test_get(self, mock_rc): | |
) | ||
|
||
@mock.patch('auth0.v3.management.jobs.RestClient') | ||
def get_failed_job(self, mock_rc): | ||
def test_get_failed_job(self, mock_rc): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
mock_instance = mock_rc.return_value | ||
|
||
j = Jobs(domain='domain', token='jwttoken') | ||
j.get('an-id') | ||
j.get_failed_job('an-id') | ||
|
||
mock_instance.get.assert_called_with( | ||
'https://domain/api/v2/jobs/an-id/errors', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,6 +198,56 @@ def test_post_error_with_no_response_text(self, mock_post): | |
self.assertEqual(context.exception.error_code, 'a0.sdk.internal.unknown') | ||
self.assertEqual(context.exception.message, '') | ||
|
||
@mock.patch('requests.post') | ||
def test_post_error_with_error_but_no_error_code(self, mock_post): | ||
rc = RestClient(jwt='a-token', telemetry=False) | ||
|
||
for error_status in [400, 500, None]: | ||
mock_post.return_value.status_code = error_status | ||
mock_post.return_value.text = '{"error": "SomeError"}' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Our errors typically come back with both an |
||
|
||
with self.assertRaises(Auth0Error) as context: | ||
rc.post('the-url') | ||
|
||
self.assertEqual(context.exception.status_code, error_status) | ||
self.assertEqual(context.exception.error_code, 'SomeError') | ||
|
||
@mock.patch('requests.post') | ||
def test_file_post(self, mock_post): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we doing this anywhere in the SDK? |
||
rc = RestClient(jwt='a-token', telemetry=False) | ||
headers = {'Authorization': 'Bearer a-token'} | ||
|
||
mock_post.return_value.text = '{"a": "b"}' | ||
|
||
data = {'some': 'data'} | ||
files = {'file': ('some.file', 'Has some text in it\n')} | ||
mock_post.return_value.status_code = 200 | ||
response = rc.file_post('the/url', data=data, files=files) | ||
mock_post.assert_called_with('the/url', data=data, | ||
files=files, headers=headers) | ||
|
||
self.assertEqual(response, {'a': 'b'}) | ||
|
||
@mock.patch('requests.post') | ||
def test_file_post_errors(self, mock_post): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we doing this anywhere in the SDK? |
||
rc = RestClient(jwt='a-token', telemetry=False) | ||
|
||
mock_post.return_value.text = json.dumps({ | ||
'statusCode': 999, | ||
'errorCode': 'some_code', | ||
'error': 'some_error' | ||
}) | ||
mock_post.return_value.status_code = 999 | ||
|
||
data = {'some': 'data'} | ||
files = {'file': ('some.file', 'Has some text in it\n')} | ||
with self.assertRaises(Auth0Error) as context: | ||
rc.file_post('the-url', data=data, files=files) | ||
|
||
self.assertEqual(context.exception.status_code, 999) | ||
self.assertEqual(context.exception.error_code, 'some_code') | ||
self.assertEqual(context.exception.message, 'some_error') | ||
|
||
@mock.patch('requests.patch') | ||
def test_patch(self, mock_patch): | ||
rc = RestClient(jwt='a-token', telemetry=False) | ||
|
@@ -231,6 +281,39 @@ def test_patch_errors(self, mock_patch): | |
self.assertEqual(context.exception.error_code, 'code') | ||
self.assertEqual(context.exception.message, 'message') | ||
|
||
@mock.patch('requests.put') | ||
def test_put(self, mock_put): | ||
rc = RestClient(jwt='a-token', telemetry=False) | ||
headers = {'Authorization': 'Bearer a-token', | ||
'Content-Type': 'application/json'} | ||
|
||
mock_put.return_value.text = '["a", "b"]' | ||
mock_put.return_value.status_code = 200 | ||
|
||
data = {'some': 'data'} | ||
|
||
response = rc.put(url='the-url', data=data) | ||
mock_put.assert_called_with('the-url', data=json.dumps(data), | ||
headers=headers) | ||
|
||
self.assertEqual(response, ['a', 'b']) | ||
|
||
@mock.patch('requests.put') | ||
def test_put_errors(self, mock_put): | ||
rc = RestClient(jwt='a-token', telemetry=False) | ||
|
||
mock_put.return_value.text = '{"statusCode": 999,' \ | ||
' "errorCode": "code",' \ | ||
' "message": "message"}' | ||
mock_put.return_value.status_code = 999 | ||
|
||
with self.assertRaises(Auth0Error) as context: | ||
rc.put(url='the/url') | ||
|
||
self.assertEqual(context.exception.status_code, 999) | ||
self.assertEqual(context.exception.error_code, 'code') | ||
self.assertEqual(context.exception.message, 'message') | ||
|
||
@mock.patch('requests.delete') | ||
def test_delete(self, mock_delete): | ||
rc = RestClient(jwt='a-token', telemetry=False) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import unittest | ||
from ..exceptions import Auth0Error | ||
|
||
|
||
class TestAuth0Error(unittest.TestCase): | ||
|
||
def test_construct(self): | ||
err = Auth0Error(123, 456, 'some message') | ||
self.assertIsInstance(err, Exception) | ||
|
||
def test_str(self): | ||
err = Auth0Error(123, 456, 'some message') | ||
string_repr = str(err) | ||
self.assertIn('some message', string_repr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this also assert the status code?