当前位置: 首页>>代码示例>>Python>>正文


Python Betamax.use_cassette方法代码示例

本文整理汇总了Python中betamax.Betamax.use_cassette方法的典型用法代码示例。如果您正苦于以下问题:Python Betamax.use_cassette方法的具体用法?Python Betamax.use_cassette怎么用?Python Betamax.use_cassette使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在betamax.Betamax的用法示例。


在下文中一共展示了Betamax.use_cassette方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestBetamax

# 需要导入模块: from betamax import Betamax [as 别名]
# 或者: from betamax.Betamax import use_cassette [as 别名]
class TestBetamax(unittest.TestCase):
    def setUp(self):
        self.session = Session()
        self.vcr = Betamax(self.session)

    def test_initialization_does_alter_the_session(self):
        for v in self.session.adapters.values():
            assert not isinstance(v, BetamaxAdapter)
            assert isinstance(v, HTTPAdapter)

    def test_entering_context_alters_adapters(self):
        with self.vcr:
            for v in self.session.adapters.values():
                assert isinstance(v, BetamaxAdapter)

    def test_exiting_resets_the_adapters(self):
        with self.vcr:
            pass
        for v in self.session.adapters.values():
            assert not isinstance(v, BetamaxAdapter)

    def test_current_cassette(self):
        assert self.vcr.current_cassette is None
        self.vcr.use_cassette('test')
        assert isinstance(self.vcr.current_cassette, Cassette)

    def test_use_cassette_returns_cassette_object(self):
        assert self.vcr.use_cassette('test') is self.vcr

    def test_register_request_matcher(self):
        class FakeMatcher(object):
            name = 'fake'

        Betamax.register_request_matcher(FakeMatcher)
        assert 'fake' in matchers.matcher_registry
        assert isinstance(matchers.matcher_registry['fake'], FakeMatcher)

    def test_stores_the_session_instance(self):
        assert self.session is self.vcr.session

    def test_replaces_all_adapters(self):
        mount_point = 'fake_protocol://'
        s = Session()
        s.mount(mount_point, HTTPAdapter())
        with Betamax(s):
            adapter = s.adapters.get(mount_point)
            assert adapter is not None
            assert isinstance(adapter, BetamaxAdapter)
开发者ID:Hasimir,项目名称:betamax,代码行数:50,代码来源:test_betamax.py

示例2: test_creates_new_cassettes

# 需要导入模块: from betamax import Betamax [as 别名]
# 或者: from betamax.Betamax import use_cassette [as 别名]
 def test_creates_new_cassettes(self):
     recorder = Betamax(self.session)
     opts = {'record': 'new_episodes'}
     cassette_name = 'test_record_new_makes_new_cassettes'
     with recorder.use_cassette(cassette_name, **opts) as betamax:
         self.cassette_path = betamax.current_cassette.cassette_path
         self.session.get('https://httpbin.org/get')
开发者ID:arhoyling,项目名称:betamax,代码行数:9,代码来源:test_record_modes.py

示例3: helium_recorder

# 需要导入模块: from betamax import Betamax [as 别名]
# 或者: from betamax.Betamax import use_cassette [as 别名]
def helium_recorder(request):
    """Generate and start a recorder using a helium.Client."""
    cassette_name = ''

    if request.module is not None:
        cassette_name += request.module.__name__ + '.'

    if request.cls is not None:
        cassette_name += request.cls.__name__ + '.'

    cassette_name += request.function.__name__

    session = helium_commander.Client(base_url=API_URL)
    session.token_auth(API_TOKEN)
    recorder = Betamax(session)

    recorder.use_cassette(cassette_name)
    recorder.start()
    request.addfinalizer(recorder.stop)
    return recorder
开发者ID:helium,项目名称:helium-commander,代码行数:22,代码来源:conftest.py

示例4: TestContentService

