"""This module contains the base test cases for the SABA module"""

import requests
import requests_mock

from django.test import TestCase

from ..client import SabaApiClient


class BaseSabaApiClientTestCase(TestCase):
    """Base test case for the SABA api client"""

    SABA_API_URL = 'mock://saba_mocked_api'
    SABA_USERNAME = 'testusername'
    SABA_PASSWORD = 'testpassword'

    SABA_LOGIN_URL = SABA_API_URL + '/v1/login'
    SABA_USER_DETAILS_URL = SABA_API_URL + '/v1/people/username=%s:(%s)'
    SABA_ENROLLMENTS_SEARCH_URL = SABA_API_URL + '/v1/learning/enroll/search'
    SABA_ATTENDANCE_URL = SABA_API_URL + '/v1/attendance'
    SABA_ENROLLMENTS_STATUS = SABA_API_URL + '/v1/learning/enroll/%s/status'
    SABA_TRANSCRIPT_URL = SABA_API_URL + '/v1/transcript/'
    SABA_COURSE_ACTIVITY_URL = '/v1/courseactivity/'

    @classmethod
    def setUpClass(cls):
        """Set up the requests mock adapter"""

        super().setUpClass()

        session = requests.Session()
        cls.adapter = requests_mock.Adapter()

        with requests_mock.Mocker() as mock:
            mock.register_uri(
                'GET',
                cls.SABA_LOGIN_URL,
                json={
                    'certificate': 'mockedcertificate',
                    '@type': 'SabaCertificate'
                }
            )
            cls.mocked_saba_api_client = SabaApiClient(
                cls.SABA_API_URL,
                cls.SABA_USERNAME,
                cls.SABA_PASSWORD
            )

        session.mount('mock', cls.adapter)
        cls.mocked_saba_api_client._session = session


