from django.http import JsonResponse


class ApiBase(object):

    STATUS_ERROR = 0
    STATUS_SUCCESS = 1
    STATUS_WARNING = 2

    def json_response(self, data=None, status=STATUS_SUCCESS, message=None):

        status_code = 400 if status == ApiBase.STATUS_ERROR else 200

        return JsonResponse({
            "data": data,
            "status": status,
            "message": message
        }, status=status_code)

from django.http import JsonResponse


class ApiBase(object):
    @classmethod
    def success(cls, data, status=200):
        """
        :type data: dict
        :type status: int
        :rtype JsonResponse

        """
        return JsonResponse(data, status=status)

    @classmethod
    def error(cls, error, status=400):
        """
        :type error: str
        :type status: int
        :rtype JsonResponse

        """
        return JsonResponse({'error': error}, status=status)

Refactor json_response to more BDD methods
Refactor json_response to more BDD methods

  from django.http import JsonResponse
  
  
  class ApiBase(object):
+     @classmethod
+     def success(cls, data, status=200):
+         """
+         :type data: dict
+         :type status: int
+         :rtype JsonResponse
  
+         """
+         return JsonResponse(data, status=status)
-     STATUS_ERROR = 0
-     STATUS_SUCCESS = 1
-     STATUS_WARNING = 2
  
-     def json_response(self, data=None, status=STATUS_SUCCESS, message=None):
+     @classmethod
+     def error(cls, error, status=400):
+         """
+         :type error: str
+         :type status: int
+         :rtype JsonResponse
  
-         status_code = 400 if status == ApiBase.STATUS_ERROR else 200
+         """
+         return JsonResponse({'error': error}, status=status)
  
-         return JsonResponse({
-             "data": data,
-             "status": status,
-             "message": message
-         }, status=status_code)
- 
Refactor json_response to more BDD methods
## Code Before:
from django.http import JsonResponse


class ApiBase(object):

    STATUS_ERROR = 0
    STATUS_SUCCESS = 1
    STATUS_WARNING = 2

    def json_response(self, data=None, status=STATUS_SUCCESS, message=None):

        status_code = 400 if status == ApiBase.STATUS_ERROR else 200

        return JsonResponse({
            "data": data,
            "status": status,
            "message": message
        }, status=status_code)

## Instruction:
Refactor json_response to more BDD methods
## Code After:
from django.http import JsonResponse


class ApiBase(object):
    @classmethod
    def success(cls, data, status=200):
        """
        :type data: dict
        :type status: int
        :rtype JsonResponse

        """
        return JsonResponse(data, status=status)

    @classmethod
    def error(cls, error, status=400):
        """
        :type error: str
        :type status: int
        :rtype JsonResponse

        """
        return JsonResponse({'error': error}, status=status)
