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


Python responses.activate方法代码示例

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


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

示例1: test_callback_no_content_type

# 需要导入模块: import responses [as 别名]
# 或者: from responses import activate [as 别名]
def test_callback_no_content_type():
    body = b'test callback'
    status = 400
    reason = 'Bad Request'
    headers = {'foo': 'bar'}
    url = 'http://example.com/'

    def request_callback(request):
        return (status, headers, body)

    @responses.activate
    def run():
        responses.add_callback(
            responses.GET, url, request_callback, content_type=None)
        resp = requests.get(url)
        assert resp.text == "test callback"
        assert resp.status_code == status
        assert resp.reason == reason
        assert 'foo' in resp.headers
        assert 'Content-Type' not in resp.headers

    run()
    assert_reset() 
开发者ID:haynieresearch,项目名称:jarvis,代码行数:25,代码来源:test_responses.py

示例2: test_make_active_fails_to_start_services

# 需要导入模块: import responses [as 别名]
# 或者: from responses import activate [as 别名]
def test_make_active_fails_to_start_services(self, mocks, mock_consul):
        """
        Test make_active() and check if it's behaving correctly when the
        playbooks to start services fail
        """
        mocks.mock_run_appserver_playbooks.return_value = ('', 2)
        instance = OpenEdXInstanceFactory(internal_lms_domain='test.activate.opencraft.co.uk')
        appserver_id = instance.spawn_appserver()
        self.assertEqual(mocks.mock_load_balancer_run_playbook.call_count, 1)
        appserver = instance.appserver_set.get(pk=appserver_id)

        self.assertEqual(instance.appserver_set.get().last_activated, None)

        appserver.make_active()

        instance.refresh_from_db()
        appserver.refresh_from_db()
        self.assertEqual(mocks.mock_run_appserver_playbooks.call_count, 1)
        self.assertFalse(appserver.is_active)
        self.assertEqual(appserver.last_activated, None)
        self.assertEqual(instance.appserver_set.get().last_activated, None)
        self.assertEqual(mocks.mock_load_balancer_run_playbook.call_count, 1)
        self.assertEqual(mocks.mock_enable_monitoring.call_count, 0) 
开发者ID:open-craft,项目名称:opencraft,代码行数:25,代码来源:test_openedx_appserver.py

示例3: test_manage_instance_services

# 需要导入模块: import responses [as 别名]
# 或者: from responses import activate [as 别名]
def test_manage_instance_services(self, mocks, mock_consul):
        """
        Test if manage instance services is correctly running the playbook
        """
        instance = OpenEdXInstanceFactory(internal_lms_domain='test.activate.opencraft.co.uk')
        appserver_id = instance.spawn_appserver()
        appserver = instance.appserver_set.get(pk=appserver_id)
        expected_playbook = Playbook(
            version=None,
            source_repo=os.path.join(settings.SITE_ROOT, 'playbooks/manage_services'),
            playbook_path='manage_services.yml',
            requirements_path='requirements.txt',
            variables='services: all\nsupervisord_action: start\n'
        )

        appserver.manage_instance_services(active=True)

        self.assertEqual(mocks.mock_run_appserver_playbooks.call_count, 1)
        mocks.mock_run_appserver_playbooks.assert_called_once_with(
            playbook=expected_playbook,
            working_dir=expected_playbook.source_repo,
        ) 
开发者ID:open-craft,项目名称:opencraft,代码行数:24,代码来源:test_openedx_appserver.py

示例4: create_decorating_metaclass

# 需要导入模块: import responses [as 别名]
# 或者: from responses import activate [as 别名]
def create_decorating_metaclass(decorators, prefix='test_'):
    class DecoratingMethodsMetaclass(type):
        def __new__(cls, name, bases, namespace):
            namespace_items = tuple(namespace.items())
            for key, val in namespace_items:
                if key.startswith(prefix) and callable(val):
                    for dec in decorators:
                        val = dec(val)
                    namespace[key] = val
            return type.__new__(cls, name, bases, dict(namespace))

    return DecoratingMethodsMetaclass


# TestCase subclass that automatically decorates test methods with
# responses.activate and sets up a client instance 
开发者ID:Asana,项目名称:python-asana,代码行数:18,代码来源:helpers.py

示例5: test_response

