Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8043561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:56:30+00:00 2026-06-05T04:56:30+00:00

I have a fairly complex app that uses celery, mongo, redis and pyramid. I

  • 0

I have a fairly complex app that uses celery, mongo, redis and pyramid. I use nose for testing. I’m not doing TDD (not test-first, at least), but I am trying very hard to get a decent amount of coverage. I’m stuck in the parts that are integrated with some of the above services. For example, I’m using redis for shared memory between celery tasks, but I’d like to be able to switch to memcache without too much trouble, so I’ve abstracted out the following functions:

import settings
db = StrictRedis(host=settings.db_uri, db=settings.db_name)

def has_task(correlation_id):
    """Return True if a task exists in db."""
    return db.exists(str(correlation_id))

def pop_task(correlation_id):
    """Get a task from db by correlation_id."""
    correlation_id = str(correlation_id) # no unicode allowed
    task_pickle = db.get(correlation_id)
    task = loads(task_pickle)
    if task:
        db.delete(correlation_id)
    return task

def add_task(correlation_id, task_id, model):
    """Add a task to db"""
    return db.set(str(correlation_id), dumps((task_id, model)))

I’m also doing similar things to abstract Mongo, which I’m using for persistent storage.

I’ve seen test suites for integrated web apps that run dummy http servers, create dummy requests and even dummy databases. I’m OK for celery and pyramid, but I haven’t been able to find dummies for mongo and redis, so I’m only able to run tests for the above when those services are actually running. Is there any way to provide dummy services for the above so I don’t have:

  1. to have external services installed and running, and
  2. to manually create and destroy entire databases (in-memory dummies can be counted on to cleanup after themselves)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T04:56:32+00:00Added an answer on June 5, 2026 at 4:56 am

    I would suggest you use the mock library for such tasks. This allows you to replace your production objects (for example the database connection) with some pseudo objects which could be provided with some functionality needed for testing.

    Example:

    >>> from mock import Mock
    >>> db = Mock()
    >>> db.exists.return_value = True
    >>> db.exists()
    True
    

    You can make assertions how your code interact with the mock, for example:

    >>> db.delete(1)
    <Mock name='mock.delete()' id='37588880'>
    >>> db.delete.assert_called_with(1)
    >>> db.delete.assert_called_with(2)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:\Python27\lib\site-packages\mock.py", line 863, in assert_called_with
        raise AssertionError(msg)
    AssertionError: Expected call: delete(2)
    Actual call: delete(1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web page that I use to update a fairly complex data
I have a fairly complex web app that was built (by a contractor) to
For my app, I have a fairly complex set of configuration options that user
I have an android app that is getting fairly large and complex now, and
I have an app that manages turns in a game, it's fairly complex and
In my ASP.NET MVC app, I have a fairly complex edit page which combines
I have a fairly complex view that has multiple forms, lots of validations on
I have a fairly complex Rails app built on top of Twitter's API, and
I have a fairly complex user drawn control that is double buffered. Works very
I'm part way through building a fairly complex HTML5 web app, that retrieves its

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.