# 需要导入模块: from betamax import Betamax [as 别名]
# 或者: from betamax.Betamax import use_cassette [as 别名]
class TestContentService():

    def setup(self):
        session = Session()
        self.betamax = Betamax(session)
        self.cs = ContentService(url=URL, apikey=APIKEY, session=session)

    def test_checkassets(self):
        # curl -X POST -H "Authorization: deconst ${APIKEY}" \
        #   http://dockerdev:9000/assets \
        #   -F [email protected]/fixtures/assets/foo/aaa.jpg \
        #   -F [email protected]/fixtures/assets/bar/bbb.gif

        with self.betamax.use_cassette('checkassets'):
            response = self.cs.checkassets({
                'foo/aaa.jpg': 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
                'bar/bbb.gif': '8810ad581e59f2bc3928b261707a71308f7e139eb04820366dc4d5c18d980225',
                'baz/missing.css': 'ffa63583dfa6706b87d284b86b0d693a161e4840aad2c5cf6b5d27c3b9621f7d'
            })

            assert_equal(response, {
                'foo/aaa.jpg': '/__local_asset__/aaa-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.jpg',
                'bar/bbb.gif': None,
                'baz/missing.css': None
            })

    def test_bulkasset(self):
        with self.betamax.use_cassette('bulkasset'):
            tarball = io.BytesIO()
            tf = tarfile.open(fileobj=tarball, mode='w:gz')
            add_tar_entry(tf, 'bar/bbb.gif')
            add_tar_entry(tf, 'foo/aaa.jpg')
            tf.close()

            response = self.cs.bulkasset(tarball.getvalue())

            assert_equal(response, {
                'bar/bbb.gif': '/__local_asset__/bbb-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.gif',
                'foo/aaa.jpg': '/__local_asset__/aaa-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.jpg'
            })

    def test_checkcontent(self):
        # curl -X PUT -H "Authorization: deconst ${APIKEY}" \
        #   -H 'Content-Type: application/json' \
        #   http://dockerdev:9000/content/https%3A%2F%2Fgithub.com%2Forg%2Frepo%2Fone \
        #   -d '{"title":"one","body":"one"}'

        # echo -n '{"body":"one","title":"one"}' | shasum -a 256

        # curl -X PUT -H "Authorization: deconst ${APIKEY}" \
        #   -H 'Content-Type: application/json' \
        #   http://dockerdev:9000/content/https%3A%2F%2Fgithub.com%2Forg%2Frepo%2Ftwo \
        #   -d '{"title":"two","body":"two"}'

        # echo -n '{"body":"two","title":"two"}' | shasum -a 256

        with self.betamax.use_cassette('checkcontent'):
            response = self.cs.checkcontent({
                'https://github.com/org/repo/one': '842d36ad29589a39fc4be06157c5c204a360f98981fc905c0b2a114662172bd8',
                'https://github.com/org/repo/two': 'f0e62392fc00c71ba3118c91b97c6f2cbfdcd75e8053fe2d9f029ebfcf6c23fe'
            })

            assert_equal(response, {
                'https://github.com/org/repo/one': True,
                'https://github.com/org/repo/two': False
            })

    def test_bulkcontent(self):
        with self.betamax.use_cassette('bulkcontent'):
            tarball = io.BytesIO()
            tf = tarfile.open(fileobj=tarball, mode='w:gz')
            add_tar_entry(
                tf,
                'https%3A%2F%2Fgithub.com%2Forg%2Frepo%2Fone.json',
                b'{"body":"one","title":"one"}')
            add_tar_entry(
                tf,
                'https%3A%2F%2Fgithub.com%2Forg%2Frepo%2Ftwo.json',
                b'{"body":"two","title":"two"}')
            tf.close()

            response = self.cs.bulkcontent(tarball.getvalue())

            assert_equal(response, {
                'accepted': 2,
                'failed': 0,
                'deleted': 0
            })
开发者ID:deconst,项目名称:submitter,代码行数:90,代码来源:content_service_test.py

示例5: TestSubmit

