def test_call_does_nothing(self):
        from collective.team.browser.add_wizard import AddWizard

        request = Mock()
        request.form = {}
        view = AddWizard(None, request)
        view.index = Mock()
        view()
        self.assertEquals(1, view.index.call_count)
    def test_call_returns_subfolders(self):
        from collective.team.browser.add_wizard import AddWizard

        request = Mock()
        request.form = {"folder": "folder1"}
        folder = Mock()
        folder.getFolderContents = lambda: []
        context = {"folder1": folder}
        view = AddWizard(context, request)
        self.assertEquals("[]", view())
    def test_expired_survey_with_request(self, manage_addSurveyAnswer):
        survey = self.survey
        survey.expired = Mock(return_value=True)
        REQUEST = Mock()
        REQUEST.form = {}

        survey.addSurveyAnswer(REQUEST=REQUEST)

        survey.setSessionErrorsTrans.assert_called_with("The survey has expired")
        REQUEST.RESPONSE.redirect.assert_called_with("http://survey")
        self.assertEqual(manage_addSurveyAnswer.call_count, 0)
    def test_from_flask_request(self):
        from dce_lti_py.contrib.flask import FlaskToolProvider

        secret = generate_token()
        mock_req = Mock()
        mock_req.form = {"oauth_consumer_key": "foo"}
        mock_req.headers = {"Content-type": "bar"}
        mock_req.url = "http://example.edu/foo/bar"
        tp = FlaskToolProvider.from_flask_request(secret, mock_req)
        self.assertEqual(tp.consumer_key, "foo")
        self.assertEqual(tp.launch_headers["Content-type"], "bar")
        self.assertEqual(tp.launch_url, "http://example.edu/foo/bar")
    def test_invalidation_onsubmit_with_request(self, manage_addSurveyAnswer):
        survey = self.survey
        REQUEST = Mock()
        REQUEST.form = {}

        survey.addSurveyAnswer(REQUEST=REQUEST)

        survey.setSessionErrorsTrans.assert_called_with(["validation_onsubmit_error"])
        survey.setSessionAnswer.assert_called_with({})
        survey.setSession.assert_called_with("notify_respondent", False)
        REQUEST.RESPONSE.redirect.assert_called_with("http://survey")
        self.assertEqual(manage_addSurveyAnswer.call_count, 0)
    def test_no_multiple_answers_with_request(self, manage_addSurveyAnswer):
        survey = self.survey
        survey.allow_multiple_answers = False
        old_answer = Mock()
        old_answer.id = "12345"
        survey.getAnswerForRespondent = Mock(return_value=old_answer)
        survey._delObject = Mock()
        REQUEST = Mock()
        REQUEST.form = {}

        survey.addSurveyAnswer(REQUEST=REQUEST)

        survey._delObject.assert_called_with("12345")
        manage_addSurveyAnswer.assert_called_with(survey, {}, REQUEST=REQUEST, draft=False, id=None, respondent=None)
    def test_explicit_answer_id_with_request(self, manage_addSurveyAnswer):
        survey = self.survey
        survey._delObject = Mock()
        survey._getOb = Mock()
        survey._getOb.return_value.respondent = "usr"
        REQUEST = Mock()
        REQUEST.form = {"answer_id": "12345"}

        survey.addSurveyAnswer(REQUEST=REQUEST)

        survey._delObject.assert_called_with("12345")
        manage_addSurveyAnswer.assert_called_with(
            survey, {}, REQUEST=REQUEST, draft=False, id="12345", respondent="usr"
        )
    def test_invalid_captcha_with_request(self, manage_addSurveyAnswer):
        survey = self.survey
        getSite = survey.getSite
        getSite.return_value.validateCaptcha = Mock(return_value="test_error")
        REQUEST = Mock()
        REQUEST.form = {}

        survey.addSurveyAnswer(REQUEST=REQUEST)

        survey.setSessionErrorsTrans.assert_called_with(["test_error"])
        survey.setSessionAnswer.assert_called_with({})
        survey.setSession.assert_called_with("notify_respondent", False)
        REQUEST.RESPONSE.redirect.assert_called_with("http://survey")
        self.assertEqual(manage_addSurveyAnswer.call_count, 0)
    def test_success_with_request(self, manage_addSurveyAnswer):
        manage_addSurveyAnswer.return_value = "answer_12345"
        survey = self.survey
        REQUEST = Mock()
        REQUEST.form = {}

        result = survey.addSurveyAnswer(REQUEST=REQUEST)

        self.assertEqual(result, "answer_12345")
        self.assertEqual(survey.setSession.call_count, 3)
        self.assertEqual(survey.setSession.call_args_list[0][0], ("title", "Thank you for taking the survey"))
        self.assertEqual(survey.setSession.call_args_list[1][0], ("body", ""))
        self.assertEqual(survey.setSession.call_args_list[2][0], ("referer", "http://survey"))
        survey.delSessionKeys.assert_called_with([])
        REQUEST.RESPONSE.redirect.assert_called_with("http://survey/messages_html")
        manage_addSurveyAnswer.assert_called_with(survey, {}, REQUEST=REQUEST, draft=False, id=None, respondent=None)
Example #10
0
    def test_invalid_widget_with_request(self, manage_addSurveyAnswer):
        survey = self.survey
        widget = Mock()
        widget.getWidgetId = Mock(return_value="test_widget")
        widget.getDatamodel = Mock(return_value="")
        widget.validateDatamodel = Mock(side_effect=WidgetError("test_error"))
        survey.getWidgets = Mock(return_value=[widget])
        REQUEST = Mock()
        REQUEST.form = {}

        survey.addSurveyAnswer(REQUEST=REQUEST)

        survey.setSessionErrorsTrans.assert_called_with(["test_error"])
        survey.setSessionAnswer.assert_called_with({"test_widget": None})
        survey.setSession.assert_called_with("notify_respondent", False)
        REQUEST.RESPONSE.redirect.assert_called_with("http://survey")
        self.assertEqual(manage_addSurveyAnswer.call_count, 0)
Example #11
0
    def test_add_draft_with_request(self, manage_addSurveyAnswer):
        manage_addSurveyAnswer.return_value = "answer_12345"
        survey = self.survey
        answer = Mock()
        answer.absolute_url = Mock(return_value="http://survey/answer_12345")
        survey._getOb = Mock(return_value=answer)
        survey.canAddAnswerDraft = Mock(return_value=True)
        REQUEST = Mock()
        REQUEST.form = {}

        result = survey.addSurveyAnswer(REQUEST=REQUEST, draft=True)

        self.assertEqual(result, "answer_12345")
        self.assertEqual(survey.setSession.call_count, 0)
        survey.delSessionKeys.assert_called_with([])
        REQUEST.RESPONSE.redirect.assert_called_with("http://survey/answer_12345?edit=1")
        manage_addSurveyAnswer.assert_called_with(survey, {}, REQUEST=REQUEST, draft=True, id=None, respondent=None)
Example #12
0
def _mock_request():
    mock_request = Mock()
    mock_request.form = dict((k, "") for k in ["title", "endpoint_url", "timeout", "query", "arg_spec"])
    mock_request.SESSION = {}
    return mock_request