Skip to content

Commit 66c298c

Browse files
committed
Merge branch 'tox-docker'
2 parents 365bd33 + 0c6825b commit 66c298c

File tree

7 files changed

+129
-47
lines changed

7 files changed

+129
-47
lines changed

.travis.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
language: python
22
python:
3-
- 2.6
43
- 2.7
5-
- 3.3
64
- 3.4
75
- 3.5
86
- 3.6
9-
# - 3.7-dev
10-
services: mongodb
11-
install: pip install -r test-requirements.txt -e .
12-
script: py.test --tb=native tests
13-
before_script:
14-
- mongo test_db --eval 'db.createUser({user:"flask", pwd:"pymongo", roles:["readWrite"]})'
7+
env:
8+
# keep this list in sync with what's in tox.ini
9+
- PYMONGO=pymongo30
10+
- PYMONGO=pymongo31
11+
- PYMONGO=pymongo32
12+
- PYMONGO=pymongo33
13+
- PYMONGO=pymongo34
14+
- PYMONGO=pymongo35
15+
- PYMONGO=pymongo36
16+
services: docker
17+
install: pip install tox tox-docker
18+
script: tox -e $(tox -l | grep "^$PYMONGO" | tr "\n" ",")

docs/index.rst

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ First, install Flask-PyMongo:
2121
2222
$ pip install Flask-PyMongo
2323
24-
Flask-PyMongo depends, and will install for you, recent versions of Flask
25-
(0.8 or later) and PyMongo (2.4 or later). Flask-PyMongo is compatible
26-
with and tested on Python 2.6, 2.7, and 3.3.
27-
2824
Next, add a :class:`~flask_pymongo.PyMongo` to your code:
2925

3026
.. code-block:: python
@@ -51,6 +47,21 @@ You can use :attr:`~flask_pymongo.PyMongo.db` directly in views:
5147
online_users=online_users)
5248
5349
50+
Compatibility
51+
-------------
52+
53+
Flask-PyMongo depends on recent versions of Flask, PyMongo, where "recent"
54+
is defined to mean "was released in the last 3 years". Flask-PyMongo _may_
55+
work with older versions, but compatibility fixes for older versions will
56+
not be accepted, and future changes may break compatibility in older
57+
versions.
58+
59+
Flask-PyMongo is tested against `supported versions
60+
<https://www.mongodb.com/support-policy>`_ of the MongoDB, and Python 2.7
61+
and 3.4+. For the exact list of version combinations that are tested and
62+
known to be compatible, see the `envlist` in `tox.ini`.
63+
64+
5465
Helpers
5566
-------
5667

@@ -229,6 +240,10 @@ History and Contributors
229240

230241
Changes:
231242

243+
- 2.0.0: *unreleased*
244+
245+
- Clarify version support of Python, Flask, PyMongo, and MongoDB
246+
232247
- 0.5.2: May 19, 2018
233248

234249
- `#102 <https://github.com/dcrosta/flask-pymongo/pull/102>`_ Return 404,

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
'License :: OSI Approved :: BSD License',
5959
'Operating System :: OS Independent',
6060
'Programming Language :: Python',
61-
'Programming Language :: Python :: 2.6',
6261
'Programming Language :: Python :: 2.7',
6362
'Programming Language :: Python :: 3.3',
6463
'Programming Language :: Python :: 3.4',

test-requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
pytest
1+
tox
2+
tox-docker
23

34
-r requirements.txt

tests/test_config.py

Lines changed: 47 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from util import FlaskRequestTest, FlaskPyMongoTest
22

33
import time
4+
import os
5+
import unittest
46

57
import pymongo
68
import flask
@@ -13,55 +15,65 @@ class CustomDict(dict):
1315

1416

1517
class FlaskPyMongoConfigTest(FlaskRequestTest):
18+
1619
def setUp(self):
17-
self.app = flask.Flask('test')
18-
self.context = self.app.test_request_context('/')
19-
self.context.push()
20+
super(FlaskPyMongoConfigTest, self).setUp()
21+
22+
conn = pymongo.MongoClient(port=self.port)
23+
conn.test_db.command(
24+
"createUser",
25+
"flask",
26+
pwd="pymongo",
27+
roles=["readWrite"],
28+
)
2029

2130
def tearDown(self):
22-
self.context.pop()
31+
super(FlaskPyMongoConfigTest, self).tearDown()
32+
33+
conn = pymongo.MongoClient(port=self.port)
34+
conn.test_db.command("dropUser", "flask")
2335

