Coder Social home page Coder Social logo

testinstances's Introduction

Make Integration Tests Easier

testinstances is a set of managed instance wrappers to make integration testing with redis and mongodb easier. If you have the binaries on your path, it can handle creating and destroying sandboxed instances for you to test with.

Examples

The API is straightforward and easily embedeed in setup/teardown functions. It also automatically returns a connection to the instance.:

import unittest

from testinstances import RedisInstance

class TestSomeJunk(unittest.TestCase):
  def setUp(self):
    # Set up an instance on port 12345
    self.redis = RedisInstance(12345)

  def tearDown(self):
    self.redis.terminate()

  def test_stuff(self):
    self.redis.conn.set('foo', 'bar')
    self.assertEqual(self.redis.conn.get('foo'), 'bar')

Or, if you wanted to be fancy and avoid the process creation/termination cost for every test case:

import unittest

from testinstances import MongoInstance

class TestSomeJunk(unittest.TestCase):
  @classmethod
  def setUpClass(cls):
    # Set up an instance on port 12345
    cls.mongo = MongoInstance(12345)

  @classmethod
  def tearDownClass(cls):
    cls.mongo.terminate()

  def setUp(self):
    # All instance types implement ``flush``
    self.mongo.flush()

  def test_stuff(self):
    collection = self.mongo.conn['someDB']['someCollection']
    collection.insert({'foo': 'bar'})
    self.assertEqual(collection.find({'foo': 'bar'}).next()['foo'], 'bar')

Developing

To run the tests you need to install all of the databases the tests run:

For Debian/Ubuntu:

$ sudo apt-get install redis-server mongodb-server

For OSX:

$ sudo brew install redis mongodb

Then you just run tox.

Roadmap

  • New Instance Kinds
    • Kafka
    • Zookeeper
  • Documentation and ReadTheDocs
  • Travis-CI

testinstances's People

Contributors

kbourgoin avatar emmettbutler avatar sontek avatar dannyzen avatar yungchin avatar dfdeshom avatar

Stargazers

Jonathan Barratt avatar Keith Yang avatar Dan Blanchard avatar Isaul Vargas avatar Omer Katz avatar  avatar

Watchers

Chris Wisecarver avatar sal avatar Andrew Montalenti avatar Omer Katz avatar ted kaemming avatar Martin Laprise avatar  avatar Alexey Kopytko avatar Mike Sukmanowsky avatar  avatar Alexander Ose avatar James Cloos avatar  avatar Sachin Kamdar avatar  avatar  avatar Josh Romero avatar bot user - don't ping avatar Kemper Smith avatar Cody Hiar avatar Brian Alvey avatar Caitlin McKenna avatar Will Burgess avatar alexa benatar avatar  avatar Ben Probert avatar Annelise avatar  avatar  avatar Daniel Griffin avatar

testinstances's Issues

Mongo Example in README does not function

Very cool project. Wanted to point out that the mongo example in your readme is not currently functioning.

  def TestSomeJunk(unittest.TestCase):
                             ^
SyntaxError: invalid syntax

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.