[IMP] css
[odoo/odoo.git] / addons / edi / test / edi_partner_test.yml
1 -
2   In order to test the basic EDI system, I will export a partner,
3   modify the exported EDI document to add an attachment and change
4   the data, and then re-import it and re-export it.
5   
6   with an attached file, check the result, the alter the data
7   and reimport it.
8 -
9   !python {model: edi.edi}: |
10       import json
11       res_partner = self.pool.get('res.partner')
12       doc = self.generate_edi(cr, uid, [res_partner.browse(cr, uid, ref('base.res_partner_2'))])
13       edi_doc, = json.loads(doc)
14
15       # check content of the document
16       assert edi_doc.get('__id').endswith('.res_partner_2'), 'Incorrect external ID'
17       assert edi_doc.get('__model') == 'res.partner', 'Incorrect/Missing __model'
18       assert edi_doc.get('__module') == 'base', 'Incorrect/Missing __module'
19       assert edi_doc.get('__last_update'), 'Missing __last_update'
20
21       # try to import the document after changing the name and id, and attaching a
22       # file, and check that a new partner is returned
23       edi_doc['__id'] = 'base:xxd37f8a-xx55-11e0-xxdd-xx81124c8b50.res_partner_xxx'
24       edi_doc['name'] = 'AgroMilk'
25       attachment = {
26         'name': 'Test file',
27         'file_name': 'test.png',
28         # base64 standard requires blocks of 57bytes=76chars, NL-separated
29         'content': 'iVBORw0KGgoAAAANSUhEUgAAAA4AAAAKCAYAAACE2W/HAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A\n/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9oIDQ84BkjLWAYAAACNSURBVCjP\njZKxDUJBDEOf/wbUbEHDhkxAzRjUDECBhMQYjIApuPBNpK+PpUinOPYll5Nt1iCJXifbSPpJZtHg\nXLUdu0FWpMEt87a/xtsmqjjNetPFyhuWYFuj7RcgQBNwXNGdw2CqY85yXWi5z7YBnmRyEHvg0YSX\nrLE9P30nwugOHHr+s5va4x+fofAGm1+JjnJICm0AAAAASUVORK5CYII=\n',
30       }
31       edi_doc['__attachments'] = [attachment]
32       doc = json.dumps([edi_doc])
33       result, = self.import_edi(cr, uid, edi_document=doc)
34       assert result[0] == 'res.partner' and result[1] > ref('base.res_partner_2'),\
35          "Expected (%r,> %r) after import 1, got %r" % ('res.partner', ref('base.res_partner_2'), result)
36
37       # export the same partner we just created, and see if the output matches the input
38       doc_output = self.generate_edi(cr, uid, [res_partner.browse(cr, uid, result[1])])
39       edi_doc_output, = json.loads(doc_output)
40       for attribute in ('__model', '__module', '__id', 'name', '__attachments'):
41         assert edi_doc_output.get(attribute) == edi_doc.get(attribute), \
42             'Incorrect value for %s, expected %r, got %r' % (attribute, edi_doc.get(attribute), edi_doc_output.get(attribute))