Ejemplo n.º 1
0
 def test_do_import_file(self):
     with self.app.test_request_context():
         success, headers, data = items._import_file('testsuite/files/items_add.xlsx')
         self.assertTrue(success)
         refhdr = ['serial', 'partno', 'batch', 'param1', 'param2', 'param3', 'param5',
                   'param4', 'param6', 'param7', 'param8', 'comment']
         self.assertEqual(refhdr, headers)
         self.assertEqual(4, len(data))
         d = data[0]
         refd = dict(
                 serial='LPM0001',
                 partno='TE0001a',
                 batch='b1',
                 param5=datetime(2016, 1, 31, 15, 38, 4),
                 param6=3,
                 param7=4.6,
                 param8=True,
         )
         self.assertEqual(refd, d)
         d = data[1]
         refd = dict(
                 serial='LPM0002',
                 partno='TE0001b',
                 batch='b1',
                 param2='7',
                 param5='2016-02-01 15:38:50',  # not defined as a date field
                 param6='4',
                 param7='4.3',
                 param8='False',
         )
         self.assertEqual(refd, d)
         d = data[2]
         refd = dict(
                 serial='LPM0003',
                 partno='TE0001a',
                 batch='b1',
                 param5=datetime(2016, 2, 2, 15, 38, 9),
                 param6=5,
                 param7=2.0,
                 param8=False,
                 comment='some comment here',
         )
         self.assertEqual(refd, d)
         d = data[3]
         refd = dict(
                 serial='LPM0004',
                 partno='TE0002a',
                 batch='b2',
                 param1='a',
                 param2=5,
                 param3='7',
                 param5='n',
                 param4='d',
                 param8='text',
         )
         self.assertEqual(refd, d)
Ejemplo n.º 2
0
 def test_bad_import(self):
     with self.app.test_request_context():
         usr = auth.auth_user('viewer', '1234')
         login_user(usr)
         success, headers, data = items._import_file('testsuite/files/badimport.xlsx')
         self.assertFalse(success)
         msg = get_flashed_messages()
         refmsg=[
             "field 'param5' must be a datetime object (row 2)",
             "serial number 'LP0001' exists already (row 3)",
             "required field 'param5' is missing (row 4)",
             'unknown part number TE0012 (row 5)',
             'part number requires a revision (row 6)'
         ]
         self.assertEqual(refmsg, msg)