Esempio n. 1
0
    def test_should_parse_datasenders_with_all_fields(self):
        imported_datasenders = [{
            "l": ["loc1", "loc2"],
            "s": "reporter_id",
            "n": "reporter_name",
            "g": [1.11, 2.22],
            "m": "12334534",
            "email": "*****@*****.**"
        }, {
            "l": ["loc11", "loc22"],
            "s": "reporter_id2",
            "n": "reporter_name2",
            "g": [1.11, 2.22],
            "m": "123345341",
            "email": "*****@*****.**"
        }]
        parsed_datasenders = _parse_successful_imports(imported_datasenders)

        self.assertEqual(len(parsed_datasenders), 2)
        first_datasender = parsed_datasenders[0]
        self.assertEqual(first_datasender["name"], "reporter_name")
        self.assertEqual(first_datasender["location"], "loc1,loc2")
        self.assertEqual(first_datasender["id"], "reporter_id")
        self.assertEqual(first_datasender["email"], "*****@*****.**")
        self.assertEqual(first_datasender["mobile_number"], "12334534")
        self.assertEqual(first_datasender["coordinates"], "1.11,2.22")

        second_datasender = parsed_datasenders[1]
        self.assertEqual(second_datasender["name"], "reporter_name2")
        self.assertEqual(second_datasender["location"], "loc11,loc22")
        self.assertEqual(second_datasender["id"], "reporter_id2")
        self.assertEqual(second_datasender["email"], "*****@*****.**")
        self.assertEqual(second_datasender["mobile_number"], "123345341")
        self.assertEqual(second_datasender["coordinates"], "1.11,2.22")
Esempio n. 2
0
    def test_should_parse_datasenders_with_no_location_field(self):
        imported_datasenders = [{
            "s": "reporter_id",
            "n": "reporter_name",
            "g": [1.11, 2.22],
            "m": "12334534",
            "email": "*****@*****.**"
        }]
        parsed_datasenders = _parse_successful_imports(imported_datasenders)

        self.assertEqual(len(parsed_datasenders), 1)
        first_datasender = parsed_datasenders[0]
        self.assertEqual(first_datasender["name"], "reporter_name")
        self.assertEqual(first_datasender["location"], "")
        self.assertEqual(first_datasender["id"], "reporter_id")
        self.assertEqual(first_datasender["email"], "*****@*****.**")
        self.assertEqual(first_datasender["mobile_number"], "12334534")
        self.assertEqual(first_datasender["coordinates"], "1.11,2.22")
 def post(self, request, *args, **kwargs):
     manager = get_database_manager(request.user)
     error_message, failure_imports, success_message, imported_datasenders, successful_imports = import_module.import_data(
         request,
         manager,
         default_parser=XlsDatasenderParser)
     imported_data_senders = _parse_successful_imports(successful_imports)
     imported_datasenders_ids = [imported_data_sender["id"] for imported_data_sender in imported_data_senders]
     if len(imported_datasenders_ids):
         UserActivityLog().log(request, action=IMPORTED_DATA_SENDERS,
                               detail=json.dumps(
                                   dict({"Unique ID": "[%s]" % ", ".join(imported_datasenders_ids)})))
     org_id = request.user.get_profile().org_id
     _add_imported_datasenders_to_trail_account(imported_data_senders, org_id)
     return HttpResponse(json.dumps(
         {
             'success': error_message is None and is_empty(failure_imports),
             'message': success_message,
             'error_message': error_message,
             'failure_imports': failure_imports,
             'successful_imports': imported_data_senders
         }))