import json
from mock import MagicMock
from tornado.testing import AsyncHTTPTestCase
from insight_reloaded.api import application
from insight_reloaded import __version__ as VERSION


class InsightApiHTTPTest(AsyncHTTPTestCase):
    def get_app(self):
        return application

    def test_api_version(self):
        self.http_client.fetch(self.get_url('/'), self.stop)
        response = self.wait()
        body_json = json.loads(response.body)
        self.assertIn('version', body_json)
        self.assertIn('insight_reloaded', body_json)

        self.assertEqual('insight-reloaded', body_json['name'])
        self.assertEqual(VERSION, body_json['version'])

    def test_api_request(self):
        self.http_client.fetch(self.get_url('/') +
                               u'?url=http://my_file_url.com/file.pdf',
                               self.stop)
        response = self.wait()
        json_body = json.loads(response.body)
        self.assertIn('insight_reloaded', json_body)
        self.assertEqual(json_body['number_in_queue'], 1)

    def test_api_url_missing(self):
        self.http_client.fetch(self.get_url('/') + '?arg=foobar', self.stop)
        response = self.wait()
        self.assertEqual(response.code, 404)

import json
from mock import MagicMock
from tornado.testing import AsyncHTTPTestCase
from insight_reloaded.api import application
from insight_reloaded import __version__ as VERSION

from tornado import ioloop


class InsightApiHTTPTest(AsyncHTTPTestCase):

    def get_new_ioloop(self):
        return ioloop.IOLoop.instance()

    def get_app(self):
        return application

    def test_api_version(self):
        self.http_client.fetch(self.get_url('/'), self.stop)
        response = self.wait()
        body_json = json.loads(response.body)
        self.assertIn('version', body_json)
        self.assertIn('insight_reloaded', body_json)

        self.assertEqual('insight-reloaded', body_json['name'])
        self.assertEqual(VERSION, body_json['version'])

    def test_api_request(self):
        self.http_client.fetch(self.get_url('/') +
                               u'?url=http://my_file_url.com/file.pdf',
                               self.stop)
        response = self.wait()
        json_body = json.loads(response.body)
        self.assertIn('insight_reloaded', json_body)
        self.assertEqual(json_body['number_in_queue'], 1)

    def test_api_url_missing(self):
        self.http_client.fetch(self.get_url('/') + '?arg=foobar', self.stop)
        response = self.wait()
        self.assertEqual(response.code, 404)

Use global ioloop as we don't pass test ioloop to tornado redis
Use global ioloop as we don't pass test ioloop to tornado redis

  import json
  from mock import MagicMock
  from tornado.testing import AsyncHTTPTestCase
  from insight_reloaded.api import application
  from insight_reloaded import __version__ as VERSION
  
+ from tornado import ioloop
+ 
  
  class InsightApiHTTPTest(AsyncHTTPTestCase):
+ 
+     def get_new_ioloop(self):
+         return ioloop.IOLoop.instance()
+ 
      def get_app(self):
          return application
  
      def test_api_version(self):
          self.http_client.fetch(self.get_url('/'), self.stop)
          response = self.wait()
          body_json = json.loads(response.body)
          self.assertIn('version', body_json)
          self.assertIn('insight_reloaded', body_json)
  
          self.assertEqual('insight-reloaded', body_json['name'])
          self.assertEqual(VERSION, body_json['version'])
  
      def test_api_request(self):
          self.http_client.fetch(self.get_url('/') +
                                 u'?url=http://my_file_url.com/file.pdf',
                                 self.stop)
          response = self.wait()
          json_body = json.loads(response.body)
          self.assertIn('insight_reloaded', json_body)
          self.assertEqual(json_body['number_in_queue'], 1)
  
      def test_api_url_missing(self):
          self.http_client.fetch(self.get_url('/') + '?arg=foobar', self.stop)
          response = self.wait()
          self.assertEqual(response.code, 404)
  
Use global ioloop as we don't pass test ioloop to tornado redis
## Code Before:
import json
from mock import MagicMock
from tornado.testing import AsyncHTTPTestCase
from insight_reloaded.api import application
from insight_reloaded import __version__ as VERSION


class InsightApiHTTPTest(AsyncHTTPTestCase):
    def get_app(self):
        return application

    def test_api_version(self):
        self.http_client.fetch(self.get_url('/'), self.stop)
        response = self.wait()
        body_json = json.loads(response.body)
        self.assertIn('version', body_json)
        self.assertIn('insight_reloaded', body_json)

        self.assertEqual('insight-reloaded', body_json['name'])
        self.assertEqual(VERSION, body_json['version'])

    def test_api_request(self):
        self.http_client.fetch(self.get_url('/') +
                               u'?url=http://my_file_url.com/file.pdf',
                               self.stop)
        response = self.wait()
        json_body = json.loads(response.body)
        self.assertIn('insight_reloaded', json_body)
        self.assertEqual(json_body['number_in_queue'], 1)

    def test_api_url_missing(self):
        self.http_client.fetch(self.get_url('/') + '?arg=foobar', self.stop)
        response = self.wait()
        self.assertEqual(response.code, 404)

## Instruction:
Use global ioloop as we don't pass test ioloop to tornado redis
## Code After:
import json
from mock import MagicMock
from tornado.testing import AsyncHTTPTestCase
from insight_reloaded.api import application
from insight_reloaded import __version__ as VERSION

from tornado import ioloop


class InsightApiHTTPTest(AsyncHTTPTestCase):

    def get_new_ioloop(self):
        return ioloop.IOLoop.instance()

    def get_app(self):
        return application

    def test_api_version(self):
        self.http_client.fetch(self.get_url('/'), self.stop)
        response = self.wait()
        body_json = json.loads(response.body)
        self.assertIn('version', body_json)
        self.assertIn('insight_reloaded', body_json)

        self.assertEqual('insight-reloaded', body_json['name'])
        self.assertEqual(VERSION, body_json['version'])

    def test_api_request(self):
        self.http_client.fetch(self.get_url('/') +
                               u'?url=http://my_file_url.com/file.pdf',
                               self.stop)
        response = self.wait()
        json_body = json.loads(response.body)
        self.assertIn('insight_reloaded', json_body)
        self.assertEqual(json_body['number_in_queue'], 1)

    def test_api_url_missing(self):
        self.http_client.fetch(self.get_url('/') + '?arg=foobar', self.stop)
        response = self.wait()
        self.assertEqual(response.code, 404)
