
import unittest
from flask import Flask
from flask.ext.knot import Knot


def create_app():
    app = Flask(__name__)
    app.config['TESTING'] = True
    return app


class TestKnot(unittest.TestCase):
    def test_acts_like_container(self):
        app = create_app()
        dic = Knot(app)

        def foo(c):
            return 'bar'

        dic.add_factory(foo)

        self.assertEqual(dic.provide('foo'), 'bar')

    def test_does_use_app_config_on_initialization(self):
        app = create_app()
        app.config['foo'] = 'bar'
        dic = Knot(app)

        self.assertEqual(dic['foo'], 'bar')

    def test_does_not_use_app_config_after_initialization(self):
        app = create_app()
        app.config['foo'] = 'bar'
        dic = Knot()
        dic.init_app(app)

        self.assertRaises(KeyError, lambda: dic['foo'])


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


import unittest
from flask import Flask
from flask.ext.knot import Knot, get_container


def create_app():
    app = Flask(__name__)
    app.config['TESTING'] = True
    return app


class TestKnot(unittest.TestCase):
    def test_acts_like_container(self):
        app = create_app()
        dic = Knot(app)

        def foo(c):
            return 'bar'

        dic.add_factory(foo)

        self.assertEqual(dic.provide('foo'), 'bar')

    def test_does_use_app_config_on_initialization(self):
        app = create_app()
        app.config['foo'] = 'bar'
        dic = Knot(app)

        self.assertEqual(dic['foo'], 'bar')

    def test_does_not_use_app_config_after_initialization(self):
        app = create_app()
        app.config['foo'] = 'bar'
        dic = Knot()
        dic.init_app(app)

        self.assertRaises(KeyError, lambda: dic['foo'])

    def test_container_is_shared(self):
        app1 = create_app()
        app2 = create_app()

        dic = Knot()
        dic.init_app(app1)
        dic.init_app(app2)

        dic1 = get_container(app1)
        dic2 = get_container(app2)

        assert dic1 is dic2


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

Add test for shared container.
Add test for shared container.
  
  import unittest
  from flask import Flask
- from flask.ext.knot import Knot
+ from flask.ext.knot import Knot, get_container
  
  
  def create_app():
      app = Flask(__name__)
      app.config['TESTING'] = True
      return app
  
  
  class TestKnot(unittest.TestCase):
      def test_acts_like_container(self):
          app = create_app()
          dic = Knot(app)
  
          def foo(c):
              return 'bar'
  
          dic.add_factory(foo)
  
          self.assertEqual(dic.provide('foo'), 'bar')
  
      def test_does_use_app_config_on_initialization(self):
          app = create_app()
          app.config['foo'] = 'bar'
          dic = Knot(app)
  
          self.assertEqual(dic['foo'], 'bar')
  
      def test_does_not_use_app_config_after_initialization(self):
          app = create_app()
          app.config['foo'] = 'bar'
          dic = Knot()
          dic.init_app(app)
  
          self.assertRaises(KeyError, lambda: dic['foo'])
  
+     def test_container_is_shared(self):
+         app1 = create_app()
+         app2 = create_app()
+ 
+         dic = Knot()
+         dic.init_app(app1)
+         dic.init_app(app2)
+ 
+         dic1 = get_container(app1)
+         dic2 = get_container(app2)
+ 
+         assert dic1 is dic2
+ 
  
  if __name__ == '__main__':
      unittest.main()
  
Add test for shared container.
## Code Before:

import unittest
from flask import Flask
from flask.ext.knot import Knot


def create_app():
    app = Flask(__name__)
    app.config['TESTING'] = True
    return app


class TestKnot(unittest.TestCase):
    def test_acts_like_container(self):
        app = create_app()
        dic = Knot(app)

        def foo(c):
            return 'bar'

        dic.add_factory(foo)

        self.assertEqual(dic.provide('foo'), 'bar')

    def test_does_use_app_config_on_initialization(self):
        app = create_app()
        app.config['foo'] = 'bar'
        dic = Knot(app)

        self.assertEqual(dic['foo'], 'bar')

    def test_does_not_use_app_config_after_initialization(self):
        app = create_app()
        app.config['foo'] = 'bar'
        dic = Knot()
        dic.init_app(app)

        self.assertRaises(KeyError, lambda: dic['foo'])


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

## Instruction:
Add test for shared container.
## Code After:

import unittest
from flask import Flask
from flask.ext.knot import Knot, get_container


def create_app():
    app = Flask(__name__)
    app.config['TESTING'] = True
    return app


class TestKnot(unittest.TestCase):
    def test_acts_like_container(self):
        app = create_app()
        dic = Knot(app)

        def foo(c):
            return 'bar'

        dic.add_factory(foo)

        self.assertEqual(dic.provide('foo'), 'bar')

    def test_does_use_app_config_on_initialization(self):
        app = create_app()
        app.config['foo'] = 'bar'
        dic = Knot(app)

        self.assertEqual(dic['foo'], 'bar')

    def test_does_not_use_app_config_after_initialization(self):
        app = create_app()
        app.config['foo'] = 'bar'
        dic = Knot()
        dic.init_app(app)

        self.assertRaises(KeyError, lambda: dic['foo'])

    def test_container_is_shared(self):
        app1 = create_app()
        app2 = create_app()

        dic = Knot()
        dic.init_app(app1)
        dic.init_app(app2)

        dic1 = get_container(app1)
        dic2 = get_container(app2)

        assert dic1 is dic2


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