Ejemplo n.º 1
0
    def test_create_new_cassette_library_with_extension(self):
        """Verify correct encoder is attached to a file CassetteLibrary."""
        filename = os.path.join(TEMPORARY_RESPONSES_ROOT, 'tmp.json')
        lib = CassetteLibrary.create_new_cassette_library(filename, '')
        self.assertTrue(isinstance(lib, FileCassetteLibrary))
        self.assertTrue(isinstance(lib.encoder, JsonEncoder))

        filename = os.path.join(TEMPORARY_RESPONSES_ROOT, 'tmp.yaml')
        lib = CassetteLibrary.create_new_cassette_library(filename, '')
        self.assertTrue(isinstance(lib, FileCassetteLibrary))
        self.assertTrue(isinstance(lib.encoder, YamlEncoder))
    def test_create_new_cassette_library_with_extension(self):
        """Verify correct encoder is attached to a file CassetteLibrary."""
        filename = os.path.join(TEMPORARY_RESPONSES_ROOT, 'tmp.json')
        lib = CassetteLibrary.create_new_cassette_library(filename, '')
        self.assertTrue(isinstance(lib, FileCassetteLibrary))
        self.assertTrue(isinstance(lib.encoder, JsonEncoder))

        filename = os.path.join(TEMPORARY_RESPONSES_ROOT, 'tmp.yaml')
        lib = CassetteLibrary.create_new_cassette_library(filename, '')
        self.assertTrue(isinstance(lib, FileCassetteLibrary))
        self.assertTrue(isinstance(lib.encoder, YamlEncoder))
    def test_create_new_cassette_library_with_extension_and_file_type(self):
        """Verify correct encoder is attached with encoder override.

        Specifying file format takes precedent over the file extension.
        """
        # Manual enforcement of encoding overrides file type
        filename = os.path.join(TEMPORARY_RESPONSES_ROOT, 'tmp.json')
        lib = CassetteLibrary.create_new_cassette_library(filename, 'yaml')
        self.assertTrue(isinstance(lib, FileCassetteLibrary))
        self.assertTrue(isinstance(lib.encoder, YamlEncoder))

        # Manual enforcement of encoding overrides file type
        filename = os.path.join(TEMPORARY_RESPONSES_ROOT, 'tmp.yaml')
        lib = CassetteLibrary.create_new_cassette_library(filename, 'json')
        self.assertTrue(isinstance(lib, FileCassetteLibrary))
        self.assertTrue(isinstance(lib.encoder, JsonEncoder))
Ejemplo n.º 4
0
    def test_create_new_cassette_library_with_extension_and_file_type(self):
        """Verify correct encoder is attached with encoder override.

        Specifying file format takes precedent over the file extension.
        """
        # Manual enforcement of encoding overrides file type
        filename = os.path.join(TEMPORARY_RESPONSES_ROOT, 'tmp.json')
        lib = CassetteLibrary.create_new_cassette_library(filename, 'yaml')
        self.assertTrue(isinstance(lib, FileCassetteLibrary))
        self.assertTrue(isinstance(lib.encoder, YamlEncoder))

        # Manual enforcement of encoding overrides file type
        filename = os.path.join(TEMPORARY_RESPONSES_ROOT, 'tmp.yaml')
        lib = CassetteLibrary.create_new_cassette_library(filename, 'json')
        self.assertTrue(isinstance(lib, FileCassetteLibrary))
        self.assertTrue(isinstance(lib.encoder, JsonEncoder))
Ejemplo n.º 5
0
def insert(filename, file_format=''):
    """Setup cassette.

    :param filename: path to where requests and responses will be stored.
    """
    global cassette_library

    cassette_library = CassetteLibrary.create_new_cassette_library(
        filename, file_format)
    patch(cassette_library)
Ejemplo n.º 6
0
def insert(filename, file_format=''):
    """Setup cassette.

    :param filename: path to where requests and responses will be stored.
    """
    global cassette_library

    cassette_library = CassetteLibrary.create_new_cassette_library(
        filename, file_format)
    patch(cassette_library)
    def test_create_new_cassette_library_errors(self):
        """Verify correct errors are raised."""
        self.create_bad_files()

        # Check to see that proper error handling is occuring for malformed file
        with self.assertRaises(IOError):
            CassetteLibrary.create_new_cassette_library(BAD_FILE, '')

        with self.assertRaises(IOError):
            CassetteLibrary.create_new_cassette_library(BAD_DIRECTORY, '')

        # Check to see if unsupported encoding raises error
        with self.assertRaises(KeyError):
            CassetteLibrary.create_new_cassette_library(BAD_DIRECTORY, 'derp')
Ejemplo n.º 8
0
    def test_create_new_cassette_library_errors(self):
        """Verify correct errors are raised."""
        self.create_bad_files()

        # Check to see that proper error handling is occuring for malformed file
        with self.assertRaises(IOError):
            CassetteLibrary.create_new_cassette_library(BAD_FILE, '')

        with self.assertRaises(IOError):
            CassetteLibrary.create_new_cassette_library(BAD_DIRECTORY, '')

        # Check to see if unsupported encoding raises error
        with self.assertRaises(KeyError):
            CassetteLibrary.create_new_cassette_library(BAD_DIRECTORY, 'derp')
 def test_create_new_cassette_library_with_directory(self):
     """Verify correct encoder is attached to a directory CassetteLibrary."""
     filename = os.path.join(TEMPORARY_RESPONSES_ROOT, 'tmp')
     lib = CassetteLibrary.create_new_cassette_library(filename, '')
     self.assertTrue(isinstance(lib, DirectoryCassetteLibrary))
     self.assertTrue(isinstance(lib.encoder, JsonEncoder))
Ejemplo n.º 10
0
 def __init__(self, path, file_format='', config=None):
     self.library = CassetteLibrary.create_new_cassette_library(
         path, file_format, config)
Ejemplo n.º 11
0
 def test_create_new_cassette_library_with_directory(self):
     """Verify correct encoder is attached to a directory CassetteLibrary."""
     filename = os.path.join(TEMPORARY_RESPONSES_ROOT, 'tmp')
     lib = CassetteLibrary.create_new_cassette_library(filename, '')
     self.assertTrue(isinstance(lib, DirectoryCassetteLibrary))
     self.assertTrue(isinstance(lib.encoder, JsonEncoder))