aboutsummaryrefslogtreecommitdiffstats
path: root/api/resources/v2/testcases.py
blob: 3277b4c43f7a07e9c57937d61561c3a9f3a5f2fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import logging
import os

from api import ApiResource
from yardstick.common.utils import result_handler
from yardstick.common import constants as consts
from yardstick.benchmark.core import Param
from yardstick.benchmark.core.testcase import Testcase

LOG = logging.getLogger(__name__)
LOG.setLevel(logging.DEBUG)


class V2Testcases(ApiResource):

    def get(self):
        param = Param({})
        testcase_list = Testcase().list_all(param)
        return result_handler(consts.API_SUCCESS, testcase_list)

    def post(self):
        return self._dispatch_post()

    def upload_case(self, args):
        try:
            upload_file = args['file']
        except KeyError:
            return result_handler(consts.API_ERROR, 'file must be provided')

        case_name = os.path.join(consts.TESTCASE_DIR, upload_file.filename)

        LOG.info('save case file')
        upload_file.save(case_name)

        return result_handler(consts.API_SUCCESS, {'testcase': upload_file.filename})