diff --git a/src/octokit/__init__.py b/src/octokit/__init__.py index 564ab13..5995963 100644 --- a/src/octokit/__init__.py +++ b/src/octokit/__init__.py @@ -1,3 +1,4 @@ +import copy import datetime import json import re @@ -180,10 +181,11 @@ class Octokit(Base): attributes = _response.json() except ValueError: attributes = _response.text - setattr(self, '_response', _response) - setattr(self, 'json', attributes) - setattr(self, 'response', self._convert_to_object(attributes)) - return self + new_self = copy.deepcopy(self) + setattr(new_self, '_response', _response) + setattr(new_self, 'json', attributes) + setattr(new_self, 'response', new_self._convert_to_object(attributes)) + return new_self _api_call.__name__ = name _api_call.__doc__ = definition['description'] diff --git a/tests/test_methods.py b/tests/test_methods.py index a5e75a7..951f83c 100644 --- a/tests/test_methods.py +++ b/tests/test_methods.py @@ -144,15 +144,17 @@ class TestClientMethods(object): } ) - def test_returned_object_is_self(self, mocker): + def test_returned_object_is_not_self_but_a_copy_of_self(self, mocker): mocker.patch('requests.patch') headers = {'accept': 'application/vnd.github.squirrel-girl-preview', 'Content-Type': 'application/json'} data = {'state': 'open'} - sut = Octokit().issues.edit(owner='testUser', repo='testRepo', number=1) + octokit = Octokit() + sut = octokit.issues.edit(owner='testUser', repo='testRepo', number=1) requests.patch.assert_called_once_with( 'https://api.github.com/repos/testUser/testRepo/issues/1', data=json.dumps(data), headers=headers ) assert sut.__class__.__name__ == 'Octokit' + assert sut != octokit def test_returned_object_has_requests_response_object(self, mocker): patch = mocker.patch('requests.patch')