summaryrefslogtreecommitdiffstats
path: root/api/views.py
blob: 883091222730756e6b419dfb31e1764e5331a332 (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
import json
import logging

from flask import request
from flask_restful import Resource

from api.utils import common as common_utils
from api.actions import test as test_action
from api import conf

logger = logging.getLogger(__name__)


class Test(Resource):
    def post(self):
        action = common_utils.translate_to_str(request.json.get('action', ''))
        args = common_utils.translate_to_str(request.json.get('args', {}))
        logger.debug('Input args is: action: %s, args: %s', action, args)

        if action not in conf.TEST_ACTION:
            logger.error('Wrong action')
            result = {
                'status': 'error',
                'message': 'wrong action'
            }
            return json.dumps(result)

        method = getattr(test_action, action)
        return method(args)