|
5 | 5 |
|
6 | 6 | from flask_mongoengine import MongoEngine |
7 | 7 |
|
8 | | -from .tests import FlaskMongoEngineTestCase |
| 8 | +from tests import FlaskMongoEngineTestCase |
9 | 9 |
|
10 | 10 |
|
11 | 11 | class ConnectionTestCase(FlaskMongoEngineTestCase): |
@@ -36,20 +36,27 @@ def test_simple_connection(self): |
36 | 36 | """Make sure a simple connection to a standalone MongoDB works.""" |
37 | 37 | db = MongoEngine() |
38 | 38 | self.app.config['MONGODB_SETTINGS'] = { |
| 39 | + 'ALIAS': 'simple_conn', |
39 | 40 | 'HOST': 'localhost', |
40 | 41 | 'PORT': 27017, |
41 | 42 | 'DB': 'flask_mongoengine_test_db' |
42 | 43 | } |
43 | 44 | self._do_persist(db) |
44 | 45 |
|
45 | | - def test_connection_with_uri_string(self): |
| 46 | + def test_host_as_uri_string(self): |
46 | 47 | """Make sure we can connect to a standalone MongoDB if we specify |
47 | 48 | the host as a MongoDB URI. |
48 | 49 | """ |
49 | 50 | db = MongoEngine() |
50 | 51 | self.app.config['MONGODB_HOST'] = 'mongodb://localhost:27017/flask_mongoengine_test_db' |
51 | 52 | self._do_persist(db) |
52 | 53 |
|
| 54 | + def test_host_as_list(self): |
| 55 | + """Make sure MONGODB_HOST can be a list hosts.""" |
| 56 | + db = MongoEngine() |
| 57 | + self.app.config['MONGODB_HOST'] = ['localhost:27017'] |
| 58 | + self._do_persist(db) |
| 59 | + |
53 | 60 | def test_multiple_connections(self): |
54 | 61 | """Make sure establishing multiple connections to a standalone |
55 | 62 | MongoDB and switching between them works. |
@@ -120,16 +127,17 @@ def test_connection_kwargs(self): |
120 | 127 | MAX_POOL_SIZE_KEY = 'MAX_POOL_SIZE' |
121 | 128 |
|
122 | 129 | self.app.config['MONGODB_SETTINGS'] = { |
| 130 | + 'ALIAS': 'tz_aware_true', |
123 | 131 | 'DB': 'flask_mongoengine_testing_tz_aware', |
124 | 132 | 'TZ_AWARE': True, |
125 | 133 | 'READ_PREFERENCE': ReadPreference.SECONDARY, |
126 | 134 | MAX_POOL_SIZE_KEY: 10, |
127 | 135 | } |
128 | 136 | db = MongoEngine() |
129 | 137 | db.init_app(self.app) |
130 | | - self.assertTrue(db.connection.client.codec_options.tz_aware) |
131 | | - self.assertEqual(db.connection.client.max_pool_size, 10) |
| 138 | + self.assertTrue(db.connection.codec_options.tz_aware) |
| 139 | + self.assertEqual(db.connection.max_pool_size, 10) |
132 | 140 | self.assertEqual( |
133 | | - db.connection.client.read_preference, |
| 141 | + db.connection.read_preference, |
134 | 142 | ReadPreference.SECONDARY |
135 | 143 | ) |
0 commit comments