diff options
| author | Gabriel Falcao <gabriel@nacaolivre.org> | 2011-06-28 17:08:52 -0400 |
|---|---|---|
| committer | Gabriel Falcao <gabriel@nacaolivre.org> | 2011-06-28 17:08:52 -0400 |
| commit | e70bc73defdf8756c46f8eeade2124301955ee32 (patch) | |
| tree | 18868b79d44ae8644e9b904d39dc413f565fae0a | |
| parent | 02eeb42fd98dfcf847edae67af05246ba9c1e454 (diff) | |
| download | httpretty-e70bc73defdf8756c46f8eeade2124301955ee32.tar.gz | |
improving the readme
| -rw-r--r-- | README.md | 35 |
1 files changed, 20 insertions, 15 deletions
@@ -35,33 +35,38 @@ HTTPretty will mock the response for you :) *(and also give you the latest reque ```python from httpretty import HTTPretty -HTTPretty.enable() # enable HTTPretty so that it will monkey patch the socket module -HTTPretty.register_uri(HTTPretty.GET, "http://globo.com/", - body="The biggest portal in Brazil") +def test_one(): + HTTPretty.enable() # enable HTTPretty so that it will monkey patch the socket module + HTTPretty.register_uri(HTTPretty.GET, "http://globo.com/", + body="The biggest portal in Brazil") -fd = urllib2.urlopen('http://globo.com') -got = fd.read() -fd.close() - -print got + fd = urllib2.urlopen('http://globo.com') + got = fd.read() + fd.close() -HTTPretty.disable() # disable afterwards, so that you will have no problems in coda that uses that socket module + assert got == "The biggest portal in Brazil" + HTTPretty.disable() # disable afterwards, so that you will have no problems in coda that uses that socket module ``` -**:: output ::** - - The biggest portal in Brazil - - ## ohhhh, really? can that be easier? **YES** we've got a decorator ```python +from httpretty import HTTPretty, httprettified -``` +@httprettified +def test_one(): + HTTPretty.register_uri(HTTPretty.GET, "http://globo.com/", + body="The biggest portal in Brazil") + fd = urllib2.urlopen('http://globo.com') + got = fd.read() + fd.close() + + assert got == "The biggest portal in Brazil" +``` ## mocking the status code |
