Skip to content

Instantly share code, notes, and snippets.

@chadwhitacre
Created October 16, 2012 21:27
Show Gist options
  • Save chadwhitacre/3902155 to your computer and use it in GitHub Desktop.
Save chadwhitacre/3902155 to your computer and use it in GitHub Desktop.
Testing with context managers
from gittip import testing
def test_inserting_inserts():
with testing.load() as context:
context.db.execute("INSERT INTO participants VALUES ('foo')")
actual = context.diff(compact=True)
assert actual == {"participants": [1,0,0]}, actual
def test_update_updates():
with testing.load("participants", ("foo",)) as context:
context.db.execute("UPDATE participants SET statement='BLAM!!!' "
"WHERE id='foo'")
expected = {"id": "foo", "statement": "BLAM!!!"}
actual = context.diff()['participants']['updates'][0]
assert actual == expected, actual
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment