# coding: utf-8

"""
    OneRoster OpenAPI (JSON) Definition

    The OneRoster service binding is available in WSDL/XSD and REST/JSON. The model is based upon the IMS PSM modelling approach.  # noqa: E501

    OpenAPI spec version: 1.1
    Contact: lmattson@imsglobal.org
    Generated by: https://github.com/swagger-api/swagger-codegen.git
"""

from __future__ import absolute_import

import json
import unittest

from faker import Faker

from oneroster_client import ApiClient
from test.fake_response import FakeResponse

fake = Faker()


class TestEnrollmentType(unittest.TestCase):
    """EnrollmentType unit test stubs"""

    def setUp(self):
        pass

    def tearDown(self):
        pass

    def testEnrollmentType(self):
        """Test EnrollmentType"""
        # FIXME: construct object with mandatory attributes with example values
        # model = oneroster_client.models.enrollment_type.EnrollmentType()  # noqa: E501
        pass

    def test_it_deserializes_isprimary_string_to_bool_false(self):
        api_client = ApiClient()
        enrollment_str = """
        {
            "sourcedId": "6de51473-0347-4a90-ac1d-659ece1537db",
            "status": "active",
            "dateLastModified": "2021-06-22T22:10:04.476Z",
            "user": {
                "href": "https://api.platform.strongmind.com/ims/oneroster/v1p1/users/31741bb1-bd95-42d9-92f7-cdb9b3a57b96",
                "sourcedId": "31741bb1-bd95-42d9-92f7-cdb9b3a57b96",
                "type": "user"
            },
            "class": {
                "href": "https://api.platform.strongmind.com/ims/oneroster/v1p1/classes/f4018c6d-bd40-44eb-bf9d-6b53f786e40d",
                "sourcedId": "f4018c6d-bd40-44eb-bf9d-6b53f786e40d",
                "type": "class"
            },
            "school": {
                "href": "https://api.platform.strongmind.com/ims/oneroster/v1p1/orgs/698a321a-c237-4271-bdc4-de64efa650eb",
                "sourcedId": "698a321a-c237-4271-bdc4-de64efa650eb",
                "type": "org"
            },
            "role": "student",
            "primary": "false",
            "beginDate": "2020-08-03",
            "endDate": "2020-12-19"
        }
        """
        res = FakeResponse()
        res.data = enrollment_str
        enrollment = api_client.deserialize(res, "EnrollmentType")
        assert not enrollment.primary

    def test_it_deserializes_isprimary_string_to_bool_true(self):
        api_client = ApiClient()
        enrollment_str = """
        {
            "sourcedId": "6de51473-0347-4a90-ac1d-659ece1537db",
            "status": "active",
            "dateLastModified": "2021-06-22T22:10:04.476Z",
            "user": {
                "href": "https://api.platform.strongmind.com/ims/oneroster/v1p1/users/31741bb1-bd95-42d9-92f7-cdb9b3a57b96",
                "sourcedId": "31741bb1-bd95-42d9-92f7-cdb9b3a57b96",
                "type": "user"
            },
            "class": {
                "href": "https://api.platform.strongmind.com/ims/oneroster/v1p1/classes/f4018c6d-bd40-44eb-bf9d-6b53f786e40d",
                "sourcedId": "f4018c6d-bd40-44eb-bf9d-6b53f786e40d",
                "type": "class"
            },
            "school": {
                "href": "https://api.platform.strongmind.com/ims/oneroster/v1p1/orgs/698a321a-c237-4271-bdc4-de64efa650eb",
                "sourcedId": "698a321a-c237-4271-bdc4-de64efa650eb",
                "type": "org"
            },
            "role": "student",
            "primary": "true",
            "beginDate": "2020-08-03",
            "endDate": "2020-12-19"
        }
        """
        res = FakeResponse()
        res.data = enrollment_str
        enrollment = api_client.deserialize(res, "EnrollmentType")
        assert enrollment.primary

    def test_it_deserializes_raises_value_error_for_invalid_date(self):
        api_client = ApiClient()
        invalid_date = fake.sentence()
        enrollment_str = json.dumps({
            "sourcedId": "6de51473-0347-4a90-ac1d-659ece1537db",
            "status": "active",
            "dateLastModified": "2021-06-22T22:10:04.476Z",
            "user": {
                "href": "https://api.platform.strongmind.com/ims/oneroster/v1p1/users/31741bb1-bd95-42d9-92f7-cdb9b3a57b96",
                "sourcedId": "31741bb1-bd95-42d9-92f7-cdb9b3a57b96",
                "type": "user"
            },
            "class": {
                "href": "https://api.platform.strongmind.com/ims/oneroster/v1p1/classes/f4018c6d-bd40-44eb-bf9d-6b53f786e40d",
                "sourcedId": "f4018c6d-bd40-44eb-bf9d-6b53f786e40d",
                "type": "class"
            },
            "school": {
                "href": "https://api.platform.strongmind.com/ims/oneroster/v1p1/orgs/698a321a-c237-4271-bdc4-de64efa650eb",
                "sourcedId": "698a321a-c237-4271-bdc4-de64efa650eb",
                "type": "org"
            },
            "role": "student",
            "primary": "true",
            "beginDate": invalid_date,
            "endDate": "2020-12-19"
        })

        res = FakeResponse()
        res.data = enrollment_str

        with self.assertRaises(ValueError) as context:
            api_client.deserialize(res, "EnrollmentType")

        assert str(context.exception) == f"Failed to parse `{invalid_date}` as date object"


if __name__ == '__main__':
    unittest.main()