# 需要导入模块: import responses [as 别名]
# 或者: from responses import activate [as 别名]
def test_response():
    @responses.activate
    def run():
        responses.add(responses.GET, 'http://example.com', body=b'test')
        resp = requests.get('http://example.com')
        assert_response(resp, 'test')
        assert len(responses.calls) == 1
        assert responses.calls[0].request.url == 'http://example.com/'
        assert responses.calls[0].response.content == b'test'

        resp = requests.get('http://example.com?foo=bar')
        assert_response(resp, 'test')
        assert len(responses.calls) == 2
        assert responses.calls[1].request.url == 'http://example.com/?foo=bar'
        assert responses.calls[1].response.content == b'test'

    run()
    assert_reset() 
开发者ID:haynieresearch,项目名称:jarvis,代码行数:20,代码来源:test_responses.py

示例6: test_response_with_instance

# 需要导入模块: import responses [as 别名]
# 或者: from responses import activate [as 别名]
def test_response_with_instance():
    @responses.activate
    def run():
        responses.add(
            responses.Response(
                method=responses.GET,
                url='http://example.com', ))
        resp = requests.get('http://example.com')
        assert_response(resp, '')
        assert len(responses.calls) == 1
        assert responses.calls[0].request.url == 'http://example.com/'

        resp = requests.get('http://example.com?foo=bar')
        assert_response(resp, '')
        assert len(responses.calls) == 2
        assert responses.calls[1].request.url == 'http://example.com/?foo=bar'

    run()
    assert_reset() 
开发者ID:haynieresearch,项目名称:jarvis,代码行数:21,代码来源:test_responses.py

示例7: test_match_empty_querystring

# 需要导入模块: import responses [as 别名]
# 或者: from responses import activate [as 别名]
def test_match_empty_querystring():
    @responses.activate
    def run():
        responses.add(
            responses.GET,
            'http://example.com',
            body=b'test',
            match_querystring=True)
        resp = requests.get('http://example.com')
        assert_response(resp, 'test')
        resp = requests.get('http://example.com/')
        assert_response(resp, 'test')
        with pytest.raises(ConnectionError):
            requests.get('http://example.com?query=foo')

    run()
    assert_reset() 
开发者ID:haynieresearch,项目名称:jarvis,代码行数:19,代码来源:test_responses.py

示例8: test_match_querystring_error_regex

# 需要导入模块: import responses [as 别名]
# 或者: from responses import activate [as 别名]
def test_match_querystring_error_regex():
    @responses.activate
    def run():
        """Note that `match_querystring` value shouldn't matter when passing a
        regular expression"""

        responses.add(
            responses.GET,
            re.compile(r'http://example\.com/foo/\?test=1'),
            match_querystring=True)

        with pytest.raises(ConnectionError):
            requests.get('http://example.com/foo/?test=3')

        responses.add(
            responses.GET,
            re.compile(r'http://example\.com/foo/\?test=2'),
            match_querystring=False)

        with pytest.raises(ConnectionError):
            requests.get('http://example.com/foo/?test=4')

    run()
    assert_reset() 
开发者ID:haynieresearch,项目名称:jarvis,代码行数:26,代码来源:test_responses.py

示例9: test_accept_json_body

# 需要导入模块: import responses [as 别名]
# 或者: from responses import activate [as 别名]
def test_accept_json_body():
    @responses.activate
    def run():
        content_type = 'application/json'

        url = 'http://example.com/'
        responses.add(responses.GET, url, json={"message": "success"})
        resp = requests.get(url)
        assert_response(resp, '{"message": "success"}', content_type)

        url = 'http://example.com/1/'
        responses.add(responses.GET, url, json=[])
        resp = requests.get(url)
        assert_response(resp, '[]', content_type)

    run()
    assert_reset() 
开发者ID:haynieresearch,项目名称:jarvis,代码行数:19,代码来源:test_responses.py

示例10: test_callback

# 需要导入模块: import responses [as 别名]
# 或者: from responses import activate [as 别名]
def test_callback():
    body = b'test callback'
    status = 400
    reason = 'Bad Request'
    headers = {'foo': 'bar'}
    url = 'http://example.com/'

    def request_callback(request):
        return (status, headers, body)

    @responses.activate
    def run():
        responses.add_callback(responses.GET, url, request_callback)
        resp = requests.get(url)
        assert resp.text == "test callback"
        assert resp.status_code == status
        assert resp.reason == reason
        assert 'foo' in resp.headers
        assert resp.headers['foo'] == 'bar'

    run()
    assert_reset() 
开发者ID:haynieresearch,项目名称:jarvis,代码行数:24,代码来源:test_responses.py

示例11: test_regular_expression_url

