Skip to content

SG-38306 Python2 Removal - Part 5 - Remove deprecated backported mock module #402

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

Open
wants to merge 7 commits into
base: ticket/SG-38306-python2-removal-mimetypes
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@

[flake8]
max-line-length = 120
exclude = shotgun_api3/lib/httplib2/*,shotgun_api3/lib/six.py,tests/httplib2test.py,tests/mock.py
exclude = shotgun_api3/lib/httplib2/*,shotgun_api3/lib/six.py,tests/httplib2test.py
13 changes: 6 additions & 7 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
import re
import time
import unittest
import unittest.mock
import urllib.error

from . import mock

import shotgun_api3 as api
from shotgun_api3.shotgun import ServerCapabilities
from shotgun_api3.lib import six
Expand Down Expand Up @@ -133,12 +132,12 @@ def _setup_mock(self, s3_status_code_error=503):
"""Setup mocking on the ShotgunClient to stop it calling a live server"""
# Replace the function used to make the final call to the server
# eaiser than mocking the http connection + response
self.sg._http_request = mock.Mock(
self.sg._http_request = unittest.mock.Mock(
spec=api.Shotgun._http_request, return_value=((200, "OK"), {}, None)
)
# Replace the function used to make the final call to the S3 server, and simulate
# the exception HTTPError raised with 503 status errors
self.sg._make_upload_request = mock.Mock(
self.sg._make_upload_request = unittest.mock.Mock(
spec=api.Shotgun._make_upload_request,
side_effect=urllib.error.HTTPError(
"url",
Expand All @@ -152,12 +151,12 @@ def _setup_mock(self, s3_status_code_error=503):
# also replace the function that is called to get the http connection
# to avoid calling the server. OK to return a mock as we will not use
# it
self.mock_conn = mock.Mock(spec=api.lib.httplib2.Http)
self.mock_conn = unittest.mock.Mock(spec=api.lib.httplib2.Http)
# The Http objects connection property is a dict of connections
# it is holding
self.mock_conn.connections = dict()
self.sg._connection = self.mock_conn
self.sg._get_connection = mock.Mock(return_value=self.mock_conn)
self.sg._get_connection = unittest.mock.Mock(return_value=self.mock_conn)

# create the server caps directly to say we have the correct version
self.sg._server_caps = ServerCapabilities(
Expand All @@ -173,7 +172,7 @@ def _mock_http(self, data, headers=None, status=None):
"""
# test for a mock object rather than config.mock as some tests
# force the mock to be created
if not isinstance(self.sg._http_request, mock.Mock):
if not isinstance(self.sg._http_request, unittest.mock.Mock):
return

if not isinstance(data, str):
Expand Down
Loading