# coding: utf-8

"""
    OneLogin API

    OpenAPI Specification for OneLogin  # noqa: E501

    The version of the OpenAPI document: 3.1.1
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""


import unittest
import datetime

import onelogin
from onelogin.models.user import User  # noqa: E501
from onelogin.rest import ApiException


class TestUserManagerUserIdFix(unittest.TestCase):
    """Test case for manager_user_id field fix (GitHub issue #100)"""

    def setUp(self):
        pass

    def tearDown(self):
        pass

    def test_manager_user_id_with_string_value(self):
        """
        Test that manager_user_id accepts string values from API response.
        This test validates the fix for GitHub issue #100 where API returns
        manager_user_id as string but model expected integer.
        """
        user_data = {
            "id": 123,
            "username": "testuser",
            "email": "test@example.com",
            "manager_user_id": "252462756"  # String value as returned by API
        }
        
        # This should work without validation errors
        user = User.from_dict(user_data)
        self.assertEqual(user.manager_user_id, "252462756")
        self.assertIsInstance(user.manager_user_id, str)

    def test_manager_user_id_with_integer_value(self):
        """
        Test that manager_user_id accepts integer values and converts them to string.
        This test validates the fix where API sometimes returns manager_user_id as integer.
        """
        user_data = {
            "id": 123,
            "username": "testuser",
            "email": "test@example.com",
            "manager_user_id": 252462756  # Integer value as sometimes returned by API
        }
        
        # This should work without validation errors and convert to string
        user = User.from_dict(user_data)
        self.assertEqual(user.manager_user_id, "252462756")
        self.assertIsInstance(user.manager_user_id, str)

    def test_manager_user_id_with_none_value(self):
        """
        Test that manager_user_id accepts None values.
        """
        user_data = {
            "id": 123, 
            "username": "testuser",
            "email": "test@example.com",
            "manager_user_id": None
        }
        
        user = User.from_dict(user_data)
        self.assertIsNone(user.manager_user_id)

    def test_manager_user_id_missing_field(self):
        """
        Test that manager_user_id can be omitted (defaults to None).
        """
        user_data = {
            "id": 123,
            "username": "testuser", 
            "email": "test@example.com"
            # manager_user_id field is omitted
        }
        
        user = User.from_dict(user_data)
        self.assertIsNone(user.manager_user_id)

    def test_user_serialization_with_manager_user_id(self):
        """
        Test that User can be serialized back to dict with manager_user_id.
        """
        user_data = {
            "id": 123,
            "username": "testuser",
            "email": "test@example.com", 
            "manager_user_id": "252462756"
        }
        
        user = User.from_dict(user_data)
        user_dict = user.to_dict()
        
        self.assertEqual(user_dict["manager_user_id"], "252462756")
        self.assertIsInstance(user_dict["manager_user_id"], str)

    def test_parse_obj_compatibility(self):
        """
        Test that parse_obj method (used in API deserialization) works correctly.
        This specifically tests the flow mentioned in the original issue traceback.
        """
        user_data = {
            "id": 123,
            "username": "testuser",
            "email": "test@example.com", 
            "manager_user_id": "252462756"
        }
        
        # This is the method called in the traceback from the original issue
        user = User.parse_obj(user_data)
        self.assertEqual(user.manager_user_id, "252462756")
        self.assertIsInstance(user.manager_user_id, str)


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