Actions
Issue #1494
closedThe streamer unit tests need to set up a database connection
Start date:
Due date:
Estimated time:
Severity:
2. Medium
Version:
Platform Release:
2.8.1
OS:
Triaged:
Yes
Groomed:
No
Sprint Candidate:
No
Tags:
Easy Fix, Pulp 2
Sprint:
Quarter:
Description
Unit test suites need to set up their own database connection, and it seems that the streamer tests do not do this:
$ nosetests -sx streamer/test/unit/streamer/test_server.py
...............E
======================================================================
ERROR: Assert a deferred download entry is made.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/fedora/.virtualenvs/pulp/lib/python2.7/site-packages/mock.py", line 1193, in patched
arg = patching.__enter__()
File "/home/fedora/.virtualenvs/pulp/lib/python2.7/site-packages/mock.py", line 1349, in __enter__
_name=self.attribute, **kwargs)
File "/home/fedora/.virtualenvs/pulp/lib/python2.7/site-packages/mock.py", line 2200, in create_autospec
_name='()', _parent=mock)
File "/home/fedora/.virtualenvs/pulp/lib/python2.7/site-packages/mock.py", line 2221, in create_autospec
original = getattr(spec, entry)
File "/usr/lib/python2.7/site-packages/mongoengine/queryset/manager.py", line 37, in __get__
queryset = queryset_class(owner, owner._get_collection())
File "/usr/lib/python2.7/site-packages/mongoengine/document.py", line 177, in _get_collection
db = cls._get_db()
File "/usr/lib/python2.7/site-packages/mongoengine/document.py", line 170, in _get_db
return get_db(cls._meta.get("db_alias", DEFAULT_CONNECTION_NAME))
File "/usr/lib/python2.7/site-packages/mongoengine/connection.py", line 145, in get_db
conn = get_connection(alias)
File "/usr/lib/python2.7/site-packages/mongoengine/connection.py", line 101, in get_connection
raise ConnectionError(msg)
ConnectionError: You have not defined a default connection
Here is an example of how this is done for pulp.server tests:
$ cat server/test/unit/__init__.py
from pulp.devel.unit.server import base as devel_base
def setup():
"""
Set up the database connection for the tests to use.
"""
devel_base.start_database_connection()
def teardown():
"""
Drop the test database.
"""
devel_base.drop_database()
Without this, the streamer tests cannot be run on their own.
Actions
Do not use autospec with the mock MongoEngine objects
This was causing code to execute that required a database connection, but the tests themselves never used the database.
closes #1494