Skip to content

Instantly share code, notes, and snippets.

@cpdean
Forked from anonymous/README.markdown
Created July 3, 2013 00:10

Revisions

  1. @invalid-email-address Anonymous created this gist Jul 3, 2013.
    3 changes: 3 additions & 0 deletions README.markdown
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    This is how mock.patch should be used, but I'm having some problems on my own codebase.

    It's weird, but in this tiny example everything works just fine...
    10 changes: 10 additions & 0 deletions db.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    import boto.s3.connection


    creds = {"aws_secret_access_key": "fakes",
    "aws_access_key_id": "fakes"}


    class DBConnection(object):
    def connect(self):
    return boto.s3.connection.S3Connection(**creds).get_bucket("something")
    3 changes: 3 additions & 0 deletions requirements.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    boto==2.9.6
    mock==1.0.1
    nose==1.3.0
    4 changes: 4 additions & 0 deletions service.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    import db

    def connect():
    return db.DBConnection().connect()
    8 changes: 8 additions & 0 deletions tests.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    import service
    from mock import patch


    def service_test():
    with patch("boto.s3.connection.S3Connection.get_bucket") as c:
    service.connect()
    c.assert_called_with("something")