def test_should_validate_the_mobile_number_for_paid_account_if_unique(self): org = Mock(spec=Organization) org.in_trial_mode = False self.get_database_manager_for_org_mock.return_value = Mock(spec=DatabaseManager) self.find_reporters_by_from_number_mock.side_effect = NumberNotRegisteredException('1234') validator = get_unique_mobile_number_validator(org) self.assertTrue(validator(org,'1234'))
def test_should_return_default_msg_for_exception_if_channel_specific_msg_missing( self): message = get_exception_message_for( exception=NumberNotRegisteredException("1234567890"), channel="web") expected_message = "This telephone number is not registered in our system." self.assertEqual(expected_message, message)
def find_reporters_by_from_number(dbm, from_number): reporters = data.aggregate(dbm, entity_type=REPORTER_ENTITY_TYPE, aggregates={MOBILE_NUMBER_FIELD: data.reduce_functions.LATEST, NAME_FIELD: data.reduce_functions.LATEST}, aggregate_on=EntityAggregration() ) from_reporter_list = [{id: reporters[id]} for id in reporters if reporters[id].get(MOBILE_NUMBER_FIELD) == from_number] if not len(from_reporter_list): raise NumberNotRegisteredException(from_number) return from_reporter_list
def find_reporters_by_from_number(dbm, from_number): rows = dbm.view.datasender_by_mobile(start_key=[from_number], end_key=[from_number, {}], include_docs=True) if len(rows) == 0: raise NumberNotRegisteredException(from_number) return [ Contact.new_from_doc(dbm=dbm, doc=Contact.__document_class__.wrap( row.get('doc'))) for row in rows ]
def test_should_handle_NumberNotRegisteredException(self): patcher = patch('datawinners.messageprovider.handlers.create_failure_log') create_failure_log_mock = patcher.start() exception = NumberNotRegisteredException('1234312') expected_message = get_exception_message_for(exception, SMS) response = handle(exception, self.request) patcher.stop() self.assertEqual(expected_message, response) create_failure_log_mock.assert_called_with(expected_message,self.request)
def test_should_validate_the_mobile_number_for_paid_account_if_not_unique( self): org = Mock(spec=Organization) type(org).in_trial_mode = PropertyMock(return_value=False) validator = MobileNumberValidater(org, "56789", "rep") with patch( "datawinners.accountmanagement.mobile_number_validater.find_reporters_by_from_number" ) as find_reporters_by_from_number: with patch( "datawinners.accountmanagement.mobile_number_validater.get_database_manager_for_org" ) as get_db_manager: find_reporters_by_from_number.return_value = [] find_reporters_by_from_number.side_effect = NumberNotRegisteredException( "12345678") manager = MagicMock(spec=DatabaseManager) manager.load_all_rows_in_view.return_value = [] get_db_manager.return_value = manager self.assertTrue(validator.validate())
def test_should_allow_submission_by_unregistered_reporter_for_open_datasender_questionnaire( self): self.reporter_module.find_reporter_entity.side_effect = NumberNotRegisteredException( "1234") self.form_model_mock.is_open_survey = True entity_question_field = Mock() entity_question_field.code = 'q1' self.form_model_mock.entity_questions = [entity_question_field] with patch('mangrove.form_model.project.get_project_by_code' ) as get_project_by_code: with patch('mangrove.form_model.project.check_if_form_code_is_poll' ) as mock_check_if_form_code_is_poll: response = self.sms_player.add_survey_response( Request(message=self.message, transportInfo=self.transport)) self.assertEqual(response.errors, {}) self.assertTrue(response.success)
def test_should_handle_NumberNotRegisteredException(self): patcher = patch( 'datawinners.messageprovider.handlers.create_failure_log') create_failure_log_mock = patcher.start() exception = NumberNotRegisteredException('1234312') expected_message = "error msg" with patch( "datawinners.messageprovider.handlers.get_account_wide_sms_reply" ) as get_account_wide_sms_reply_mock: get_account_wide_sms_reply_mock.return_value = "error msg" response = handle(exception, self.request) patcher.stop() self.assertEqual(expected_message, response) create_failure_log_mock.assert_called_with(expected_message, self.request)
def test_should_return_valid_message_if_its_not_parameterized(self): message = get_exception_message_for( exception=NumberNotRegisteredException("1234567"), channel="web") expected_message = "This telephone number is not registered in our system." self.assertEqual(expected_message, message)
def test_should_check_if_submission_by_unregistered_reporter(self): self.reporter_module.find_reporter_entity.side_effect = NumberNotRegisteredException( "1234") with self.assertRaises(NumberNotRegisteredException): self.sms_player.accept(self.request)