# -*- coding: utf-8 -*-

"""
    greenbyteapi

    This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
"""

import jsonpickle
import dateutil.parser
from .controller_test_base import ControllerTestBase
from ..test_helper import TestHelper
from greenbyteapi.api_helper import APIHelper


class AlertsControllerTests(ControllerTestBase):

    @classmethod
    def setUpClass(cls):
        super(AlertsControllerTests, cls).setUpClass()
        cls.controller = cls.api_client.alerts

    # Gets active alerts for multiple devices.
    #The timestamps are in the time zone configured in the Greenbyte Platform.
    #Use the useUtc flag to get timestamps in UTC.
    #
    #_🔐 This endpoint requires the **Alerts** endpoint permission._
    #
    #_This request can also be made using the POST method, 
    #with a request to `activealerts.json` and 
    #a JSON request body instead of query parameters._
    #
    def test_test_get_active_alerts(self):
        # Parameters for the API call
        device_ids = APIHelper.json_deserialize('[1,2,3]')
        fields = APIHelper.json_deserialize('["ruleId","timestampStart"]')
        sort_by = None
        sort_asc = False
        page_size = 50
        page = 1
        use_utc = False

        # Perform the API call through the SDK function
        result = self.controller.get_active_alerts(device_ids, fields, sort_by, sort_asc, page_size, page, use_utc)

        # Test response code
        self.assertEquals(self.response_catcher.response.status_code, 200)

        # Test headers
        expected_headers = {}
        expected_headers['content-type'] = 'application/json; charset=utf-8'

        self.assertTrue(TestHelper.match_headers(expected_headers, self.response_catcher.response.headers))

        
        # Test whether the captured response is as we expected
        self.assertIsNotNone(result)
        expected_body = APIHelper.json_deserialize(
            '[{"deviceId":179,"ruleId":104,"description":"Power curve less than 90%","d'
            'etails":"Evaluation period: 6 hours\\nData coverage: 70% of devices\\nExclu'
            'de data during: Active Stop or Warning status\\nData condition: The consecu'
            'tive value of the performance index of Backen 2 is less than 90%\\nData con'
            'dition: The consecutive value of the wind speed of Backen 2 is greater than'
            ' 5 m/s","timestampStart":"2020-03-18T06:50:00","timestampEnd":"2020-03-18T1'
            '4:00:00","message":"Low Performance Wind","comment":"A comment"},{"deviceId'
            '":183,"ruleId":104,"description":"Power curve less than 90%","details":"Eva'
            'luation period: 6 hours\\nData coverage: 70% of devices\\nExclude data duri'
            'ng: Active Stop or Warning status\\nData condition: The consecutive value o'
            'f the performance index of Backen 6 is less than 90%\\nData condition: The '
            'consecutive value of the wind speed of Backen 6 is greater than 5 m/s","tim'
            'estampStart":"2020-03-18T07:40:00","timestampEnd":"2020-03-18T14:00:00","me'
            'ssage":"Low Performance Wind","comment":"A comment"}]'
            )
        received_body = APIHelper.json_deserialize(self.response_catcher.response.raw_body)
        self.assertTrue(TestHelper.match_body(expected_body, received_body))


    # Gets active alerts for multiple devices.
    #The timestamps are in the time zone configured in the Greenbyte Platform.
    #Use the useUtc flag to get timestamps in UTC.
    #
    #_🔐 This endpoint requires the **Alerts** endpoint permission._
    #
    #_This request can also be made using the POST method, 
    #with a request to `activealerts.json` and 
    #a JSON request body instead of query parameters._
    #
    def test_test_get_active_alerts_1(self):
        # Parameters for the API call
        device_ids = APIHelper.json_deserialize('[1,2,3]')
        fields = APIHelper.json_deserialize('["ruleId","timestampStart"]')
        sort_by = None
        sort_asc = False
        page_size = 50
        page = 1
        use_utc = False

        # Perform the API call through the SDK function
        result = self.controller.get_active_alerts(device_ids, fields, sort_by, sort_asc, page_size, page, use_utc)

        # Test response code
        self.assertEquals(self.response_catcher.response.status_code, 204)

    # Gets alerts for multiple devices and the given time period.
    #The timestamps are in the time zone configured in the Greenbyte Platform.
    #Use the useUtc flag to get timestamps in UTC.
    #
    #_🔐 This endpoint requires the **Alerts** endpoint permission._
    #
    #_This request can also be made using the POST method, 
    #with a request to `alerts.json` and 
    #a JSON request body instead of query parameters._
    #
    def test_test_get_alerts(self):
        # Parameters for the API call
        device_ids = APIHelper.json_deserialize('[1,2,3]')
        timestamp_start = APIHelper.RFC3339DateTime.from_value('2020-01-01T00:00:00Z').datetime
        timestamp_end = APIHelper.RFC3339DateTime.from_value('2020-01-08T00:00:00Z').datetime
        fields = APIHelper.json_deserialize('["ruleId","timestampStart"]')
        sort_by = None
        sort_asc = False
        page_size = 50
        page = 1
        use_utc = False

        # Perform the API call through the SDK function
        result = self.controller.get_alerts(device_ids, timestamp_start, timestamp_end, fields, sort_by, sort_asc, page_size, page, use_utc)

        # Test response code
        self.assertEquals(self.response_catcher.response.status_code, 200)

        # Test headers
        expected_headers = {}
        expected_headers['content-type'] = 'application/json; charset=utf-8'

        self.assertTrue(TestHelper.match_headers(expected_headers, self.response_catcher.response.headers))

        
        # Test whether the captured response is as we expected
        self.assertIsNotNone(result)
        expected_body = APIHelper.json_deserialize(
            '[{"deviceId":179,"ruleId":104,"description":"Power curve less than 90%","d'
            'etails":"Evaluation period: 6 hours\\nData coverage: 70% of devices\\nExclu'
            'de data during: Active Stop or Warning status\\nData condition: The consecu'
            'tive value of the performance index of Backen 2 is less than 90%\\nData con'
            'dition: The consecutive value of the wind speed of Backen 2 is greater than'
            ' 5 m/s","timestampStart":"2020-03-18T06:50:00","timestampEnd":"2020-03-18T1'
            '4:00:00","message":"Low Performance Wind","comment":"A comment"},{"deviceId'
            '":183,"ruleId":104,"description":"Power curve less than 90%","details":"Eva'
            'luation period: 6 hours\\nData coverage: 70% of devices\\nExclude data duri'
            'ng: Active Stop or Warning status\\nData condition: The consecutive value o'
            'f the performance index of Backen 6 is less than 90%\\nData condition: The '
            'consecutive value of the wind speed of Backen 6 is greater than 5 m/s","tim'
            'estampStart":"2020-03-18T07:40:00","timestampEnd":"2020-03-18T14:00:00","me'
            'ssage":"Low Performance Wind","comment":"A comment"}]'
            )
        received_body = APIHelper.json_deserialize(self.response_catcher.response.raw_body)
        self.assertTrue(TestHelper.match_body(expected_body, received_body))


    # Gets alerts for multiple devices and the given time period.
    #The timestamps are in the time zone configured in the Greenbyte Platform.
    #Use the useUtc flag to get timestamps in UTC.
    #
    #_🔐 This endpoint requires the **Alerts** endpoint permission._
    #
    #_This request can also be made using the POST method, 
    #with a request to `alerts.json` and 
    #a JSON request body instead of query parameters._
    #
    def test_test_get_alerts_1(self):
        # Parameters for the API call
        device_ids = APIHelper.json_deserialize('[1,2,3]')
        timestamp_start = APIHelper.RFC3339DateTime.from_value('2020-01-01T00:00:00Z').datetime
        timestamp_end = APIHelper.RFC3339DateTime.from_value('2020-01-08T00:00:00Z').datetime
        fields = APIHelper.json_deserialize('["ruleId","timestampStart"]')
        sort_by = None
        sort_asc = False
        page_size = 50
        page = 1
        use_utc = False

        # Perform the API call through the SDK function
        result = self.controller.get_alerts(device_ids, timestamp_start, timestamp_end, fields, sort_by, sort_asc, page_size, page, use_utc)

        # Test response code
        self.assertEquals(self.response_catcher.response.status_code, 204)

    # _**This endpoint is deprecated.** Please use the new endpoint `/activealerts.json` instead._
    def test_test_get_active_alarms(self):
        # Parameters for the API call
        device_ids = APIHelper.json_deserialize('[1,2,3]')
        fields = APIHelper.json_deserialize('["ruleId","timestampStart"]')
        sort_by = None
        sort_asc = False
        page_size = 50
        page = 1

        # Perform the API call through the SDK function
        result = self.controller.get_active_alarms(device_ids, fields, sort_by, sort_asc, page_size, page)

        # Test response code
        self.assertEquals(self.response_catcher.response.status_code, 200)

        # Test headers
        expected_headers = {}
        expected_headers['content-type'] = 'application/json; charset=utf-8'

        self.assertTrue(TestHelper.match_headers(expected_headers, self.response_catcher.response.headers))

        
        # Test whether the captured response is as we expected
        self.assertIsNotNone(result)
        expected_body = APIHelper.json_deserialize(
            '[{"deviceId":179,"ruleId":104,"description":"Power curve less than 90%","d'
            'etails":"Evaluation period: 6 hours\\nData coverage: 70% of devices\\nExclu'
            'de data during: Active Stop or Warning status\\nData condition: The consecu'
            'tive value of the performance index of Backen 2 is less than 90%\\nData con'
            'dition: The consecutive value of the wind speed of Backen 2 is greater than'
            ' 5 m/s","timestampStart":"2020-03-18T06:50:00","timestampEnd":"2020-03-18T1'
            '4:00:00","message":"Low Performance Wind","comment":"A comment"},{"deviceId'
            '":183,"ruleId":104,"description":"Power curve less than 90%","details":"Eva'
            'luation period: 6 hours\\nData coverage: 70% of devices\\nExclude data duri'
            'ng: Active Stop or Warning status\\nData condition: The consecutive value o'
            'f the performance index of Backen 6 is less than 90%\\nData condition: The '
            'consecutive value of the wind speed of Backen 6 is greater than 5 m/s","tim'
            'estampStart":"2020-03-18T07:40:00","timestampEnd":"2020-03-18T14:00:00","me'
            'ssage":"Low Performance Wind","comment":"A comment"}]'
            )
        received_body = APIHelper.json_deserialize(self.response_catcher.response.raw_body)
        self.assertTrue(TestHelper.match_body(expected_body, received_body))


    # _**This endpoint is deprecated.** Please use the new endpoint `/activealerts.json` instead._
    def test_test_get_active_alarms_1(self):
        # Parameters for the API call
        device_ids = APIHelper.json_deserialize('[1,2,3]')
        fields = APIHelper.json_deserialize('["ruleId","timestampStart"]')
        sort_by = None
        sort_asc = False
        page_size = 50
        page = 1

        # Perform the API call through the SDK function
        result = self.controller.get_active_alarms(device_ids, fields, sort_by, sort_asc, page_size, page)

        # Test response code
        self.assertEquals(self.response_catcher.response.status_code, 204)

    # _**This endpoint is deprecated.** Please use the new endpoint `/alerts.json` instead._
    def test_test_get_alarms(self):
        # Parameters for the API call
        device_ids = APIHelper.json_deserialize('[1,2,3]')
        timestamp_start = APIHelper.RFC3339DateTime.from_value('2020-01-01T00:00:00Z').datetime
        timestamp_end = APIHelper.RFC3339DateTime.from_value('2020-01-08T00:00:00Z').datetime
        fields = APIHelper.json_deserialize('["ruleId","timestampStart"]')
        sort_by = None
        sort_asc = False
        page_size = 50
        page = 1

        # Perform the API call through the SDK function
        result = self.controller.get_alarms(device_ids, timestamp_start, timestamp_end, fields, sort_by, sort_asc, page_size, page)

        # Test response code
        self.assertEquals(self.response_catcher.response.status_code, 200)

        # Test headers
        expected_headers = {}
        expected_headers['content-type'] = 'application/json; charset=utf-8'

        self.assertTrue(TestHelper.match_headers(expected_headers, self.response_catcher.response.headers))

        
        # Test whether the captured response is as we expected
        self.assertIsNotNone(result)
        expected_body = APIHelper.json_deserialize(
            '[{"deviceId":179,"ruleId":104,"description":"Power curve less than 90%","d'
            'etails":"Evaluation period: 6 hours\\nData coverage: 70% of devices\\nExclu'
            'de data during: Active Stop or Warning status\\nData condition: The consecu'
            'tive value of the performance index of Backen 2 is less than 90%\\nData con'
            'dition: The consecutive value of the wind speed of Backen 2 is greater than'
            ' 5 m/s","timestampStart":"2020-03-18T06:50:00","timestampEnd":"2020-03-18T1'
            '4:00:00","message":"Low Performance Wind","comment":"A comment"},{"deviceId'
            '":183,"ruleId":104,"description":"Power curve less than 90%","details":"Eva'
            'luation period: 6 hours\\nData coverage: 70% of devices\\nExclude data duri'
            'ng: Active Stop or Warning status\\nData condition: The consecutive value o'
            'f the performance index of Backen 6 is less than 90%\\nData condition: The '
            'consecutive value of the wind speed of Backen 6 is greater than 5 m/s","tim'
            'estampStart":"2020-03-18T07:40:00","timestampEnd":"2020-03-18T14:00:00","me'
            'ssage":"Low Performance Wind","comment":"A comment"}]'
            )
        received_body = APIHelper.json_deserialize(self.response_catcher.response.raw_body)
        self.assertTrue(TestHelper.match_body(expected_body, received_body))


    # _**This endpoint is deprecated.** Please use the new endpoint `/alerts.json` instead._
    def test_test_get_alarms_1(self):
        # Parameters for the API call
        device_ids = APIHelper.json_deserialize('[1,2,3]')
        timestamp_start = APIHelper.RFC3339DateTime.from_value('2020-01-01T00:00:00Z').datetime
        timestamp_end = APIHelper.RFC3339DateTime.from_value('2020-01-08T00:00:00Z').datetime
        fields = APIHelper.json_deserialize('["ruleId","timestampStart"]')
        sort_by = None
        sort_asc = False
        page_size = 50
        page = 1

        # Perform the API call through the SDK function
        result = self.controller.get_alarms(device_ids, timestamp_start, timestamp_end, fields, sort_by, sort_asc, page_size, page)

        # Test response code
        self.assertEquals(self.response_catcher.response.status_code, 204)