2436
def test_default_config_prefix(self):
2537
self.app.config['MONGO_DBNAME'] = 'flask_pymongo_test_db'
2638
self.app.config['MONGO_HOST'] = 'localhost'
27-
self.app.config['MONGO_PORT'] = 27017
39+
self.app.config['MONGO_PORT'] = self.port
2840

2941
mongo = flask_pymongo.PyMongo(self.app)
3042
assert mongo.db.name == 'flask_pymongo_test_db', 'wrong dbname: %s' % mongo.db.name
3143
if pymongo.version_tuple[0] > 2:
3244
time.sleep(0.2)
33-
assert ('localhost', 27017) == mongo.cx.address
45+
assert ('localhost', self.port) == mongo.cx.address
3446
else:
3547
assert mongo.cx.host == 'localhost'
36-
assert mongo.cx.port == 27017
48+
assert mongo.cx.port == self.port
3749

3850
def test_custom_config_prefix(self):
3951
self.app.config['CUSTOM_DBNAME'] = 'flask_pymongo_test_db'
4052
self.app.config['CUSTOM_HOST'] = 'localhost'
41-
self.app.config['CUSTOM_PORT'] = 27017
53+
self.app.config['CUSTOM_PORT'] = self.port
4254

4355
mongo = flask_pymongo.PyMongo(self.app, 'CUSTOM')
4456
assert mongo.db.name == 'flask_pymongo_test_db', 'wrong dbname: %s' % mongo.db.name
4557
if pymongo.version_tuple[0] > 2:
4658
time.sleep(0.2)
47-
assert ('localhost', 27017) == mongo.cx.address
59+
assert ('localhost', self.port) == mongo.cx.address
4860
else:
4961
assert mongo.cx.host == 'localhost'
50-
assert mongo.cx.port == 27017
62+
assert mongo.cx.port == self.port
5163

5264
def test_converts_str_to_int(self):
5365
self.app.config['MONGO_DBNAME'] = 'flask_pymongo_test_db'
5466
self.app.config['MONGO_HOST'] = 'localhost'
55-
self.app.config['MONGO_PORT'] = '27017'
67+
self.app.config['MONGO_PORT'] = str(self.port)
5668

5769
mongo = flask_pymongo.PyMongo(self.app)
5870
assert mongo.db.name == 'flask_pymongo_test_db', 'wrong dbname: %s' % mongo.db.name
5971
if pymongo.version_tuple[0] > 2:
6072
time.sleep(0.2)
61-
assert ('localhost', 27017) == mongo.cx.address
73+
assert ('localhost', self.port) == mongo.cx.address
6274
else:
6375
assert mongo.cx.host == 'localhost'
64-
assert mongo.cx.port == 27017
76+
assert mongo.cx.port == self.port
6577

6678
def test_rejects_invalid_string(self):
6779
self.app.config['MONGO_PORT'] = '27017x'
@@ -70,6 +82,7 @@ def test_rejects_invalid_string(self):
7082

7183
def test_multiple_pymongos(self):
7284
for prefix in ('ONE', 'TWO'):
85+
self.app.config['%s_PORT' % prefix] = self.port
7386
self.app.config['%s_DBNAME' % prefix] = prefix
7487

7588
for prefix in ('ONE', 'TWO'):
@@ -78,7 +91,7 @@ def test_multiple_pymongos(self):
7891
# this test passes if it raises no exceptions
7992

8093
def test_config_with_uri(self):
81-
self.app.config['MONGO_URI'] = 'mongodb://localhost:27017/flask_pymongo_test_db'
94+
self.app.config['MONGO_URI'] = 'mongodb://localhost:{}/flask_pymongo_test_db'.format(self.port)
8295

8396
with warnings.catch_warnings():
8497
# URI connections without a username and password
@@ -88,11 +101,12 @@ def test_config_with_uri(self):
88101
assert mongo.db.name == 'flask_pymongo_test_db', 'wrong dbname: %s' % mongo.db.name
89102
if pymongo.version_tuple[0] > 2:
90103
time.sleep(0.2)
91-
assert ('localhost', 27017) == mongo.cx.address
104+
assert ('localhost', self.port) == mongo.cx.address
92105
else:
93106
assert mongo.cx.host == 'localhost'
94-
assert mongo.cx.port == 27017
107+
assert mongo.cx.port == self.port
95108

