Project

Profile

Help

Issue #1494

The streamer unit tests need to set up a database connection

Added by rbarlow over 4 years ago. Updated over 1 year ago.

Status:
CLOSED - CURRENTRELEASE
Priority:
Normal
Category:
-
Sprint/Milestone:
-
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.

Associated revisions

Revision 77235b58 View on GitHub
Added by Jeremy Cline over 4 years ago

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

Revision 77235b58 View on GitHub
Added by Jeremy Cline over 4 years ago

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

History

#1 Updated by mhrivnak over 4 years ago

  • Status changed from NEW to ASSIGNED
  • Assignee set to jcline@redhat.com
  • Triaged changed from No to Yes
  • Tags Easy Fix added

#2 Updated by bmbouter over 4 years ago

Consider two things:

1) Unit tests shouldn't need the DB at all. Unit tests should be able to be run without mongodb running. Many unit tests require the db so this is nothing new, but adding in a DB connection would take us further away from this goal.

2) There is guard logic[0] that prevents two connections from being called twice so if you add this here, when you run the whole test suite then that will break.

I also find not being able to run a specific test annoying.

[0]: https://github.com/pulp/pulp/blob/a828660f5fdaac279cd58ece43599cf412f6bcbd/server/pulp/server/db/connection.py#L52-L54

#3 Updated by jcline@redhat.com over 4 years ago

  • Status changed from ASSIGNED to POST

#4 Updated by Anonymous over 4 years ago

  • Status changed from POST to MODIFIED
  • % Done changed from 0 to 100

#5 Updated by semyers over 4 years ago

  • Status changed from MODIFIED to CLOSED - CURRENTRELEASE
  • Platform Release set to 2.8.1

This was released in 2.8.1.

#6 Updated by bmbouter over 1 year ago

  • Tags Pulp 2 added

Please register to edit this issue

Also available in: Atom PDF