-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add generic VCR function * version, changelog
- Loading branch information
1 parent
ee7e81c
commit 1f09e55
Showing
5 changed files
with
45 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
Changelog | ||
========= | ||
|
||
2.1.0 | ||
----- | ||
|
||
- add generic VCR function to help with test implementation | ||
|
||
2.0.3 | ||
----- | ||
|
||
|
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,20 @@ | ||
import os | ||
|
||
import aiohttp | ||
from aiounittest import AsyncTestCase | ||
|
||
from cassettedeck.vcr import vcr | ||
|
||
|
||
class TestVCR(AsyncTestCase): | ||
|
||
async def test_should_store_cassette_at_expected_location(self): | ||
expected_path = os.path.join(os.path.dirname(__file__), "cassettes", f"{self.id()}.yaml") | ||
self.assertFalse(os.path.exists(expected_path)) | ||
|
||
with vcr(self): | ||
async with aiohttp.request("GET", "https://example.com") as response: | ||
response.raise_for_status() | ||
|
||
self.assertTrue(os.path.isfile(expected_path)) | ||
os.remove(expected_path) |
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 inspect | ||
import os | ||
from contextlib import contextmanager | ||
from unittest import TestCase | ||
|
||
from cassettedeck import CassetteDeck | ||
|
||
|
||
@contextmanager | ||
def vcr(test_case: TestCase): | ||
""" | ||
Test utility which allows cassettes to be stored with a unique name near their point of use. | ||
""" | ||
test_file = inspect.getfile(type(test_case)) | ||
library = os.path.join(os.path.dirname(test_file), "cassettes") | ||
my_vcr = CassetteDeck(cassette_library_dir=library, ignore_localhost=True) | ||
with my_vcr.use_cassette(f"{test_case.id()}.yaml", mode="once") as cassette: | ||
yield cassette |
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