Skip to content
Open
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
14 changes: 7 additions & 7 deletions tests/auth_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
limitations under the License.
"""
import json
from unittest.mock import MagicMock
from unittest.mock import patch
from mock import MagicMock
from mock import patch

import unittest2

Expand All @@ -31,7 +31,7 @@ def tearDown(self):
patch.stopall()

def test_generate_token(self):
mock_requests = patch(TARGET).start()
mock_requests = patch(self.TARGET).start()
token_data = {
'token': 'token123',
'expires_at': '2018-04-12T05:51:58.144271Z',
Expand All @@ -53,7 +53,7 @@ def test_generate_token(self):
)

def test_generate_token_validator(self):
mock_requests = patch(TARGET).start()
mock_requests = patch(self.TARGET).start()

response_mock = MagicMock(return_value={'message': 'Error'})
mock_requests.post.return_value = MagicMock(
Expand All @@ -63,7 +63,7 @@ def test_generate_token_validator(self):
Auth('http://localhost', 'test', '123')

def test_generate_token_unauthorized(self):
mock_requests = patch(TARGET).start()
mock_requests = patch(self.TARGET).start()

response_mock = MagicMock(return_value={'message': 'Error'})
mock_requests.post.return_value = MagicMock(
Expand All @@ -73,7 +73,7 @@ def test_generate_token_unauthorized(self):
Auth('http://localhost', 'test', '123')

def test_generate_token_error(self):
mock_requests = patch(TARGET).start()
mock_requests = patch(self.TARGET).start()

response_mock = MagicMock(return_value={'message': 'Error'})
mock_requests.post.return_value = MagicMock(
Expand All @@ -83,7 +83,7 @@ def test_generate_token_error(self):
Auth('http://localhost', 'test', '123')

def test_generate_token_exception(self):
mock_requests = patch(TARGET).start()
mock_requests = patch(self.TARGET).start()

mock_requests.post = MagicMock(side_effect=Exception())

Expand Down
49 changes: 17 additions & 32 deletions tests/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
limitations under the License.
"""
import json
from unittest.mock import MagicMock
from unittest.mock import Mock
from unittest.mock import patch
from mock import MagicMock
from mock import Mock
from mock import patch

import unittest2

Expand All @@ -27,12 +27,12 @@
class BaseTest(unittest2.TestCase):

TARGET = 'globomap_loader_api_client.base.Session'

def tearDown(self):
patch.stopall()

def test_post_error(self):
mock_requests = patch(TARGET).start()
mock_requests = patch(self.TARGET).start()
response_mock = MagicMock(return_value={'message': 'Error'})

mock_requests.return_value.request.return_value = MagicMock(
Expand All @@ -45,7 +45,7 @@ def test_post_error(self):
base.make_request('POST', 'path', data)

def test_post_exception(self):
mock_requests = patch(TARGET).start()
mock_requests = patch(self.TARGET).start()

mock_requests.return_value.request.side_effect = Exception()

Expand All @@ -56,7 +56,7 @@ def test_post_exception(self):
base.make_request('POST', 'path', data)

def test_post_202(self):
mock_session = TARGET).start()
mock_session = patch(self.TARGET).start()

response_mock = MagicMock(return_value={'message': 'message'})
request_mock = mock_session.return_value.request
Expand All @@ -79,7 +79,7 @@ def test_post_202(self):
)

def test_post_400(self):
mock_requests = patch(TARGET).start()
mock_requests = patch(self.TARGET).start()
response_mock = MagicMock(return_value={'message': 'Error'})

mock_requests.return_value.request.return_value = MagicMock(
Expand All @@ -91,7 +91,7 @@ def test_post_400(self):
base.make_request('POST', 'path', data)

def test_post_401(self):
mock_requests = patch(TARGET).start()
mock_requests = patch(self.TARGET).start()
mock_time = patch(
'globomap_loader_api_client.base.time').start()
response_mock = MagicMock(return_value={'message': 'Error'})
Expand All @@ -114,7 +114,7 @@ def test_post_401(self):
mock_time.sleep.assert_any_call(5 + 15)

def test_post_403(self):
mock_requests = patch(TARGET).start()
mock_requests = patch(self.TARGET).start()
response_mock = MagicMock(return_value={'message': 'Error'})

mock_requests.return_value.request.return_value = MagicMock(
Expand All @@ -127,7 +127,7 @@ def test_post_403(self):
base.make_request('POST', 'path', None, data)

def test_post_404(self):
mock_requests = patch(TARGET).start()
mock_requests = patch(self.TARGET).start()
response_mock = MagicMock(return_value={'message': 'Error'})

mock_requests.return_value.request.return_value = MagicMock(
Expand All @@ -140,7 +140,7 @@ def test_post_404(self):
base.make_request('POST', 'path', None, data)

def test_get_error(self):
mock_requests = patch(TARGET).start()
mock_requests = patch(self.TARGET).start()
response_mock = MagicMock(return_value={'message': 'Error'})

mock_requests.return_value.request.return_value = MagicMock(
Expand All @@ -152,7 +152,7 @@ def test_get_error(self):
base.make_request('GET', 'path', None)

def test_get_exception(self):
mock_requests = patch(TARGET).start()
mock_requests = patch(self.TARGET).start()

mock_requests.return_value.request.side_effect = Exception()
base = Base(Mock(), 'driver_test')
Expand All @@ -161,7 +161,7 @@ def test_get_exception(self):
base.make_request('GET', 'path', None)

def test_get_200(self):
mock_session = TARGET).start()
mock_session = patch(self.TARGET).start()

response_mock = MagicMock(return_value={'message': 'message'})
request_mock = mock_session.return_value.request
Expand All @@ -182,7 +182,7 @@ def test_get_200(self):
)

def test_get_401(self):
mock_requests = patch(TARGET).start()
mock_requests = patch(self.TARGET).start()
mock_time = patch(
'globomap_loader_api_client.base.time').start()
response_mock = MagicMock(return_value={'message': 'Error'})
Expand All @@ -202,7 +202,7 @@ def test_get_401(self):
mock_time.sleep.assert_any_call(5 + 10)

def test_get_403(self):
mock_requests = patch(TARGET).start()
mock_requests = patch(self.TARGET).start()
response_mock = MagicMock(return_value={'message': 'Error'})

mock_requests.return_value.request.return_value = MagicMock(
Expand All @@ -214,7 +214,7 @@ def test_get_403(self):
base.make_request('GET', 'path', None)

def test_get_404(self):
mock_requests = patch(TARGET).start()
mock_requests = patch(self.TARGET).start()
response_mock = MagicMock(return_value={'message': 'Error'})

mock_requests.return_value.request.return_value = MagicMock(
Expand All @@ -224,18 +224,3 @@ def test_get_404(self):

with self.assertRaises(exceptions.NotFound):
base.make_request('GET', 'path', None)

# self.assertEqual(base.auth.generate_token.call_count, 3)
# self.assertEqual(base.make_request.call_count, 3)
# self.assertEqual(base.auth.generate_token.call_count, 3)
# .assert_called
# assert_called_once_with
# self.()
# return self.make_request(
# method=method, uri=uri, params=params,
# data=data, retries=retries+1)

# self.assertEqual(base.auth.generate_token.call_count, 3)
# self.auth.generate_token()
# self.make_request(method=method, uri=uri, params=params,
# data=data, retries=retries + 1)
4 changes: 2 additions & 2 deletions tests/update_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
See the License for the specific language governing permissions and
limitations under the License.
"""
from unittest.mock import Mock
from unittest.mock import patch
from mock import Mock
from mock import patch

import unittest2

Expand Down