Ejemplo n.º 1
0
    def test_should_remove_submissions_whose_reporting_period_does_not_match_date_format(
            self):
        submission_logs_with_wrong_date_format = [
            Submission(self.dbm,
                       self.transport_info,
                       form_code='test',
                       values={
                           'q1': 'q1',
                           'q2': '12.25.2012',
                           'entity_question_code': '001'
                       }),
            Submission(self.dbm,
                       self.transport_info,
                       form_code='test',
                       values={
                           'q1': 'q1',
                           'q2': '12.2012',
                           'entity_question_code': '001'
                       })
        ]

        self.submissions.extend(submission_logs_with_wrong_date_format)
        filtered_submission_logs = ReportPeriodFilter(
            question_name='q2',
            period={
                'start': '01.05.2012',
                'end': '30.09.2012'
            }).filter(self.submissions)
        self.assertEqual(len(filtered_submission_logs), 3)
Ejemplo n.º 2
0
    def test_should_filter_for_other_reporting_date_format(self):
        submission_logs_with_wrong_date_format = [
            Submission(self.dbm,
                       self.transport_info,
                       form_code='test',
                       values={
                           'q1': 'q1',
                           'q2': '12.25.2012',
                           'entity_question_code': '001'
                       }),
            Submission(self.dbm,
                       self.transport_info,
                       form_code='test',
                       values={
                           'q1': 'q1',
                           'q2': '12.2012',
                           'entity_question_code': '001'
                       })
        ]

        self.submissions.extend(submission_logs_with_wrong_date_format)
        filtered_submission_logs = ReportPeriodFilter(
            question_name='q2',
            period={
                'start': '05.01.2012',
                'end': '12.30.2012'
            },
            date_format="mm.dd.yyyy").filter(self.submissions)
        self.assertEqual(len(filtered_submission_logs), 1)
Ejemplo n.º 3
0
    def test_should_return_submissions_filter_by_test_datasender(self):
        test_submission1 = Submission(self.dbm,
                                      transport_info=TransportInfo(
                                          'web', '127359085', 'destination'),
                                      form_code='test',
                                      values=self.values[1])
        test_submission1._doc.test = True

        test_submission2 = Submission(self.dbm,
                                      transport_info=TransportInfo(
                                          'web', TEST_REPORTER_MOBILE_NUMBER,
                                          'destination'),
                                      form_code='test',
                                      values=self.values[2])
        test_submission2._doc.test = False

        submission_logs = [
            Submission(self.dbm,
                       transport_info=TransportInfo('web',
                                                    '*****@*****.**',
                                                    'destination'),
                       form_code='test',
                       values=self.values[0]), test_submission1,
            test_submission2
        ]

        filtered_submissions = DataSenderFilter('TEST').filter(submission_logs)
        self.assertEqual(1, len(filtered_submissions))
        self.assertEqual(test_submission2.id, filtered_submissions[0].id)
Ejemplo n.º 4
0
    def test_should_return_submissions_filter_by_datasender(self):
        submission_logs = [
            Submission(self.dbm,
                       transport_info=TransportInfo('web',
                                                    '*****@*****.**',
                                                    'destination'),
                       form_code='test',
                       values=self.values[0]),
            Submission(self.dbm,
                       transport_info=TransportInfo('web', '127359085',
                                                    'destination'),
                       form_code='test',
                       values=self.values[1]),
            Submission(self.dbm,
                       transport_info=TransportInfo('web', '0000000000',
                                                    'destination'),
                       form_code='test',
                       values=self.values[2])
        ]

        filtered_submissions = DataSenderFilter(
            '*****@*****.**').filter(submission_logs)
        self.assertEqual(1, len(filtered_submissions))
Ejemplo n.º 5
0
    def setUp(self):
        self.dbm = Mock(spec=DatabaseManager)
        self.mock_form_model = Mock(spec=FormModel)
        self.mock_form_model.entity_question.code = '123'

        self.transport_info = TransportInfo('web', 'source', 'destination')
        self.values = [
            {
                'q1': 'q1',
                'q2': '30.07.2012',
                'entity_question_code': '001'
            },
            {
                'q1': 'q1',
                'q2': '30.08.2012',
                'entity_question_code': '005'
            },
            {
                'q1': 'q1',
                'q2': '30.08.2012',
                'entity_question_code': '002'
            },
        ]
        self.submissions = [
            Submission(self.dbm,
                       self.transport_info,
                       form_code='test',
                       values=self.values[0]),
            Submission(self.dbm,
                       transport_info=self.transport_info,
                       form_code='test',
                       values=self.values[1]),
            Submission(self.dbm,
                       transport_info=self.transport_info,
                       form_code='test',
                       values=self.values[2])
        ]
Ejemplo n.º 6
0
    def _prepare_analyzer_with_one_submission(self,
                                              form_model,
                                              values,
                                              is_for_submission_page=False):
        submission = Submission(self.manager,
                                transport_info=TransportInfo(
                                    'web', '*****@*****.**',
                                    'destination'),
                                form_code=form_model.form_code,
                                values=values)
        self.submission_id = submission.id

        return SubmissionAnalyzer(
            form_model,
            self.manager,
            self.org_id, [submission],
            is_for_submission_page=is_for_submission_page)
