Пример #1
0
def get_submissions(dbm, form_code):
    rows = dbm.load_all_rows_in_view('submissionlog', reduce=False, descending=True, startkey=[form_code, {}],
                                         endkey=[form_code], limit=7)

    submission_list = []
    submission_success = 0
    submission_errors = 0
    if rows is not None:
        for row in rows:
            phone_number = row.value["source"]
            if phone_number <> 'xls':
                reporter = find_reporter(dbm, row.value["source"])
                reporter = reporter[0].get("name")
                if row.value["status"]:
                    message = " ".join(["%s: %s" % (k, v) for k, v in row.value["values"].items()])
                else:
                    message = row.value["error_message"]
                submission = dict(message=message, created=row.value["submitted_on"], reporter=reporter,
                                  status=row.value["status"])
                submission_list.append(submission)

        rows = dbm.load_all_rows_in_view('submissionlog', startkey=[form_code], endkey=[form_code, {}],
                                         group=True, group_level=1, reduce=True)
        for row in rows:
            submission_success = row["value"]["success"]
            submission_errors = row["value"]["count"] - row["value"]["success"]

    return submission_list, submission_success, submission_errors
Пример #2
0
 def test_should_not_raise_exception_if_multiple_reporters_for_a_number(
         self):
     reporter_list = find_reporter(self.manager, "1234567890")
     self.assertEqual(2, len(reporter_list))
     self.assertTrue({
         NAME_FIELD: "A",
         MOBILE_NUMBER_FIELD: "1234567890"
     } in reporter_list)
     self.assertTrue({
         NAME_FIELD: "B",
         MOBILE_NUMBER_FIELD: "1234567890"
     } in reporter_list)
Пример #3
0
def get_submissions(dbm, form_code):
    rows = dbm.load_all_rows_in_view('submissionlog',
                                     reduce=False,
                                     descending=True,
                                     startkey=[form_code, {}],
                                     endkey=[form_code],
                                     limit=7)

    submission_list = []
    submission_success = 0
    submission_errors = 0
    if rows is not None:
        for row in rows:
            phone_number = row.value["source"]
            if phone_number <> 'xls':
                reporter = find_reporter(dbm, row.value["source"])
                reporter = reporter[0].get("name")
                if row.value["status"]:
                    message = " ".join([
                        "%s: %s" % (k, v)
                        for k, v in row.value["values"].items()
                    ])
                else:
                    message = row.value["error_message"]
                submission = dict(message=message,
                                  created=row.value["submitted_on"],
                                  reporter=reporter,
                                  status=row.value["status"])
                submission_list.append(submission)

        rows = dbm.load_all_rows_in_view('submissionlog',
                                         startkey=[form_code],
                                         endkey=[form_code, {}],
                                         group=True,
                                         group_level=1,
                                         reduce=True)
        for row in rows:
            submission_success = row["value"]["success"]
            submission_errors = row["value"]["count"] - row["value"]["success"]

    return submission_list, submission_success, submission_errors
Пример #4
0
 def test_should_not_raise_exception_if_multiple_reporters_for_a_number(self):
     reporter_list = find_reporter(self.manager, "1234567890")
     self.assertEqual(2, len(reporter_list))
     self.assertTrue({NAME_FIELD: "A", MOBILE_NUMBER_FIELD: "1234567890"} in reporter_list)
     self.assertTrue({NAME_FIELD: "B", MOBILE_NUMBER_FIELD: "1234567890"} in reporter_list)
Пример #5
0
 def test_should_raise_exception_if_no_reporter_for_tel_number(self):
     with self.assertRaises(NumberNotRegisteredException):
         find_reporter(self.manager, "X")
Пример #6
0
 def test_should_load_reporter_list_given_tel_number(self):
     saved_r2 = find_reporter(self.manager, "8888567890")
     self.assertIsNotNone(saved_r2)
     self.assertEqual(1, len(saved_r2))
     self.assertEquals(saved_r2[0]["name"], "B")
     self.assertEquals(saved_r2[0]["mobile_number"], "8888567890")
Пример #7
0
 def test_should_raise_exception_if_no_reporter_for_tel_number(self):
     with self.assertRaises(NumberNotRegisteredException):
         find_reporter(self.manager, "X")
Пример #8
0
 def test_should_load_reporter_list_given_tel_number(self):
     saved_r2 = find_reporter(self.manager, "8888567890")
     self.assertIsNotNone(saved_r2)
     self.assertEqual(1, len(saved_r2))
     self.assertEquals(saved_r2[0]["name"], "B")
     self.assertEquals(saved_r2[0]["mobile_number"], "8888567890")