def _get_new_form_json(xml, xform_id):
    form_json = convert_xform_to_json(xml)
    with force_phone_timezones_should_be_processed():
        adjust_datetimes(form_json)
    # this is actually in-place because of how jsonobject works
    scrub_meta(XFormInstance.wrap({'form': form_json, '_id': xform_id}))
    return form_json
Beispiel #2
0
 def test_strip_tz(self):
     if phone_timezones_should_be_processed():
         self.assertEqual(
             adjust_datetimes({'datetime': '2013-03-09T06:30:09.007+03'}),
             {'datetime': '2013-03-09T03:30:09.007000Z'})
     else:
         self.assertEqual(
             adjust_datetimes({'datetime': '2013-03-09T06:30:09.007+03'}),
             {'datetime': '2013-03-09T06:30:09.007000Z'})
 def test_strip_tz(self):
     if phone_timezones_should_be_processed():
         self.assertEqual(
             adjust_datetimes({'datetime': '2013-03-09T06:30:09.007+03'}),
             {'datetime': '2013-03-09T03:30:09.007000Z'}
         )
     else:
         self.assertEqual(
             adjust_datetimes({'datetime': '2013-03-09T06:30:09.007+03'}),
             {'datetime': '2013-03-09T06:30:09.007000Z'}
         )
Beispiel #4
0
def unpack_commtrack(xform):
    form_xml = xform.get_xml_element()
    commtrack_node_names = ('{%s}balance' % COMMTRACK_REPORT_XMLNS,
                            '{%s}transfer' % COMMTRACK_REPORT_XMLNS)

    def commtrack_nodes(node):
        for child in node:
            if child.tag in commtrack_node_names:
                yield child
            else:
                for e in commtrack_nodes(child):
                    yield e

    for elem in commtrack_nodes(form_xml):
        report_type, ledger_json = convert_xml_to_json(
            elem, last_xmlns=COMMTRACK_REPORT_XMLNS)

        # apply the same datetime & string conversions
        # that would be applied to XFormInstance.form
        adjust_datetimes(ledger_json)
        ledger_json = XFormInstance({'form': ledger_json}).form

        yield ledger_json_to_stock_report_helper(
            xform, report_type, ledger_json)
 def test_date_no_change(self):
     self.assertEqual(adjust_datetimes({'date': '2015-04-03'}),
                      {'date': '2015-04-03'})
 def test_match_no_parse(self):
     fake_datetime = '2015-07-14 2015-06-07 '
     self.assertEqual(
         adjust_datetimes({'fake_datetime': fake_datetime}),
         {'fake_datetime': fake_datetime}
     )
 def test_no_tz(self):
     self.assertEqual(
         adjust_datetimes({'datetime': '2013-03-09T06:30:09.007'}),
         {'datetime': '2013-03-09T06:30:09.007000Z'}
     )
Beispiel #8
0
 def test_date_no_change(self):
     self.assertEqual(adjust_datetimes({'date': '2015-04-03'}),
                      {'date': '2015-04-03'})
Beispiel #9
0
 def test_match_no_parse(self):
     fake_datetime = '2015-07-14 2015-06-07 '
     self.assertEqual(adjust_datetimes({'fake_datetime': fake_datetime}),
                      {'fake_datetime': fake_datetime})
Beispiel #10
0
 def test_no_tz(self):
     self.assertEqual(
         adjust_datetimes({'datetime': '2013-03-09T06:30:09.007'}),
         {'datetime': '2013-03-09T06:30:09.007000Z'})