109+
@unittest.skip("URI without port won't work with tox-docker's non-default port")
96110
def test_config_with_uri_no_port(self):
97111
self.app.config['MONGO_URI'] = 'mongodb://localhost/flask_pymongo_test_db'
98112

@@ -104,12 +118,13 @@ def test_config_with_uri_no_port(self):
104118
assert mongo.db.name == 'flask_pymongo_test_db', 'wrong dbname: %s' % mongo.db.name
105119
if pymongo.version_tuple[0] > 2:
106120
time.sleep(0.2)
107-
assert ('localhost', 27017) == mongo.cx.address
121+
assert ('localhost', self.port) == mongo.cx.address
108122
else:
109123
assert mongo.cx.host == 'localhost'
110-
assert mongo.cx.port == 27017
124+
assert mongo.cx.port == self.port
111125

112126
def test_config_with_document_class(self):
127+
self.app.config['MONGO_PORT'] = self.port
113128
self.app.config['MONGO_DOCUMENT_CLASS'] = CustomDict
114129
mongo = flask_pymongo.PyMongo(self.app)
115130
if pymongo.version_tuple[0] > 2:
@@ -118,14 +133,15 @@ def test_config_with_document_class(self):
118133
assert mongo.cx.document_class == CustomDict
119134

120135
def test_config_without_document_class(self):
136+
self.app.config['MONGO_PORT'] = self.port
121137
mongo = flask_pymongo.PyMongo(self.app)
122138
if pymongo.version_tuple[0] > 2:
123139
assert mongo.cx.codec_options.document_class == dict
124140
else:
125141
assert mongo.cx.document_class == dict
126142

127143
def test_host_with_port_does_not_get_overridden_by_separate_port_config_value(self):
128-
self.app.config['MONGO_HOST'] = 'localhost:27017'
144+
self.app.config['MONGO_HOST'] = 'localhost:{}'.format(self.port)
129145
self.app.config['MONGO_PORT'] = 27018
130146

