Skip to content

Commit

Permalink
Fix #9 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Aitor Magán García committed Oct 18, 2016
1 parent f6959c4 commit 4601615
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 5 additions & 0 deletions ckanext/oauth2/tests/test_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,17 @@ def setUp(self):
self._toolkit = controller.toolkit
controller.toolkit = MagicMock()

self.__session = controller.session
controller.session = MagicMock()

self.controller = controller.OAuth2Controller()

def tearDown(self):
# Unmock the function
controller.helpers = self._helpers
controller.oauth2 = self._oauth2
controller.toolkit = self._toolkit
controller.session = self.__session

def generate_state(self, url):
return b64encode(bytes(json.dumps({CAME_FROM_FIELD: url})))
Expand Down Expand Up @@ -118,6 +122,7 @@ def test_controller_errors(self, came_from=None, exception=Exception(EXCEPTION_M
self.controller.callback()

# Check the state and the location
controller.session.save.assert_called_once_with()
self.assertEquals(RETURNED_STATUS, controller.toolkit.response.status_int)
self.assertEquals(came_from, controller.toolkit.response.location)
controller.helpers.flash_error.assert_called_once_with(expected_flash)
4 changes: 0 additions & 4 deletions ckanext/oauth2/tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ def setUp(self):
self._toolkit = plugin.toolkit
plugin.toolkit = MagicMock()

self._session = plugin.session
plugin.session = MagicMock()

self._oauth2 = plugin.oauth2
plugin.oauth2 = MagicMock()
Expand All @@ -50,7 +48,6 @@ def tearDown(self):
# Unmock functions
plugin.config = self._config
plugin.toolkit = self._toolkit
plugin.session = self._session

def _set_identity(self, identity):
plugin.toolkit.request.environ = {}
Expand Down Expand Up @@ -166,7 +163,6 @@ def authenticate_side_effect(identity):
self.assertEquals(0, plugin.oauth2.OAuth2Helper.return_value.identify.call_count)

self.assertEquals(expected_user, plugin.toolkit.c.user)
plugin.session.save.assert_called_once()

if expected_user is None:
self.assertIsNone(plugin.toolkit.c.usertoken)
Expand Down

0 comments on commit 4601615

Please sign in to comment.