import unittest

from urllib3_mock import Responses
import demisto_client
from datetime import datetime
import json
responses = Responses('requests.packages.urllib3')

api_key = 'sample_api_key'
host = 'http://localhost:8080'


def assert_reset():
    assert len(responses._urls) == 0
    assert len(responses.calls) == 0


def test_get_docker_images():
    '''Check GET docker images.'''

    @responses.activate
    def run():
        body = '{ "images": [{"id": "aae7b8aaba8c", "repository": ' \
               '"openapitools/openapi-generator-cli", "tag": "latest", "createdSince": "3 days ago", ' \
               '"createdAt": "2019-08-19 13:34:22 +0300 IDT", "size": "131MB" }]}'
        responses.add('GET', '/settings/docker-images',
                      body=body,
                      status=200,
                      content_type='application/json')

        # create an instance of the API class
        api_instance = demisto_client.configure(base_url=host, api_key=api_key)
        api_response = api_instance.get_docker_images()

        assert api_response.images[0].created_at == '2019-08-19 13:34:22 +0300 IDT'
        assert api_response.images[0].id == 'aae7b8aaba8c'
        assert api_response.images[0].repository == 'openapitools/openapi-generator-cli'

        assert len(responses.calls) == 1
        assert responses.calls[0].request.url == '/settings/docker-images'
        assert responses.calls[0].request.host == 'localhost'
        assert responses.calls[0].request.scheme == 'http'

    run()
    assert_reset()


def test_create_incident():
    '''Check creating an incident.'''

    @responses.activate
    def run():