예제 #1
0
 def test_create_comment(self):
     with self.app.test_request_context():
         usr = auth.auth_user('viewer', '1234')
         login_user(usr)
         c = items.create_comment('comment')
         self.assertEqual('viewer', c.get('user'))
         self.assertEqual('comment', c.get('message'))
         # don't test the date
         date = datetime.now()
         c = items.create_comment('comment', date)
         self.assertEqual({'user': '******', 'date': date, 'message': 'comment'}, c)
         logout_user()
예제 #2
0
 def test_check_status(self):
     with self.app.test_request_context():
         usr = auth.auth_user('admin', '1234')
         login_user(usr)
         items._check_status('TE0002a', '', 'tested')
         items._check_status('TE0002a', '', 'reserved')
         with self.assertRaises(ValueError):
             items._check_status('TE0002a', '', 'shipped')  # invalid transition
         with self.assertRaises(ValueError):
             items._check_status('TE0002a', '', 'somestatus')  # unknown status
         items._check_status('TE0002a', 'reserved', 'shipped')  # now a valid transition
         logout_user()
         usr = auth.auth_user('viewer', '1234')
         login_user(usr)
         with self.assertRaises(ValueError):
             items._check_status('TE0002a', '', 'tested')  # requires item_admin
         logout_user()
         usr = auth.auth_user('admin', '1234')
         login_user(usr)
         with self.assertRaises(ValueError):
             items._check_status('TE0001a', '', 'tested')  # unknown status for this part number
         items._check_status('TE0001a', '', 'obsolete')
         logout_user()
예제 #3
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)
예제 #4
0
 def test_store_items(self):
     with self.app.test_request_context():
         usr = auth.auth_user('viewer', '1234')
         login_user(usr)
         importdata = [
             {
                 'serial': 'LPM0001',
                 'partno': 'TE0002a',
                 'project': 'some project',
                 'status': 'shipped',
                 'param1': 'some param',
                 'batch': 'b1'
             },
             {
                 'serial': 'LPM0002',
                 'partno': 'TE0001b',
                 'param2': 'testdata',
                 'comment': 'my comment'
             },
             {
                 'serial': 'LPM0003',
                 'partno': 'TE0002a',
                 'batch': 'b1'
             },
         ]
         items._store_items(importdata)
         obj = self.app.mongo.db.items.find_one('LPM0001')
         self.assertIsNotNone(obj)
         self.assertEqual('TE0002a', obj.get('partno'))
         self.assertEqual('some project', obj.get('project'))
         self.assertEqual('shipped', obj.get('status'))
         self.assertFalse(obj.get('available'))
         self.assertEqual('b1', obj.get('batch'))
         self.assertEqual('some param', obj.get('param1'))
         comments = obj.get('comments', list())
         self.assertEqual(1, len(comments))
         comment = comments[0]
         self.assertEqual('viewer', comment.get('user'))
         self.assertEqual('[Auto] created', comment.get('message'))
         obj = self.app.mongo.db.items.find_one('LPM0002')
         self.assertIsNotNone(obj)
         self.assertEqual('TE0001b', obj.get('partno'))
         self.assertEqual('', obj.get('project'))
         self.assertEqual('', obj.get('status'))
         self.assertTrue(obj.get('available'))
         self.assertEqual('testdata', obj.get('param2'))
         comments = obj.get('comments', list())
         self.assertEqual(2, len(comments))
         comment = comments[0]
         self.assertEqual('viewer', comment.get('user'))
         self.assertEqual('[Auto] created', comment.get('message'))
         comment = comments[1]
         self.assertEqual('viewer', comment.get('user'))
         self.assertEqual('my comment', comment.get('message'))
         obj = self.app.mongo.db.items.find_one('LPM0003')
         self.assertIsNotNone(obj)
         self.assertEqual('TE0002a', obj.get('partno'))
         self.assertEqual('b1', obj.get('batch'))
         self.assertTrue(obj.get('available'))
         comments = obj.get('comments', list())
         self.assertEqual(1, len(comments))
         comment = comments[0]
         self.assertEqual('viewer', comment.get('user'))
         self.assertEqual('[Auto] created', comment.get('message'))
         # also test that the stock is correctly updated
         obj = self.app.mongo.db.stock.find_one('TE0001')
         self.assertIsNotNone(obj)
         self.assertEqual(97, obj.get('quantity'))  # 100 - 4 + 1
         obj = self.app.mongo.db.stock.find_one('TE0002')
         self.assertIsNotNone(obj)
         self.assertEqual(37, obj.get('quantity'))
         obj = self.app.mongo.db.stock_batches.find_one({'partno': 'TE0002', 'name': 'b1'})
         self.assertIsNotNone(obj)
         self.assertEqual(2, obj.get('quantity'))
         entries = self.app.mongo.db.stock_history.find({'partno': 'TE0002'}).count()
         self.assertEqual(1, entries)  # one entry for the insertion
         entries = self.app.mongo.db.stock_history.find({'partno': 'TE0001'}).count()
         self.assertEqual(2, entries)  # one entry for the insertion, one for the stock removal
         logout_user()