"""
test_requests.py
====================================
Unit testing for requests module
"""

import unittest
from imath_requests.requests import PartData, ImageAnalysisData, ImageAnalysisFailure
from imath_requests.requests import ImageValue, ImageMetaData


class TestRequestsPartData(unittest.TestCase):
    """
    Unit testing for PartData class in requests module.

    """
    def test_init_part_data(self):
        """
        Test generation of part data class
        """
        part_data_list = [
            {
                "key": "steel_grade",
                "value": "Grade01"
            },
            {
                "key": "heat_number",
                "value": "C1234566"
            },
            {
                "key": "rolling_schedule",
                "value": "Schedule1"
            },
            {
                "key": "analysis",
                "value": [
                    {
                        "key": "C",
                        "value": "0.2"
                    },
                    {
                        "key": "Mn",
                        "value": "0.02"
                    }
                ]
            }
        ]
        part_data = PartData(
            "1516193959559", "Part1234", "I3DR_DESKTOP_ABC123", part_data_list)

    def test_part_data_json(self):
        """
        Tests part data json generation.

        """
        part_data_list = [
            {
                "key": "steel_grade",
                "value": "Grade01"
            },
            {
                "key": "heat_number",
                "value": "C1234566"
            },
            {
                "key": "rolling_schedule",
                "value": "Schedule1"
            },
            {
                "key": "analysis",
                "value": [
                    {
                        "key": "C",
                        "value": "0.2"
                    },
                    {
                        "key": "Mn",
                        "value": "0.02"
                    }
                ]
            }
        ]
        part_data = PartData(
            "1516193959559", "Part1234", "I3DR_DESKTOP_ABC123", part_data_list)
        # TODO add part data json generation test


class TestRequestsImageValue(unittest.TestCase):
    """
    Unit testing for ImageValue class in requests module.

    """
    def test_init_image_value(self):
        """
        Test generation of image value class
        """
        image_value = ImageValue(
            "test001.png", "1516193959559", "(44.2,17.4)",
            "(5.2,1)", "1"
        )

    def test_image_value_json(self):
        """
        Tests image value json generation.

        """
        image_value = ImageValue(
            "test001.png", "1516193959559", "(44.2,17.4)",
            "(5.2,1)", "1"
        )
        # TODO add image value json generation test


class TestRequestsImageMetaData(unittest.TestCase):
    """
    Unit testing for ImageMetaData class in requests module.

    """
    def test_init_image_meta_data(self):
        """
        Test generation of image meta data class
        """
        image_value = ImageValue(
            "test001.png", "1516193959559", "(44.2,17.4)",
            "(5.2,1)", "1"
        )
        image_value_list = [
            image_value,
            image_value
        ]
        qualifying_metadata = [
            {
                "key": "xxx",
                "value": "1"
            },
            {
                "key": "yyy",
                "value": "2"
            }
        ]
        image_meta_data = ImageMetaData(
            "Part1234", "Camera1", "I3DR_DESKTOP_ABC123",
            image_value_list, qualifying_metadata
        )

    def test_image_meta_data_json(self):
        """
        Tests image meta data json generation.

        """
        image_value = ImageValue(
            "test001.png", "1516193959559", "(44.2,17.4)",
            "(5.2,1)", "1"
        )
        image_value_list = [
            image_value,
            image_value
        ]
        qualifying_metadata = [
            {
                "key": "xxx",
                "value": "1"
            },
            {
                "key": "yyy",
                "value": "2"
            }
        ]
        image_meta_data = ImageMetaData(
            "Part1234", "Camera1", "I3DR_DESKTOP_ABC123",
            image_value_list, qualifying_metadata
        )
        # TODO add image meta data json generation test


class TestRequestsImageAnalysisFailure(unittest.TestCase):
    """
    Unit testing for ImageAnalysisFailure class in requests module.

    """
    def test_init_image_analysis_failure(self):
        """
        Test generation of image analysis failure class
        """
        qualifying_metadata = [
            {
                "key": "xxx",
                "value": "1"
            },
            {
                "key": "yyy",
                "value": "2"
            }
        ]
        image_analysis_failure = ImageAnalysisFailure(
            "124355435321576", "4711", "(44.2,17.4)",
            "(5.2,1)", qualifying_metadata
        )

    def test_image_analysis_failure_json(self):
        """
        Tests image analysis failure json generation.

        """
        qualifying_metadata = [
            {
                "key": "xxx",
                "value": "1"
            },
            {
                "key": "yyy",
                "value": "2"
            }
        ]
        image_analysis_failure = ImageAnalysisFailure(
            "124355435321576", "4711", "(44.2,17.4)",
            "(5.2,1)", qualifying_metadata
        )
        # TODO add image analysis failure json generation test


class TestRequestsImageAnalysisData(unittest.TestCase):
    """
    Unit testing for ImageAnalysisData class in requests module.

    """
    def test_init_image_analysis_data(self):
        """
        Test generation of image analysis data class
        """
        qualifying_metadata = [
            {
                "key": "xxx",
                "value": "1"
            },
            {
                "key": "yyy",
                "value": "2"
            }
        ]
        image_analysis_failure = ImageAnalysisFailure(
            "124355435321576", "4711", "(44.2,17.4)",
            "(5.2,1)", qualifying_metadata
        )
        image_analysis_failure_list = [
            image_analysis_failure,
            image_analysis_failure
        ]
        image_analysis_data = ImageAnalysisData(
            "Part1234", "I3DR_DESKTOP_ABC123",
            "test001.png", "1516193959559", image_analysis_failure_list
        )

    def test_image_analysis_data_json(self):
        """
        Tests image analysis data json generation.

        """
        qualifying_metadata = [
            {
                "key": "xxx",
                "value": "1"
            },
            {
                "key": "yyy",
                "value": "2"
            }
        ]
        image_analysis_failure = ImageAnalysisFailure(
            "124355435321576", "4711", "(44.2,17.4)",
            "(5.2,1)", qualifying_metadata
        )
        image_analysis_failure_list = [
            image_analysis_failure,
            image_analysis_failure
        ]
        image_analysis_data = ImageAnalysisData(
            "Part1234", "I3DR_DESKTOP_ABC123",
            "test001.png", "1516193959559", image_analysis_failure_list
        )
        # TODO add image analysis data json generation test


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