Skip to content

Commit

Permalink
Add test for http code 401
Browse files Browse the repository at this point in the history
  • Loading branch information
surkova committed Jun 9, 2016
1 parent 2d1223c commit 6ee2b60
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from mock import patch, MagicMock
from urllib3.exceptions import SSLError

from txclib import utils
from txclib import utils, exceptions


class MakeRequestTestCase(unittest.TestCase):
Expand Down Expand Up @@ -87,7 +87,7 @@ def test_makes_request_404(self, mock_connection_from_url):
host = 'http://whynotestsforthisstuff.com'
url = '/my_test_url/'
self.assertRaises(
utils.HttpNotFound,
exceptions.HttpNotFound,
utils.make_request,
'GET',
host,
Expand Down Expand Up @@ -118,6 +118,28 @@ def test_makes_request_403(self, mock_connection_from_url):
'a_pass'
)

@patch('urllib3.connection_from_url')
def test_makes_request_401(self, mock_connection_from_url):
response_mock = MagicMock()
response_mock.status = 401
response_mock.data = 'test_data'

mock_connection = MagicMock()
mock_connection.request.return_value = response_mock
mock_connection_from_url.return_value = mock_connection

host = 'http://whynotestsforthisstuff.com'
url = '/my_test_url/'
self.assertRaises(
exceptions.HttpNotAuthorized,
utils.make_request,
'GET',
host,
url,
'a_user',
'a_pass'
)

@patch('urllib3.connection_from_url')
def test_makes_request_None(self, mock_connection_from_url):
response_mock = MagicMock()
Expand Down

0 comments on commit 6ee2b60

Please sign in to comment.