3 # Copyright (c) 2016 Orange and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
12 import functest.utils.functest_logger as ft_logger
13 import functest.utils.functest_utils as ft_utils
16 class TestCase(object):
19 EX_RUN_ERROR = os.EX_SOFTWARE
20 EX_PUSH_TO_DB_ERROR = os.EX_SOFTWARE - 1
21 EX_TESTCASE_FAILED = os.EX_SOFTWARE - 2
23 logger = ft_logger.Logger(__name__).getLogger()
27 self.project_name = "functest"
33 def check_criteria(self):
36 if self.criteria == 'PASS':
38 except AssertionError:
39 self.logger.error("Please run test before checking the results")
40 return TestCase.EX_TESTCASE_FAILED
42 def run(self, **kwargs):
43 # pylint: disable=unused-argument
44 self.logger.error("Run must be implemented")
45 return TestCase.EX_RUN_ERROR
49 assert self.project_name
52 assert self.start_time
54 if ft_utils.push_results_to_db(
55 self.project_name, self.case_name, self.start_time,
56 self.stop_time, self.criteria, self.details):
57 self.logger.info("The results were successfully pushed to DB")
60 self.logger.error("The results cannot be pushed to DB")
61 return TestCase.EX_PUSH_TO_DB_ERROR
62 except Exception: # pylint: disable=broad-except
63 self.logger.exception("The results cannot be pushed to DB")
64 return TestCase.EX_PUSH_TO_DB_ERROR