Ejemplo n.º 7
0
    def _prepare_analyzer(self,
                          form_model,
                          values_list,
                          keywords=None,
                          is_for_submission_page=False):
        submissions = []
        for values in values_list:
            submission = Submission(self.manager,
                                    transport_info=TransportInfo(
                                        'web', '*****@*****.**',
                                        'destination'),
                                    form_code=form_model.form_code,
                                    values=values)
            submissions.append(submission)

        return SubmissionAnalyzer(
            form_model,
            self.manager,
            self.org_id,
            submissions,
            keywords,
            is_for_submission_page=is_for_submission_page)
Ejemplo n.º 8
0
    def test_should_return_all_data_senders_that_have_submitted_data(self):
        FROM_NUMBER1 = '1234567890'
        FROM_NUMBER2 = '261332592634'
        FROM_NUMBER_NOT_EXIST = '434543545'
        TO_NUMBER = '919880734937'
        EMAIL = "*****@*****.**"
        EMAIL1 = "*****@*****.**"
        EMAIL2 = "*****@*****.**"
        EMAIL_NOT_EXIST = "[email protected]"

        Submission(self.manager, TransportInfo(SMS, FROM_NUMBER1, TO_NUMBER), FORM_CODE, []).save()
        Submission(self.manager, TransportInfo(SMS, FROM_NUMBER1, TO_NUMBER), FORM_CODE, []).save()
        Submission(self.manager, TransportInfo(SMS, FROM_NUMBER2, TO_NUMBER), FORM_CODE, []).save()
        Submission(self.manager, TransportInfo(SMS, FROM_NUMBER_NOT_EXIST, TO_NUMBER), FORM_CODE, []).save()
        Submission(self.manager, TransportInfo(WEB, EMAIL, "destination"), FORM_CODE, []).save()
        Submission(self.manager, TransportInfo(WEB, EMAIL, "destination"), FORM_CODE, []).save()
        Submission(self.manager, TransportInfo(SMART_PHONE, EMAIL, "destination"), FORM_CODE, []).save()
        Submission(self.manager, TransportInfo(WEB, EMAIL1, "destination"), FORM_CODE, []).save()
        Submission(self.manager, TransportInfo(SMART_PHONE, EMAIL2, "destination"), FORM_CODE, []).save()
        Submission(self.manager, TransportInfo(SMART_PHONE, EMAIL_NOT_EXIST, "destination"), FORM_CODE, []).save()
        Submission(self.manager, TransportInfo(SMS, TEST_REPORTER_MOBILE_NUMBER, TO_NUMBER), FORM_CODE, []).save()

        Submission(self.manager, TransportInfo(SMS, "4008123123", TO_NUMBER), "sent for other form_code which shouldn't be included in the result", []).save()

        data_sender_list = DataSenderHelper(self.manager, FORM_CODE).get_all_data_senders_ever_submitted(self.org_id)

        self.assertEqual(6, len(data_sender_list))

        self.assertIn(DataSender([FROM_NUMBER1], "Beany", "rep1"), data_sender_list)
        self.assertIn(DataSender([FROM_NUMBER2], "Qingshan", "rep2"), data_sender_list)
        self.assertIn(DataSender([EMAIL1], "Tester Pune", "admin"), data_sender_list)
        self.assertIn(DataSender([TEST_REPORTER_MOBILE_NUMBER], "TEST", "test"), data_sender_list)
        self.assertIn(DataSender(sorted([EMAIL_NOT_EXIST, FROM_NUMBER_NOT_EXIST, EMAIL]), ugettext(NOT_AVAILABLE_DS), None), data_sender_list)
        self.assertIn(DataSender([EMAIL2], "mamy rasamoel", "rep11"), data_sender_list)
Ejemplo n.º 9
0
    def test_should_return_data_sender_TESTER_when_send_from_TEST_REPORTER_MOBILE_NUMBER(self):
        submission = Submission(self.manager, TransportInfo("sms", TEST_REPORTER_MOBILE_NUMBER, "destination"))
        data_sender = DataSenderHelper(self.manager).get_data_sender(self.org_id, submission)

        self.assertEqual(('TEST', '', 'TEST'), data_sender)
Ejemplo n.º 10
0
    def test_should_return_N_A_when_the_data_sender_was_deleted_and_send_from_smart_phone(self):
        submission = Submission(self.manager, TransportInfo("smartPhone", "*****@*****.**", "destination"))
        data_sender = DataSenderHelper(self.manager).get_data_sender(self.org_id, submission)

        self.assertEqual((NOT_AVAILABLE_DS, None, '*****@*****.**'), data_sender)
Ejemplo n.º 11
0
    def test_should_return_data_sender_information_send_from_web(self):
        submission = Submission(self.manager, TransportInfo("web", "*****@*****.**", "destination"))
        data_sender = DataSenderHelper(self.manager).get_data_sender(self.org_id, submission)

        self.assertEqual(("Tester Pune", "admin", "*****@*****.**"), data_sender)
Ejemplo n.º 12
0
    def test_should_return_N_A_when_the_data_sender_was_deleted_and_send_from_sms(self):
        submission = Submission(self.manager, TransportInfo("sms", "123123", "destination"))
        data_sender = DataSenderHelper(self.manager).get_data_sender(self.org_id, submission)

        self.assertEqual((NOT_AVAILABLE_DS, None, '123123'), data_sender)