-
  In order to test the basic EDI system, I will export a partner,
  modify the exported EDI document to add an attachment and change
  the data, and then re-import it and re-export it.
  
  with an attached file, check the result, the alter the data
  and reimport it.
-
  !python {model: edi.edi}: |
      import simplejson as json
      res_partner = self.pool.get('res.partner')
      doc = self.generate_edi(cr, uid, [res_partner.browse(cr, uid, ref('base.res_partner_2'))])
      edi_doc, = json.loads(doc)

      # check content of the document
      assert edi_doc.get('__id').endswith('.res_partner_2'), 'Incorrect external ID'
      assert edi_doc.get('__model') == 'res.partner', 'Incorrect/Missing __model'
      assert edi_doc.get('__module') == 'base', 'Incorrect/Missing __module'
      assert edi_doc.get('__last_update'), 'Missing __last_update'

      # try to import the document after changing the name and id, and attaching a
      # file, and check that a new partner is returned
      edi_doc['__id'] = 'base:xxd37f8a-xx55-11e0-xxdd-xx81124c8b50.res_partner_xxx'
      edi_doc['name'] = 'AgroMilk'
      attachment = {
        'name': 'Test file',
        'file_name': 'test.png',
        # base64 standard requires blocks of 57bytes=76chars, NL-separated
        'content': 'iVBORw0KGgoAAAANSUhEUgAAAA4AAAAKCAYAAACE2W/HAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A\n/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9oIDQ84BkjLWAYAAACNSURBVCjP\njZKxDUJBDEOf/wbUbEHDhkxAzRjUDECBhMQYjIApuPBNpK+PpUinOPYll5Nt1iCJXifbSPpJZtHg\nXLUdu0FWpMEt87a/xtsmqjjNetPFyhuWYFuj7RcgQBNwXNGdw2CqY85yXWi5z7YBnmRyEHvg0YSX\nrLE9P30nwugOHHr+s5va4x+fofAGm1+JjnJICm0AAAAASUVORK5CYII=\n',
      }
      edi_doc['__attachments'] = [attachment]
      doc = json.dumps([edi_doc])
      result, = self.import_edi(cr, uid, edi_document=doc)
      assert result[0] == 'res.partner' and result[1] > ref('base.res_partner_2'),\
         "Expected (%r,> %r) after import 1, got %r" % ('res.partner', ref('base.res_partner_2'), result)

      # export the same partner we just created, and see if the output matches the input
      doc_output = self.generate_edi(cr, uid, [res_partner.browse(cr, uid, result[1])])
      edi_doc_output, = json.loads(doc_output)
      for attribute in ('__model', '__module', '__id', 'name', '__attachments'):
        assert edi_doc_output.get(attribute) == edi_doc.get(attribute), \
            'Incorrect value for %s, expected %r, got %r' % (attribute, edi_doc.get(attribute), edi_doc_output.get(attribute))
