Exemple #1
0
    def test_download_binary_file(self):
        """Verify that cassette can store a binary file (e.g. picture)"""

        # An image
        with open(IMAGE_FILENAME) as image_handle:
            expected_image = image_handle.read()

        # downloaded via urllib
        cassette.insert(self.filename, file_format=self.file_format)
        actual_image = urllib2.urlopen(TEST_URL_IMAGE).read()
        cassette.eject()

        # has a matching image
        self.assertEqual(self.had_response.called, False)
        self.assertEqual(expected_image, actual_image)

        self.had_response.reset_mock()

        # downloaded again via urllib
        cassette.insert(self.filename, file_format=self.file_format)
        actual_image = urllib2.urlopen(TEST_URL_IMAGE).read()
        cassette.eject()

        # still has a matching image
        self.assertEqual(self.had_response.called, True)
        self.assertEqual(expected_image, actual_image)
Exemple #2
0
    def test_download_binary_file(self):
        """Verify that cassette can store a binary file (e.g. picture)"""

        # An image
        with open(IMAGE_FILENAME) as image_handle:
            expected_image = image_handle.read()

        # downloaded via urllib
        cassette.insert(self.filename, file_format=self.file_format)
        actual_image = urllib2.urlopen(TEST_URL_IMAGE).read()
        cassette.eject()

        # has a matching image
        self.assertEqual(self.had_response.called, False)
        self.assertEqual(expected_image, actual_image)

        self.had_response.reset_mock()

        # downloaded again via urllib
        cassette.insert(self.filename, file_format=self.file_format)
        actual_image = urllib2.urlopen(TEST_URL_IMAGE).read()
        cassette.eject()

        # still has a matching image
        self.assertEqual(self.had_response.called, True)
        self.assertEqual(expected_image, actual_image)
    def generate_large_cassette(self):
        # Record every next request
        cassette.insert(CASSETTE_FILENAME)

        # Create 100 requests to load in
        for i in range(0, 100):
            url = '%s?%s' % (TEST_URL, i)
            urllib2.urlopen(url).read()

        # Write out to files
        cassette.eject()
Exemple #4
0
    def generate_large_cassette_json(self):
        """Generate a large set of responses and store in JSON."""
        # Record every next request
        cassette.insert(self.filename, file_format='json')

        # Create 100 requests to load in
        for i in range(0, 100):
            url = '%s?%s' % (TEST_URL, i)
            urllib2.urlopen(url).read()

        # Write out to files
        cassette.eject()
    def generate_large_cassette_json(self):
        """Generate a large set of responses and store in JSON."""
        # Record every next request
        cassette.insert(self.filename, file_format='json')

        # Create 100 requests to load in
        for i in range(0, 100):
            url = '%s?%s' % (TEST_URL, i)
            urllib2.urlopen(url).read()

        # Write out to files
        cassette.eject()
    def fetch_frequent_cassette(self):
        # 100 times in a row
        for i in range(0, 100):
            # Open cassette
            cassette.insert(CASSETTE_FILENAME)

            # Make a few requests
            for j in range(0, 5):
                url = '%s?%s' % (TEST_URL, j)
                urllib2.urlopen(url).read()

            # Close cassette
            cassette.eject()
Exemple #7
0
    def fetch_frequent_cassette_json(self):
        """Make repeated fetches of the same url in JSON file storage."""
        # 100 times in a row
        for i in range(0, 100):
            # Open cassette
            cassette.insert(self.filename, file_format='json')

            # Make a few requests
            for j in range(0, 5):
                url = '%s?%s' % (TEST_URL, j)
                urllib2.urlopen(url).read()

            # Close cassette
            cassette.eject()
    def fetch_frequent_cassette_json(self):
        """Make repeated fetches of the same url in JSON file storage."""
        # 100 times in a row
        for i in range(0, 100):
            # Open cassette
            cassette.insert(self.filename, file_format='json')

            # Make a few requests
            for j in range(0, 5):
                url = '%s?%s' % (TEST_URL, j)
                urllib2.urlopen(url).read()

            # Close cassette
            cassette.eject()
Exemple #9
0
    def test_flow_manual_context(self):
        """Verify the cassette behavior when setting up the context."""

        # First run
        cassette.insert(self.filename, file_format=self.file_format)
        r = urllib2.urlopen(TEST_URL + '?manual')
        cassette.eject()

        self.assertEqual(self.had_response.called, False)
        self.assertEqual(r.read(), "hello world")

        self.had_response.reset_mock()

        # Second run
        cassette.insert(self.filename, file_format=self.file_format)
        r = urllib2.urlopen(TEST_URL + '?manual')
        cassette.eject()

        self.assertEqual(self.had_response.called, True)
        self.assertEqual(r.read(), "hello world")
Exemple #10
0
    def test_flow_manual_context(self):
        """Verify the cassette behavior when setting up the context."""

        # First run
        cassette.insert(self.filename, file_format=self.file_format)
        r = urllib2.urlopen(TEST_URL + '?manual')
        cassette.eject()

        self.assertEqual(self.had_response.called, False)
        self.assertEqual(r.read(), "hello world")

        self.had_response.reset_mock()

        # Second run
        cassette.insert(self.filename, file_format=self.file_format)
        r = urllib2.urlopen(TEST_URL + '?manual')
        cassette.eject()

        self.assertEqual(self.had_response.called, True)
        self.assertEqual(r.read(), "hello world")