Esempio n. 1
0
class BaseTestCaseInitAppWithContext():
    def setUp(self):
        self.app = create_app()

    def test_init_later(self):
        self.db = MongoKit()
        self.assertRaises(RuntimeError, self.db.connect)

        self.db.init_app(self.app)
        self.db.connect()
        assert self.db.connected

    def test_init_immediately(self):
        self.db = MongoKit(self.app)
        self.db.connect()
        assert self.db.connected
Esempio n. 2
0
class BaseTestCaseInitAppWithContext():
    def setUp(self):
        self.app = create_app()

    def test_init_later(self):
        self.db = MongoKit()
        self.assertRaises(RuntimeError, self.db.connect)

        self.db.init_app(self.app)
        self.db.connect()
        assert self.db.connected

    def test_init_immediately(self):
        self.db = MongoKit(self.app)
        self.db.connect()
        assert self.db.connected
Esempio n. 3
0
class BaseTestCaseMultipleApps():

    def setUp(self):
        self.app_1 = create_app()
        self.app_1.config['MONGODB_DATABASE'] = 'app_1'
        
        self.app_2 = create_app()
        self.app_2.config['MONGODB_DATABASE'] = 'app_2'
        
        assert self.app_1 != self.app_2
        
        self.db = MongoKit()
        self.db.init_app(self.app_1)
        self.db.init_app(self.app_2)

    def tearDown(self):
        self.pop_ctx()

    def push_ctx(self):
        raise NotImplementedError
    
    def pop_ctx(self):
        raise NotImplementedError

    def test_app_1(self):
        self.push_ctx(self.app_1)
        
        self.db.connect()
        assert self.db.connected
        assert self.db.name == 'app_1'
        assert self.db.name != 'app_2'
        
    def test_app_2(self):
        self.push_ctx(self.app_2)
        
        self.db.connect()
        assert self.db.connected
        assert self.db.name != 'app_1'
        assert self.db.name == 'app_2'
Esempio n. 4
0
class BaseTestCaseMultipleApps():
    def setUp(self):
        self.app_1 = create_app()
        self.app_1.config['MONGODB_DATABASE'] = 'app_1'

        self.app_2 = create_app()
        self.app_2.config['MONGODB_DATABASE'] = 'app_2'

        assert self.app_1 != self.app_2

        self.db = MongoKit()
        self.db.init_app(self.app_1)
        self.db.init_app(self.app_2)

    def tearDown(self):
        self.pop_ctx()

    def push_ctx(self):
        raise NotImplementedError

    def pop_ctx(self):
        raise NotImplementedError

    def test_app_1(self):
        self.push_ctx(self.app_1)

        self.db.connect()
        assert self.db.connected
        assert self.db.name == 'app_1'
        assert self.db.name != 'app_2'

    def test_app_2(self):
        self.push_ctx(self.app_2)

        self.db.connect()
        assert self.db.connected
        assert self.db.name != 'app_1'
        assert self.db.name == 'app_2'