import json
import unittest

from flask import Flask
from flask_selfdoc import Autodoc


class TestAutodocWithFlask(unittest.TestCase):
    def setup_app(self):
        self.app = Flask(__name__)
        self.autodoc = Autodoc(self.app)

    def setUp(self):
        self.setup_app()

        @self.app.route('/')
        @self.autodoc.doc()
        def index():
            """Returns a hello world message"""
            return 'Hello World!'

        self.client = self.app.test_client()

    def test_html(self):
        @self.app.route('/docs')
        def html_docs():
            return self.autodoc.html()

        response = self.client.get('/docs')
        self.assertEqual(response.status_code, 200)

    def test_json(self):
        @self.app.route('/docs')
        def json_docs():
            return self.autodoc.json()

        response = self.client.get('/docs')
        self.assertEqual(response.status_code, 200)

        data = json.loads(response.data.decode('utf-8'))
        self.assertIn('endpoints', data)
        self.assertEqual(len(data['endpoints']), 1)

        endpoint = data['endpoints'][0]
        expected = {
            "args": [],
            "docstring": "Returns a hello world message",
            "methods": ["GET", "HEAD", "OPTIONS"],
            "rule": "/"
        }
        self.assertEqual(endpoint, expected)


class TestAutodocWithFlaskFactory(TestAutodocWithFlask):
    def setup_app(self):
        self.app = Flask(__name__)
        self.autodoc = Autodoc()
        self.autodoc.init_app(self.app)

@@ -1533,16 +1533,700 @@
 t_app(self.app)%0A
+%0A%0Aclass TestAutodocTwoApps(unittest.TestCase):%0A    def setUp(self):%0A        self.app_1 = Flask(__name__)%0A        self.app_2 = Flask(__name__)%0A        self.autodoc = Autodoc()%0A        self.autodoc.init_app(self.app_1)%0A        self.autodoc.init_app(self.app_2)%0A%0A    def test_endpoint_on_one_app(self):%0A        @self.app_1.route('/')%0A        @self.autodoc.doc()%0A        def index():%0A            %22%22%22Returns a hello world message%22%22%22%0A            return 'Hello World!'%0A%0A        with self.app_2.app_context():%0A            response = self.autodoc.json()%0A        %0A        data = json.loads(response.data)%0A        self.assertIn('endpoints', data)%0A        self.assertEqual(data%5B'endpoints'%5D, %5B%5D)%0A

Add a test for two apps with the same object.