Example #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
Example #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
Example #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'
Example #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'
Example #5
0
class BaseTestCaseWithAuth():
    def setUp(self):
        db = 'flask_testing_auth'
        conn = Connection()
        conn[db].add_user('test', 'test')

        self.app = create_app()
        self.app.config['TESTING'] = True
        self.app.config['MONGODB_DATABASE'] = db

        self.db = MongoKit(self.app)

    def test_correct_login(self):
        self.app.config['MONGODB_USERNAME'] = '******'
        self.app.config['MONGODB_PASSWORD'] = '******'

        self.db.connect()

    def test_incorrect_login(self):
        self.app.config['MONGODB_USERNAME'] = '******'
        self.app.config['MONGODB_PASSWORD'] = '******'

        self.assertRaises(AuthenticationIncorrect, self.db.connect)
Example #6
0
class BaseTestCaseWithAuth():
    def setUp(self):
        db = 'flask_testing_auth'
        conn = Connection()
        conn[db].add_user('test', 'test')
        
        self.app = create_app()
        self.app.config['TESTING'] = True
        self.app.config['MONGODB_DATABASE'] = db
        
        self.db = MongoKit(self.app)

    def test_correct_login(self):
        self.app.config['MONGODB_USERNAME'] = '******'
        self.app.config['MONGODB_PASSWORD'] = '******'
        
        self.db.connect()
    
    def test_incorrect_login(self):
        self.app.config['MONGODB_USERNAME'] = '******'
        self.app.config['MONGODB_PASSWORD'] = '******'
        
        self.assertRaises(AuthenticationIncorrect, self.db.connect)