def get_next_asset_code(self, user_number): """ Get the next available asset code. :param int user_number: The user number for the asset code. :returns: The new asset code. """ maxno = -1 for p in map(assetcode.code_to_num, self.asset_codes): if p[0] == user_number: maxno = max(maxno, p[1]) return assetcode.num_to_code(user_number, maxno + 1)
def test_both_ways(self): uid = 10 pid = 20 num = assetcode.num_to_code(uid, pid) self.assertEqual(assetcode.code_to_num(num), (uid, pid))
def test_invalid_part(self): with self.assertRaises(ValueError): assetcode.num_to_code(10, -10)
def test_invalid_user(self): with self.assertRaises(ValueError): assetcode.num_to_code(-10, 10)