# 需要导入模块: import responses [as 别名]
# 或者: from responses import activate [as 别名]
def test_regular_expression_url():
    @responses.activate
    def run():
        url = re.compile(r'https?://(.*\.)?example.com')
        responses.add(responses.GET, url, body=b'test')

        resp = requests.get('http://example.com')
        assert_response(resp, 'test')

        resp = requests.get('https://example.com')
        assert_response(resp, 'test')

        resp = requests.get('https://uk.example.com')
        assert_response(resp, 'test')

        with pytest.raises(ConnectionError):
            requests.get('https://uk.exaaample.com')

    run()
    assert_reset() 
开发者ID:haynieresearch,项目名称:jarvis,代码行数:22,代码来源:test_responses.py

示例12: test_response_cookies

# 需要导入模块: import responses [as 别名]
# 或者: from responses import activate [as 别名]
def test_response_cookies():
    body = b'test callback'
    status = 200
    headers = {'set-cookie': 'session_id=12345; a=b; c=d'}
    url = 'http://example.com/'

    def request_callback(request):
        return (status, headers, body)

    @responses.activate
    def run():
        responses.add_callback(responses.GET, url, request_callback)
        resp = requests.get(url)
        assert resp.text == "test callback"
        assert resp.status_code == status
        assert 'session_id' in resp.cookies
        assert resp.cookies['session_id'] == '12345'
        assert resp.cookies['a'] == 'b'
        assert resp.cookies['c'] == 'd'

    run()
    assert_reset() 
开发者ID:haynieresearch,项目名称:jarvis,代码行数:24,代码来源:test_responses.py

示例13: test_okta_mfa_push_challenge

# 需要导入模块: import responses [as 别名]
# 或者: from responses import activate [as 别名]
def test_okta_mfa_push_challenge(
            self,
            mock_print_tty,
            mock_makedirs,
            mock_open,
            mock_chmod
    ):
        responses.add(
            responses.POST,
            'https://organization.okta.com/api/v1/authn',
            json=json.loads(AUTH_MFA_PUSH_RESPONSE)
        )

        responses.add(
            responses.POST,
            'https://organization.okta.com/api/v1/authn/factors/id/verify',
            json=json.loads(MFA_WAITING_RESPONSE)
        )

        responses.add(
            responses.POST,
            'https://organization.okta.com/api/v1/authn/factors/id/lifecycle/activate/poll',
            json=json.loads(AUTH_TOKEN_RESPONSE)
        )

        responses.add(
            responses.POST,
            'https://organization.okta.com/api/v1/sessions',
            json=json.loads(SESSION_RESPONSE)
        )

        okta = Okta(
            user_name="user_name",
            user_pass="user_pass",
            organization="organization.okta.com"
        )

        self.assertEqual(okta.okta_single_use_token, "single_use_token")
        self.assertEqual(okta.organization, "organization.okta.com")
        self.assertEqual(okta.okta_session_id, "session_token") 
开发者ID:godaddy,项目名称:aws-okta-processor,代码行数:42,代码来源:test_okta.py

示例14: decorate

# 需要导入模块: import responses [as 别名]
# 或者: from responses import activate [as 别名]
def decorate(cls, func):
        return moto.mock_sqs(moto.mock_sns(responses.activate(func))) 
开发者ID:tdsmith,项目名称:github-snooze-button,代码行数:4,代码来源:test_repository_listener.py

示例15: test_is_active

# 需要导入模块: import responses [as 别名]
# 或者: from responses import activate [as 别名]
def test_is_active(self, *mocks):
        """
        Test is_active property and setter
        """
        instance = OpenEdXInstanceFactory(internal_lms_domain='test.activate.opencraft.co.uk')
        appserver_id = instance.spawn_appserver()
        appserver = instance.appserver_set.get(pk=appserver_id)

        self.assertEqual(instance.appserver_set.get().last_activated, None)

        with freeze_time('2017-01-17 11:25:00') as freezed_time:
            appserver.is_active = True
        activation_time = utc.localize(freezed_time())
        self.assertTrue(appserver.is_active)

        # Re-activating doesn't change the date, since no change was made.
        appserver.is_active = True
        self.assertTrue(appserver.is_active)
        self.assertEqual(appserver.last_activated, activation_time)

        self.assertEqual(appserver.last_activated, activation_time)

        # Deactivating does not change last_activated time
        appserver.is_active = False
        self.assertFalse(appserver.is_active)
        self.assertEqual(appserver.last_activated, activation_time)

        # Re-deactivating is ok too
        appserver.is_active = False
        self.assertFalse(appserver.is_active)
        self.assertEqual(appserver.last_activated, activation_time) 
开发者ID:open-craft,项目名称:opencraft,代码行数:33,代码来源:test_openedx_appserver.py


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