def test_get_email_from_fit_quiz(self): # user filled a fit quiz view = InquiryApplyWizard() view.initial_dict = {} # add the fit quiz email cookie to the session email = '*****@*****.**' request = self._get_request() request.session['fit_email'] = email request.session.save() view.request = request self.assertEqual(view._get_email({}, 'first'), email)
def test_vet_based_on_form(self): view = InquiryApplyWizard() view.request = self._get_request() mocked_form = mock.Mock() with mock.patch.object(mocked_form, 'cleaned_data', { 'state': 'MA', 'zip_code': '02138' }): (outcome_slug, url_name, vetted_message) = view._vet_based_on_form( 'first', mocked_form ) # yapf: disable self.assertIsNone(outcome_slug) self.assertEqual(url_name, '') self.assertEqual(vetted_message, '')
def test_get_email_from_first_form_not_fit_quiz(self): # user filled a fit quiz but changed the email in the first step view = InquiryApplyWizard() request = self._get_request() fit_quiz_email = '*****@*****.**' request.session['fit_email'] = fit_quiz_email request.session.save() view.request = request first_email = '*****@*****.**' # yapf: disable self.assertEqual( view._get_email({'email': first_email, 'password1': 'testpassword1'}, 'first'), first_email )
def test_vet_based_on_form_not_first_step(self): """ tests that only the first step vets based on state """ view = InquiryApplyWizard() view.request = self._get_request() mocked_form = mock.Mock() for form in ['home', 'homeowner', 'signup']: with mock.patch.object(mocked_form, 'cleaned_data', { 'state': 'MT', 'zip_code': '01234' }): (outcome_slug, url_name, vetted_message) = view._vet_based_on_form(form, mocked_form) self.assertIsNone(outcome_slug) self.assertEqual(url_name, '') self.assertEqual(vetted_message, '')
def test_vet_based_on_form_calls_get_state_zip_code_outcome_key( self, mocked_get_state_zip_code_outcome_key): view = InquiryApplyWizard() view.request = self._get_request() mocked_get_state_zip_code_outcome_key.return_value = (None, '') mocked_form = mock.Mock() with mock.patch.object(mocked_form, 'cleaned_data', { 'state': 'MA', 'zip_code': '02138' }): (outcome_slug, url_name, vetted_message) = view._vet_based_on_form( 'first', mocked_form ) # yapf: disable cleaned_data = mocked_form.cleaned_data mocked_get_state_zip_code_outcome_key.assert_called_once_with( cleaned_data['state'], cleaned_data['zip_code'])
def test_vet_based_on_form_expansion_state(self): view = InquiryApplyWizard() view.request = self._get_request() mocked_form = mock.Mock() for state in EXPANSION_STATES: with mock.patch.object(mocked_form, 'cleaned_data', { 'state': state, 'zip_code': '01234' }): (outcome_slug, url_name, vetted_message) = view._vet_based_on_form( 'first', mocked_form) self.assertEqual(outcome_slug, INQUIRY_OUTCOME_SLUG_MAP['2_expansion_states']) self.assertEqual(url_name, 'inquiry:outcome') self.assertEqual(vetted_message, 'rejected expansion states')
def test_vet_based_on_form_undesirable_zip_code(self): view = InquiryApplyWizard() view.request = self._get_request() mocked_form = mock.Mock() for undesirable_zip_code in UNDESIRABLE_ZIP_CODES: with mock.patch.object(mocked_form, 'cleaned_data', { 'state': 'MA', 'zip_code': undesirable_zip_code }): (outcome_slug, url_name, vetted_message) = view._vet_based_on_form( 'first', mocked_form) self.assertEqual( outcome_slug, INQUIRY_OUTCOME_SLUG_MAP['3_undesirable_zip_code']) self.assertEqual(url_name, 'inquiry:outcome') self.assertEqual(vetted_message, 'rejected undesirable zip code')
def test_get_email_no_client_session_or_form(self): # no fit quiz and the user messed up on the first step view = InquiryApplyWizard() view.initial_dict = {} view.request = self._get_request() self.assertEqual(view._get_email({}, 'first'), '')