Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default AUTH_MECHANISM #93

Merged
merged 2 commits into from May 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Expand Up @@ -10,3 +10,5 @@ python:
services: mongodb
install: pip install -r test-requirements.txt -e .
script: py.test --tb=native tests
before_script:
- mongo test_db --eval 'db.addUser("flask", "pymongo");'
1 change: 1 addition & 0 deletions flask_pymongo/__init__.py
Expand Up @@ -184,6 +184,7 @@ def key(suffix):
app.config.setdefault(key('AUTH_SOURCE'), None)
app.config.setdefault(key('REPLICA_SET'), None)
app.config.setdefault(key('MAX_POOL_SIZE'), None)
app.config.setdefault(key('AUTH_MECHANISM'), 'DEFAULT')

try:
int(app.config[key('PORT')])
Expand Down
44 changes: 44 additions & 0 deletions tests/test_config.py
Expand Up @@ -160,6 +160,50 @@ def test_uri_prioritised_over_host_and_port(self):
assert mongo.db.name == 'database_name'


def test_missing_auth_mechanism_in_nonprefixed_config(self):

self.app.config["MONGO_HOST"] = 'localhost'
self.app.config["MONGO_PORT"] = 27017
self.app.config["MONGO_USERNAME"] = 'flask'
self.app.config["MONGO_PASSWORD"] = 'pymongo'
self.app.config['MONGO_DBNAME'] = 'test_db'

mongo = flask_pymongo.PyMongo(self.app)

assert mongo.db.name == 'test_db', 'wrong dbname: %s' % mongo.db.name

if pymongo.version_tuple[0] > 2:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the else ever going to be hit? I suspect you mean if pymongo.version_tuple[0] == 2: here and L196?

EDIT: oh, right, I need coffee. this is a little confusing so I'd slightly prefer if you would make this ">= 3" to avoid my brain's bugs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure - i actually copied an earlier test, so should I update that one too

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so it is -- OK, I don't love that, but won't hold this up any more.

time.sleep(0.2)

assert ('localhost', 27017) == mongo.cx.address
else:
assert mongo.cx.host == 'localhost'
assert mongo.cx.port == 27017


def test_missing_auth_mechanism_in_prefixed_config(self):

self.app.config["CUSTOM_MONGO_HOST"] = 'localhost'
self.app.config["CUSTOM_MONGO_PORT"] = 27017
self.app.config["CUSTOM_MONGO_USERNAME"] = 'flask'
self.app.config["CUSTOM_MONGO_PASSWORD"] = 'pymongo'
self.app.config['CUSTOM_MONGO_DBNAME'] = 'test_db'

mongo = flask_pymongo.PyMongo(self.app, 'CUSTOM_MONGO')

assert mongo.db.name == 'test_db', 'wrong dbname: %s' % mongo.db.name

if pymongo.version_tuple[0] > 2:
time.sleep(0.2)

assert ('localhost', 27017) == mongo.cx.address
else:
assert mongo.cx.host == 'localhost'
assert mongo.cx.port == 27017




class CustomDocumentClassTest(FlaskPyMongoTest):
""" Class that tests reading from DB with custom document_class """

Expand Down