Python vcr.use_cassette() Examples

The following are 30 code examples of vcr.use_cassette(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module vcr , or try the search function .
Example #1
Source File: entry_test.py    From contentful-management.py with MIT License 6 votes vote down vote up
def test_update_entry_field_that_was_undefined_in_the_webapp(self):
        entry = None
        with vcr.use_cassette('fixtures/entry/undefined_fields.yaml'):
            entry = CLIENT.entries(PLAYGROUND_SPACE, 'master').find('33uj74Wln2Oc02CAyEY8CK')

            self.assertEqual(entry.fields(), {})

            with vcr.use_cassette('fixtures/entry/undefined_fields_write.yaml'):
                entry.name = 'foo'

                self.assertEqual(entry.fields()['name'], 'foo')

                entry.save()

                updated_entry = CLIENT.entries(PLAYGROUND_SPACE, 'master').find('33uj74Wln2Oc02CAyEY8CK')

                self.assertEqual(updated_entry.fields(), {'name': 'foo'}) 
Example #2
Source File: api_key_test.py    From contentful-management.py with MIT License 6 votes vote down vote up
def test_update_api_key_with_new_environment(self):
        api_key = CLIENT.api_keys(PLAYGROUND_SPACE).find('5mxNhKOZYOp1wzafOR9qPw')

        with vcr.use_cassette('fixtures/api_key/update_key.yaml'):
            self.assertEqual(len(api_key.environments), 1)
            self.assertEqual(api_key.environments[0].id, 'testing')

            api_key.environments.append(
                Link({
                    'sys': {
                        'id': 'master',
                        'type': 'Link',
                        'linkType': 'Environment'
                    }
                })
            )

            api_key.save()

            self.assertEqual(len(api_key.environments), 2) 
Example #3
Source File: test_sql_validator.py    From spectacles with MIT License 6 votes vote down vote up
def validator_fail_with_warning(
        self, record_mode, validator
    ) -> Iterable[Tuple[SqlValidator, Dict]]:
        with vcr.use_cassette(
            "tests/cassettes/test_sql_validator/fixture_validator_fail_with_warning.yaml",
            match_on=["uri", "method", "raw_body"],
            filter_headers=["Authorization"],
            record_mode=record_mode,
        ):
            # Move to dev mode to test conditional logic warning
            validator.client.update_workspace("eye_exam", "dev")
            validator.client.checkout_branch("eye_exam", "pytest")

            validator.build_project(selectors=["eye_exam/users__fail_and_warn"])
            results = validator.validate(mode="hybrid")
            yield validator, results 
Example #4
Source File: test_s3.py    From gbdxtools with MIT License 6 votes vote down vote up
def test_s3_delete_delimiter(self):
        """
        See the pre_load_s3_data functions for details on the bucket 
        contents. structure is as follows:

        readme.txt
        images/myimages{0-499}.tif
        scripts/myscripts{0-399}.py
        scripts/subdir/otherscripts{0-109}.sh
        """
        # Test delete multiple files
        assert len(self.s3.list_contents("scripts/", delimiter="/")) == 400
        self.s3.delete("scripts/", delimiter="/")
        assert len(self.s3.list_contents("scripts/", delimiter="/")) == 0

    #@vcr.use_cassette(cassette_name, filter_headers=['authorization'])
    #def test_download(self):
    #    location = 'gbdxtools/ski_areas.geojson'
    #    s = S3()
    #    s.download(location, local_dir=self._temp_path)
    #    assert os.path.isfile(os.path.join(self._temp_path, 'ski_areas.geojson')) 
Example #5
Source File: entry_test.py    From contentful-management.py with MIT License 6 votes vote down vote up
def test_update_entry_field_with_field_that_was_not_present(self):
        entry = None
        with vcr.use_cassette('fixtures/entry/added_fields_1.yaml'):
            entry = CLIENT.entries(PLAYGROUND_SPACE, 'master').find('3fTNzlQsDmge6YQEikEuME')

            self.assertEqual(entry.fields(), {'name': 'A Name', 'other': 'Other Stuff'})

            with vcr.use_cassette('fixtures/entry/added_fields_2.yaml'):
                entry.different = 'A Different Field'

                self.assertEqual(entry.different, 'A Different Field')
                self.assertEqual(entry.fields(), {'name': 'A Name', 'other': 'Other Stuff', 'different': 'A Different Field'})

                self.assertEqual(entry.to_json()['fields']['different']['en-US'], 'A Different Field')

                entry.save()

            with vcr.use_cassette('fixtures/entry/added_fields_3.yaml'):
                entry = CLIENT.entries(PLAYGROUND_SPACE, 'master').find('3fTNzlQsDmge6YQEikEuME')
                self.assertEqual(entry.different, 'A Different Field') 
Example #6
Source File: test_data_test_validator.py    From spectacles with MIT License 5 votes vote down vote up
def validator(looker_client, record_mode) -> Iterable[DataTestValidator]:
    with vcr.use_cassette(
        "tests/cassettes/test_data_test_validator/fixture_validator_init.yaml",
        match_on=["uri", "method", "raw_body"],
        filter_headers=["Authorization"],
        record_mode=record_mode,
    ):
        validator = DataTestValidator(looker_client, project="eye_exam")
        yield validator 
Example #7
Source File: test_calc.py    From limbo with MIT License 5 votes vote down vote up
def test_unicode():
    with vcr.use_cassette('test/fixtures/calc_unicode.yaml'):
        # บาท is the Thai Bhat (spelled in Thai, obvs)
        ret = on_message({"text": u"!calc 10 dollars in บาท"}, None)
        # no exception == success 
Example #8
Source File: test_wiki.py    From sdbot with MIT License 5 votes vote down vote up
def test_unicode():
    with vcr.use_cassette('test/fixtures/wiki_unicode.yaml'):
        ret = on_message({"text": u"!wiki नेपाल"}, None)
        # not blowing up == success 
Example #9
Source File: test_cfn_resource.py    From cfn-wrapper-python with MIT License 5 votes vote down vote up
def cassette(request):
    recordings_file = os.path.join(
        request.fspath.dirname,
        'vcr_recordings',
        request.function.__name__ + '.yaml'
    ).replace('test_', '')
    with vcr.use_cassette(recordings_file, record_mode='none') as cass:
        yield cass 
Example #10
Source File: test_restclient.py    From tiingo-python with MIT License 5 votes vote down vote up
def test_invalid_url(self):
        with self.assertRaisesRegexp(RestClientError, "404"),\
                vcr.use_cassette('tests/fixtures/invalid_url.yaml'):
            # Should return 404 error
            self._client._request('GET', "bing_is_great") 
Example #11
Source File: test_restclient.py    From tiingo-python with MIT License 5 votes vote down vote up
def test_valid_url(self):
        with vcr.use_cassette('tests/fixtures/valid_url.yaml'):
            response = self._client._request('GET', "")
        self.assertEqual(response.status_code, 200)

    # Test 404 error 
Example #12
Source File: test_restclient.py    From tiingo-python with MIT License 5 votes vote down vote up
def test_invalid_url(self):
        with self.assertRaisesRegexp(RestClientError, "404"),\
                vcr.use_cassette('tests/fixtures/invalid_url.yaml'):
            # Should return 404 error
            self._client._request('GET', "bing_is_great")

    # Todo: try using an invalid HTTP method (i.e. SNAG) and catch the error


# Check if everything still works when a session is reused
# TODO: Figure how how to refactor so that we can run these same 3 tests,
# except with 2 different types of client. 
Example #13
Source File: test_the_pirate_bay.py    From we-get with MIT License 5 votes vote down vote up
def test_search():
    import vcr
    from we_get.modules.the_pirate_bay import the_pirate_bay
    cl = the_pirate_bay('')
    cl.search_query = 'ubuntu'
    with vcr.use_cassette('fixtures/test_the_pirate_bay_test_search.yaml'):
        res = cl.search()
        assert res
        assert any('user_status' in res[k] for k in res)
        assert any('vip' == res[k]['user_status'] for k in res)
        assert any('trusted' == res[k]['user_status'] for k in res) 
Example #14
Source File: test_commit.py    From limbo with MIT License 5 votes vote down vote up
def test_commit():
  with vcr.use_cassette('test/fixtures/commit.yaml'):
    ret = on_message({"text": u"!commit"}, None)
    assert 'stuff' in ret 
Example #15
Source File: test_weather.py    From sdbot with MIT License 5 votes vote down vote up
def test_basic():
    with vcr.use_cassette('test/fixtures/weather_basic.yaml'):
        ret = on_message({"text": u"!weather Oahu, HI"}, None)
        assert ":cloud: Sat 71" in ret 
Example #16
Source File: test_stock.py    From sdbot with MIT License 5 votes vote down vote up
def test_price():
    with vcr.use_cassette('test/fixtures/stock_none'):
        ret = on_message({"text": u"the price is $12.43"}, None)
        eq_(ret, None) 
Example #17
Source File: test_stock.py    From sdbot with MIT License 5 votes vote down vote up
def test_multiple():
    with vcr.use_cassette('test/fixtures/stock_multiple.yaml'):
        ret = on_message({"text": u"$goog $aapl"}, None)
        assert 'Google Inc' in ret 
Example #18
Source File: test_stock.py    From sdbot with MIT License 5 votes vote down vote up
def test_unicode():
    with vcr.use_cassette('test/fixtures/stock_unicode.yaml'):
        ret = on_message({"text": u"$äapl"}, None)
        eq_(ret, None) 
Example #19
Source File: test_stock.py    From sdbot with MIT License 5 votes vote down vote up
def test_nonexistent():
    with vcr.use_cassette('test/fixtures/stock_none'):
        ret = on_message({"text": u"bana"}, None)
        eq_(ret, None) 
Example #20
Source File: test_stock.py    From sdbot with MIT License 5 votes vote down vote up
def test_apple():
    with vcr.use_cassette('test/fixtures/stock_apple.yaml'):
        ret = on_message({"text": u"$aapl"}, None)
        assert ':chart_with_upwards_trend:' in ret
        assert 'Apple Inc.' in ret
        assert '130.41' in ret
        assert '+1.62' in ret 
Example #21
Source File: test_stockphoto.py    From sdbot with MIT License 5 votes vote down vote up
def test_basic():
    with vcr.use_cassette('test/fixtures/stockphoto_basic.yaml'):
        ret = on_message({"text": u"!stock woman eating salad"}, None)
        assert ret in women_eating_salad 
Example #22
Source File: test_gif.py    From sdbot with MIT License 5 votes vote down vote up
def test_unicode():
    with vcr.use_cassette('test/fixtures/gif_unicode.yaml'):
        ret = on_message({"text": u"!gif Mötörhead"}, None)
        # not blowing up == success, for our purposes 
Example #23
Source File: test_gif.py    From sdbot with MIT License 5 votes vote down vote up
def test_gif():
    with vcr.use_cassette('test/fixtures/gif_bananas.yaml'):
        ret = on_message({"text": u"!gif bananas"}, None)
        assert ret in bananas_gifs, "{0} not in {1}".format(ret, bananas_gifs) 
Example #24
Source File: test_image.py    From sdbot with MIT License 5 votes vote down vote up
def test_unicode():
    with vcr.use_cassette('test/fixtures/image_unicode.yaml'):
        ret = on_message({"text": u"!image Mötörhead"}, None)
        # not blowing up == success, for our purposes 
Example #25
Source File: test_image.py    From sdbot with MIT License 5 votes vote down vote up
def test_image():
    with vcr.use_cassette('test/fixtures/image_bananas.yaml'):
        ret = on_message({"text": u"!image bananas"}, None)
        assert ret in bananas_images, "{0} not in {1}".format(ret, bananas_images) 
Example #26
Source File: test_youtube.py    From sdbot with MIT License 5 votes vote down vote up
def test_unicode():
    with vcr.use_cassette('test/fixtures/youtube_unicode.yaml'):
        ret = on_message({"text": u"!youtube 崖の上のポニョ"}, None)
        # not blowing up == success 
Example #27
Source File: test_youtube.py    From sdbot with MIT License 5 votes vote down vote up
def test_basic():
    with vcr.use_cassette('test/fixtures/youtube_basic.yaml'):
        ret = on_message({"text": u"!youtube live long and prosper"}, None)
        assert ret == "https://www.youtube.com/watch?v=DyiWkWcR86I" 
Example #28
Source File: test_commit.py    From sdbot with MIT License 5 votes vote down vote up
def test_commit():
  with vcr.use_cassette('test/fixtures/commit.yaml'):
    ret = on_message({"text": u"!commit"}, None)
    assert 'stuff' in ret 
Example #29
Source File: test_calc.py    From sdbot with MIT License 5 votes vote down vote up
def test_unicode():
    with vcr.use_cassette('test/fixtures/calc_unicode.yaml'):
        # บาท is the Thai Bhat (spelled in Thai, obvs)
        ret = on_message({"text": u"!calc 10 dollars in บาท"}, None)
        # no exception == success 
Example #30
Source File: test_calc.py    From sdbot with MIT License 5 votes vote down vote up
def test_calc():
    with vcr.use_cassette('test/fixtures/calc_basic.yaml'):
        ret = on_message({"text": u"!calc 2469*5"}, None)
        assert '12,345' in ret