Exemplo n.º 1
0
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
Exemplo n.º 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'})
Exemplo n.º 3
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'}
         )
Exemplo n.º 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)
Exemplo n.º 5
0
 def test_date_no_change(self):
     self.assertEqual(adjust_datetimes({'date': '2015-04-03'}),
                      {'date': '2015-04-03'})
Exemplo n.º 6
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}
     )
Exemplo n.º 7
0
 def test_no_tz(self):
     self.assertEqual(
         adjust_datetimes({'datetime': '2013-03-09T06:30:09.007'}),
         {'datetime': '2013-03-09T06:30:09.007000Z'}
     )
Exemplo n.º 8
0
 def test_date_no_change(self):
     self.assertEqual(adjust_datetimes({'date': '2015-04-03'}),
                      {'date': '2015-04-03'})
Exemplo n.º 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})
Exemplo n.º 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'})