# 需要导入模块: from betamax import Betamax [as 别名]
# 或者: from betamax.Betamax import use_cassette [as 别名]
class TestSubmit():

    def setup(self):
        self.session = Session()
        self.betamax = Betamax(self.session)
        self.cs = ContentService(url=URL, apikey=APIKEY, session=self.session)

        assert_true(CONFIG.is_valid())

    def test_submit_assets(self):
        with self.betamax.use_cassette('test_submit_assets'):
            result = submit_assets('test/fixtures/assets', 10000, self.cs)

            assert_equal(result.uploaded, 2)
            assert_equal(result.present, 0)

            aaa, bbb = None, None
            for asset in result.asset_set.all():
                if asset.localpath == 'foo/aaa.jpg':
                    aaa = asset
                elif asset.localpath == 'bar/bbb.gif':
                    bbb = asset
                else:
                    assert_true(False, 'Unrecognized asset: {}'.format(asset.localpath))

            assert_is_not_none(aaa)
            assert_is_not_none(bbb)

            assert_equal(aaa.public_url, '/__local_asset__/aaa-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.jpg')
            assert_equal(bbb.public_url, '/__local_asset__/bbb-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.gif')

    def test_submit_assets_batches(self):
        with self.betamax.use_cassette('test_submit_assets_batches'):
            result = submit_assets('test/fixtures/batched_assets', 25000, self.cs)

            assert_equal(result.uploaded, 4)
            assert_equal(result.batches, 2)
            assert_equal(result.present, 0)

    def test_submit_envelopes(self):
        with self.betamax.use_cassette('test_submit_envelopes'):
            asset_set = AssetSet()
            asset_set.append(Asset('foo/aaa.jpg', io.BytesIO()))
            asset_set.append(Asset('bar/bbb.gif', io.BytesIO()))

            asset_set.accept_urls({
                'foo/aaa.jpg': '/__local_asset__/aaa-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.jpg',
                'bar/bbb.gif': '/__local_asset__/bbb-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.gif'
            })

            result = submit_envelopes(
                'test/fixtures/envelopes',
                asset_set,
                'https://github.com/org/repo/',
                self.cs
            )

            assert_equal(result.uploaded, 3)
            assert_equal(result.present, 0)
            assert_equal(result.failed, 0)

            one, two, three = None, None, None
            for envelope in result.envelope_set.all():
                if envelope.content_id() == 'https://github.com/org/repo/one':
                    one = envelope
                elif envelope.content_id() == 'https://github.com/org/repo/two':
                    two = envelope
                elif envelope.content_id() == 'https://github.com/org/repo/three':
                    three = envelope
                else:
                    assert_true(False, 'Unrecognized envelope: {}'.format(envelope.content_id()))

            assert_is_not_none(one)
            assert_is_not_none(two)
            assert_is_not_none(three)

    def test_submit_success(self):
        # Record this one with an empty content service.
        with self.betamax.use_cassette('test_submit_success'):
            result = submit(CONFIG, self.session)

            assert_equal(result.asset_result.uploaded, 2)
            assert_equal(result.asset_result.present, 0)
            assert_equal(result.envelope_result.uploaded, 3)
            assert_equal(result.envelope_result.present, 0)
            assert_equal(result.envelope_result.deleted, 0)
            assert_equal(result.envelope_result.failed, 0)
            assert_equal(result.state, SUCCESS)

    def test_submit_noop(self):
        # Record this one with an empty content service.
        with self.betamax.use_cassette('test_submit_noop'):
            result = submit(CONFIG, self.session)

            assert_equal(result.asset_result.uploaded, 0)
            assert_equal(result.asset_result.present, 2)
            assert_equal(result.envelope_result.uploaded, 0)
            assert_equal(result.envelope_result.present, 3)
            assert_equal(result.envelope_result.deleted, 0)
            assert_equal(result.envelope_result.failed, 0)
#.........这里部分代码省略.........
开发者ID:deconst,项目名称:submitter,代码行数:103,代码来源:submit_test.py

示例6: setup

# 需要导入模块: from betamax import Betamax [as 别名]
# 或者: from betamax.Betamax import use_cassette [as 别名]
class TestUSNO_Data:
    def setup(self):
        self.lat = 51.0 + 32.0/60.0
        self.lng = -22.0/60.0
        self.year = 2015
        self.usno_data = USNO_Data(self.lat, self.lng)
        self.recorder = Betamax(self.usno_data.session, default_cassette_options={
            'record_mode': 'once',
            'match_requests_on': ['method', 'uri', 'headers'],
            'preserve_exact_body_bytes': True
        })

    def test_angle_components(self):
        (direction, degrees, minutes) = USNO_Data.angle_components(self.lat)
        assert direction == 1
        assert degrees == 51
        assert minutes == 32

    def test_parameters(self):
        expected_parameters = {
            "FFX": "2",
            "xxy": "2015",
            "type": "0",
            "place": "",
            "xx0": "-1",
            "xx1": "0",
            "xx2": "22",
            "yy0": "1",
            "yy1": "51",
            "yy2": "32",
            "zz0": "1",
            "zz1": "0",
            "ZZZ": "END"
        }
        self.usno_data.year = 2015
        assert self.usno_data.parameters() == expected_parameters

    def test_as_datetime(self):
        date = USNO_Data.as_datetime(self.year, 2, 22, '2153')
        assert date.year == self.year
        assert date.month == 2
        assert date.day == 22
        assert date.hour == 21
        assert date.minute == 53
        assert date.second == 0
        assert date.utcoffset() is None

    def test_day_of_year(self):
        assert USNO_Data.day_of_year(2015, 2, 22) == 53
        assert USNO_Data.day_of_year(2016, 4, 1) == 92

    def test_get_data(self):
        with self.recorder.use_cassette('get_data'):
            self.usno_data.get_data(self.year)
            assert self.usno_data.sunrises[-1] == USNO_Data.as_datetime(self.year, 12, 31, '0807')
            assert self.usno_data.sunsets[-1] == USNO_Data.as_datetime(self.year, 12, 31, '1601')

    def test_sunrise(self):
        with self.recorder.use_cassette('get_sunrise'):
            self.usno_data.get_data(self.year)
            sunrise = self.usno_data.sunrise(2, 22)
            assert sunrise.hour == 7
            assert sunrise.minute == 2

    def test_sunset(self):
        with self.recorder.use_cassette('get_sunset'):
            self.usno_data.get_data(self.year)
            sunset = self.usno_data.sunset(2, 22)
            assert sunset.hour == 17
            assert sunset.minute == 29
开发者ID:mygulamali,项目名称:rajab_roza,代码行数:72,代码来源:test_usno_data.py


注:本文中的betamax.Betamax.use_cassette方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。