def test_should_combine_sources_if_one_reporter_submits_data_from_different_channels(self):
        data_sender1 = DataSender("12313123123", "data_sender1", "rep1")
        data_sender2 = DataSender("*****@*****.**", "data_sender1", "rep1")
        data_sender3 = DataSender("14141241414", "data_sender3", "rep3")

        data_senders = DataSenderHelper(self.manager, None)._combine_channels([data_sender1, data_sender2, data_sender3])

        self.assertEqual(2, len(data_senders))
        self.assertIn(["12313123123", "*****@*****.**"], map(lambda x: x.source, data_senders))
 def combine_channels_for_tuple(self, data_senders_tuple_list):
     data_senders = [
         DataSender.from_tuple(data_sender_tuple)
         for data_sender_tuple in data_senders_tuple_list
     ]
     return map(lambda d: d.to_tuple(),
                self._combine_channels(data_senders))
    def _combine_channels(self, data_senders):
        keys = {x.name for x in data_senders}
        grouped_data_senders = [
            filter(lambda x: x.name == key, data_senders) for key in keys
        ]

        return sorted([
            DataSender(map(lambda x: x.source, a), a[0].name, a[0].reporter_id)
            for a in grouped_data_senders
        ],
                      key=lambda ds: ds.name)
    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)
    def _get_all_data_senders_with_submission(self, data_sender_list,
                                              submission_data_sender_info_list,
                                              filter_function):
        data_sender_info_list = filter(filter_function,
                                       submission_data_sender_info_list)
        source_to_data_sender_dict = {
            each.source: each
            for each in data_sender_list
        }

        return {
            source_to_data_sender_dict.get(
                data_sender_info[2],
                DataSender(data_sender_info[2], ugettext(NOT_AVAILABLE_DS),
                           None))
            for data_sender_info in data_sender_info_list
        }
Beispiel #6
0
 def list_data_sender(self, org_id):
     ngo_user_profiles = list(NGOUserProfile.objects.filter(org_id=org_id).all())
     return [DataSender(each.user.email, each.user.get_full_name(), each.reporter_id or "admin") for each in
             ngo_user_profiles]
    def _get_all_sms_data_senders(self):
        rows = self.manager.load_all_rows_in_view("datasender_by_mobile")

        return map(lambda x: DataSender(*x.key), rows)
Beispiel #8
0
 def test_should_data_sender_source_in_comma_seperated_format(self):
     self.assertEqual(('reporter', 'rep1', '123123,[email protected]'),
                      DataSender(['123123', '*****@*****.**'], 'reporter',
                                 'rep1').to_tuple())
Beispiel #9
0
 def test_should_return_TEST_data_sender_if_the_name_of_it_is_TEST(self):
     self.assertEqual(("TEST", "", "TEST"),
                      DataSender("", "TEST", "").to_tuple())