131147
with warnings.catch_warnings():
@@ -135,13 +151,13 @@ def test_host_with_port_does_not_get_overridden_by_separate_port_config_value(se
135151
mongo = flask_pymongo.PyMongo(self.app)
136152
if pymongo.version_tuple[0] > 2:
137153
time.sleep(0.2)
138-
assert ('localhost', 27017) == mongo.cx.address
154+
assert ('localhost', self.port) == mongo.cx.address
139155
else:
140156
assert mongo.cx.host == 'localhost'
141-
assert mongo.cx.port == 27017
157+
assert mongo.cx.port == self.port
142158

143159
def test_uri_prioritised_over_host_and_port(self):
144-
self.app.config['MONGO_URI'] = 'mongodb://localhost:27017/database_name'
160+
self.app.config['MONGO_URI'] = 'mongodb://localhost:{}/database_name'.format(self.port)
145161
self.app.config['MONGO_HOST'] = 'some_other_host'
146162
self.app.config['MONGO_PORT'] = 27018
147163
self.app.config['MONGO_DBNAME'] = 'not_the_correct_db_name'
@@ -153,17 +169,16 @@ def test_uri_prioritised_over_host_and_port(self):
153169
mongo = flask_pymongo.PyMongo(self.app)
154170
if pymongo.version_tuple[0] > 2:
155171
time.sleep(0.2)
156-
assert ('localhost', 27017) == mongo.cx.address
172+
assert ('localhost', self.port) == mongo.cx.address
157173
else:
158174
assert mongo.cx.host == 'localhost'
159-
assert mongo.cx.port == 27017
175+
assert mongo.cx.port == self.port
160176
assert mongo.db.name == 'database_name'
161177

162178

163179
def test_missing_auth_mechanism_in_nonprefixed_config(self):
164-
165180
self.app.config["MONGO_HOST"] = 'localhost'
166-
self.app.config["MONGO_PORT"] = 27017
181+
self.app.config["MONGO_PORT"] = self.port
167182
self.app.config["MONGO_USERNAME"] = 'flask'
168183
self.app.config["MONGO_PASSWORD"] = 'pymongo'
169184
self.app.config['MONGO_DBNAME'] = 'test_db'
@@ -175,16 +190,15 @@ def test_missing_auth_mechanism_in_nonprefixed_config(self):
175190
if pymongo.version_tuple[0] > 2:
176191
time.sleep(0.2)
177192

178-
assert ('localhost', 27017) == mongo.cx.address
193+
assert ('localhost', self.port) == mongo.cx.address
179194
else:
180195
assert mongo.cx.host == 'localhost'
181-
assert mongo.cx.port == 27017
196+
assert mongo.cx.port == self.port
182197

183198

184199
def test_missing_auth_mechanism_in_prefixed_config(self):
185-
186200
self.app.config["CUSTOM_MONGO_HOST"] = 'localhost'
187-
self.app.config["CUSTOM_MONGO_PORT"] = 27017
201+
self.app.config["CUSTOM_MONGO_PORT"] = self.port
188202
self.app.config["CUSTOM_MONGO_USERNAME"] = 'flask'
189203
self.app.config["CUSTOM_MONGO_PASSWORD"] = 'pymongo'
190204
self.app.config['CUSTOM_MONGO_DBNAME'] = 'test_db'
@@ -196,10 +210,10 @@ def test_missing_auth_mechanism_in_prefixed_config(self):
196210
if pymongo.version_tuple[0] > 2:
197211
time.sleep(0.2)
198212

199-
assert ('localhost', 27017) == mongo.cx.address
213+
assert ('localhost', self.port) == mongo.cx.address
200214
else:
201215
assert mongo.cx.host == 'localhost'
202-
assert mongo.cx.port == 27017
216+
assert mongo.cx.port == self.port
203217

204218

205219

@@ -218,6 +232,7 @@ def test_create_with_document_class(self):
218232
# copying standard DBNAME, so this DB gets also deleted by tearDown
219233
self.app.config['CUSTOM_DBNAME'] = self.app.config['MONGO_DBNAME']
220234
self.app.config['CUSTOM_DOCUMENT_CLASS'] = CustomDict
235+
self.app.config['CUSTOM_PORT'] = self.port
221236
# not using self.mongo, because we want to use updated config
222237
# also using CUSTOM, to avoid duplicate config_prefix exception
223238
mongo = flask_pymongo.PyMongo(self.app, 'CUSTOM')

tests/util.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
1+
import os
2+
13
import flask
24
import flask_pymongo
35
import unittest
46

5-
class FlaskRequestTest(unittest.TestCase):
7+
8+
class ToxDockerMixin(object):
9+
"""
10+
Check for the environment var from tox-docker describing the port, and set :attr:`port`.
11+
"""
612

713
def setUp(self):
14+
super(ToxDockerMixin, self).setUp()
15+
16+
self.port = int(os.environ.get('MONGO_27017_TCP', 27017))
17+
18+
19+
class FlaskRequestTest(ToxDockerMixin, unittest.TestCase):
20+
21+
def setUp(self):
22+
super(FlaskRequestTest, self).setUp()
23+
824
self.app = flask.Flask('test')
925
self.context = self.app.test_request_context('/')
1026
self.context.push()
1127

1228
def tearDown(self):
29+
super(FlaskRequestTest, self).tearDown()
30+
1331
self.context.pop()
1432

1533
class FlaskPyMongoTest(FlaskRequestTest):
@@ -19,6 +37,7 @@ def setUp(self):
1937

2038
self.dbname = self.__class__.__name__
2139
self.app.config['MONGO_DBNAME'] = self.dbname
40+
self.app.config['MONGO_PORT'] = self.port
2241
self.mongo = flask_pymongo.PyMongo(self.app)
2342
self.mongo.cx.drop_database(self.dbname)
2443

tox.ini

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[tox]
2+
3+
; keep the pymongo list in sync with what's in .travis.yaml
4+
envlist=
5+
pymongo{30,31,32,33,34,35,36}-mongo{32,34,36}-flask{0_11,0_12,10}
6+
7+
[testenv]
8+
docker =
9+
mongo32: mongo:3.2
10+
mongo34: mongo:3.4
11+
mongo36: mongo:3.6
12+
13+
deps =
14+
pytest
15+
16+
pymongo30: pymongo>=3.0,<3.1
17+
pymongo31: pymongo>=3.1,<3.2
18+
pymongo32: pymongo>=3.2,<3.3
19+
pymongo33: pymongo>=3.3,<3.4
20+
pymongo34: pymongo>=3.4,<3.5
21+
pymongo35: pymongo>=3.5,<3.6
22+
pymongo36: pymongo>=3.6,<3.7
23+
24+
flask0_11: flask>=0.11,<0.12
25+
flask0_12: flask>=0.12,<1.0
26+
flask10: flask>=1.0,<1.1
27+
28+
commands =
29+
{envbindir}/py.test --tb=native tests

0 commit comments

Comments
 (0)