Ejemplo n.º 1
0
 def test_session_from_registry_sessionmaker(self):
     """Assert the session is created using the sessionmaker in the registry."""
     mock_request = mock.Mock()
     session = server.get_db_session_for_request(mock_request)
     mock_request.registry.sessionmaker.assert_called_once_with()
     self.assertEqual(session,
                      mock_request.registry.sessionmaker.return_value)
Ejemplo n.º 2
0
    def test_cleanup_no_exception(self):
        """Test cleanup() when there is not an Exception."""
        request = mock.Mock()
        session = server.get_db_session_for_request(request)
        cleanup = request.add_finished_callback.mock_calls[0][1][0]
        request.exception = None

        cleanup(request)

        # Since there was no Exception, the session should have been committed and closed.
        self.assertEqual(session.rollback.mock_calls, [])
        self.assertEqual(session.commit.mock_calls, [mock.call()])
        self.assertEqual(session.close.mock_calls, [mock.call()])
Ejemplo n.º 3
0
    def test_cleanup_exception(self):
        """Test cleanup() when there is an Exception."""
        request = mock.Mock()
        session = server.get_db_session_for_request(request)
        cleanup = request.add_finished_callback.mock_calls[0][1][0]
        request.exception = IOError('The Internet ran out of cats.')

        cleanup(request)

        # Since there was an Exception, the session should have been rolled back and closed.
        self.assertEqual(session.rollback.mock_calls, [mock.call()])
        self.assertEqual(session.commit.mock_calls, [])
        self.assertEqual(session.close.mock_calls, [mock.call()])