def test_init_app_multiple_connections(self): """Test the `init_app()` method with multiple connections.""" url1 = 'mongodb://*****:*****@localhost:27017/simon' self.app.config['MONGO_URI'] = url1 url2 = 'mongodb://*****:*****@localhost:27017/test' self.app.config['SIMON_URI'] = url2 simon = Simon() with mock.patch('simon.connection.connect') as connect: simon.init_app(self.app, prefix='MONGO') connect.assert_called_with(url1, name='simon', alias=None, username='******', password='******', replica_set=None) simon.init_app(self.app, prefix='SIMON') connect.assert_called_with(url2, name='test', alias=None, username='******', password='******', replica_set=None)
def test_init_app_invaliduri(self): """Test that `init_app()` raises `InvalidURI`.""" url = 'http://example.com' self.app.config['MONGO_URI'] = url simon = Simon() with self.assertRaises(InvalidURI): simon.init_app(self.app)
def test_init_app_valueerror(self): """Test that `init_app()` raises `ValueError`.""" url = 'mongodb://*****:*****@localhost:27017/' self.app.config['MONGO_URI'] = url simon = Simon() with self.assertRaises(ValueError) as e: simon.init_app(self.app) expected = 'MONGO_URI does not contain a database name.' actual = '{0}'.format(e.exception) self.assertEqual(actual, expected)
def test_init_app_prefix(self): """Test the `init_app()` method with a different prefix.""" url = 'mongodb://*****:*****@localhost:27017/test-simon' self.app.config['SIMON_URI'] = url simon = Simon() with mock.patch('simon.connection.connect') as connect: simon.init_app(self.app, prefix='SIMON') connect.assert_called_with(url, name='test-simon', alias=None, username='******', password='******', replica_set=None)
def test_init_app_uri(self): """Test the `init_app()` method with `MONGO_URI`.""" url = ('mongodb://*****:*****@localhost:27017/test-simon' '?replicaSet=rs-simon') self.app.config['MONGO_URI'] = url simon = Simon() with mock.patch('simon.connection.connect') as connect: simon.init_app(self.app) connect.assert_called_with(url, name='test-simon', alias=None, username='******', password='******', replica_set='rs-simon')
def test_init_app_settings(self): """Test the `init_app()` method with config settings.""" self.app.config['MONGO_HOST'] = 'localhost' self.app.config['MONGO_PORT'] = 27017 self.app.config['MONGO_DBNAME'] = 'test-simon' simon = Simon() with mock.patch('simon.connection.connect') as connect: simon.init_app(self.app) connect.assert_called_with('localhost:27017', name='test-simon', alias=None, username=None, password=None, replica_set=None)
def test_init_app(self): """Test the `init_app()` method.""" simon = Simon() with mock.patch('simon.connection.connect') as connect: simon.init_app(self.app) connect.assert_called_with('localhost:27017', name='test', alias=None, username=None, password=None, replica_set=None) simon.init_app(self.app, prefix='SIMON', alias='simon') connect.assert_called_with('localhost:27017', name='test', alias='simon', username=None, password=None, replica_set=None)