-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from uber/ca/add_report_feature
Add ability to report on unused cassette
- Loading branch information
Showing
18 changed files
with
175 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Config(dict): | ||
|
||
def __init__(self): | ||
# Defaults | ||
self['log_cassette_used'] = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import sys | ||
|
||
from cassette.cassette_library import CassetteLibrary | ||
from cassette.patcher import patch, unpatch | ||
|
||
|
||
class Player(object): | ||
|
||
def __init__(self, path, file_format='', config=None): | ||
self.library = CassetteLibrary.create_new_cassette_library( | ||
path, file_format, config) | ||
|
||
def play(self): | ||
"""Return contextenv.""" | ||
return self | ||
|
||
def __enter__(self): | ||
patch(self.library) | ||
|
||
def __exit__(self, exc_type, exc_value, tb): | ||
# If the cassette items have changed, save the changes to file | ||
if self.library.is_dirty: | ||
self.library.write_to_file() | ||
# Remove our overrides | ||
unpatch() | ||
|
||
def report_unused_cassettes(self, output=sys.stdout): | ||
"""Report unused cassettes to file.""" | ||
self.library.report_unused_cassettes(output) |
Empty file.
Empty file.
1 change: 1 addition & 0 deletions
1
...httpbin.org_80_get_01abfc750a0c942167651c40d088531d_c2585c6aafb8fa06dc8bb6de88f9de0b.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"status": 200, "raw_headers": ["Server: nginx\r\n", "Date: Thu, 12 Mar 2015 18:43:47 GMT\r\n", "Content-Type: application/json\r\n", "Content-Length: 205\r\n", "Connection: close\r\n", "Access-Control-Allow-Origin: *\r\n", "Access-Control-Allow-Credentials: true\r\n"], "content": "{\n \"args\": {}, \n \"headers\": {\n \"Accept-Encoding\": \"identity\", \n \"Host\": \"httpbin.org\", \n \"User-Agent\": \"Python-urllib/2.7\"\n }, \n \"origin\": \"8.26.157.128\", \n \"url\": \"http://httpbin.org/get\"\n}\n", "headers": {"content-length": "205", "server": "nginx", "connection": "close", "access-control-allow-credentials": "true", "date": "Thu, 12 Mar 2015 18:43:47 GMT", "access-control-allow-origin": "*", "content-type": "application/json"}, "reason": "OK", "version": 11, "length": 0} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import urllib2 | ||
from cStringIO import StringIO | ||
|
||
from cassette.player import Player | ||
|
||
|
||
def test_report_unused(): | ||
config = {'log_cassette_used': True} | ||
player = Player('./cassette/tests/data/requests/', config=config) | ||
with player.play(): | ||
urllib2.urlopen('http://httpbin.org/get') | ||
|
||
content = StringIO() | ||
player.report_unused_cassettes(content) | ||
content.seek(0) | ||
expected = ('httplib_GET_httpbin.org_80__unused.json\n' | ||
'httplib_GET_httpbin.org_80__unused2.json') | ||
assert content.read() == expected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.