"""This module contains the base test cases for the ``api`` app"""

import json

from mtp.apps.common.tests.test_cases import MTPTestCase


class BaseAPITestCase:
    """Base test case for testing api views"""

    def get_api_response(self, url, method, data):
        """Shortcut method to query the given url of the api

        Parameters
        ----------
        url: str
            The api url to query
        method: str, can be any http method
            The http method to use
        data: dict
            The data to send to the url, when using a "POST" method for example

        Returns
        -------
        tuple(int, dict):
            The response status code and the decoded response if applicable

        """

        response = getattr(self.client, method)(url, data)

        return response.status_code, json.loads(response.content.decode('utf-8'))


class APITestCase(MTPTestCase, BaseAPITestCase):
    """A test case based on ``BaseAPITestCase`` and ``MTPTestCase``.

    Should be used in most cases.

    """
