def test_connection_auth(self, mock_method): mock_method.return_value = {'result': 'success'} params = { 'username': self.username, 'auth_data': self.password, 'auth_method': self.auth_method, 'apikey': self.apikey } connection = Connection(self.server) self.assertFalse(connection._is_authed) connection.auth(self.username, self.password, self.auth_method, self.apikey) connection.make_request.assert_called_once_with("auth", params) self.assertTrue(connection._is_authed) mock_method.return_value = {'result': 'exception', 'exception': { 'message': 'Auth', 'id': 1, 'type': 'HolviAuthException' } } mock_method.reset_mock() with self.assertRaises(HolviAuthException): connection.auth(self.username, self.password, self.auth_method, self.apikey) connection.make_request.assert_called_once_with("auth", params) self.assertFalse(connection._is_authed)