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


Python Mock.META方法代码示例

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


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

示例1: test_auth_api_meta

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import META [as 别名]
    def test_auth_api_meta(self):
        request = Mock()
        request_text = base64.encodestring('test1:123')
        request.META = {"HTTP_AUTHORIZATION": "basic %s" % request_text}
        ok_(basic_auth_api(request))

        request = Mock()
        request_text = base64.encodestring('test1:1234')
        request.META = {"HTTP_AUTHORIZATION": "basic %s" % request_text}
        ok_(not basic_auth_api(request))

        request = Mock()
        request_text = base64.encodestring('test123:1234')
        request.META = {"HTTP_AUTHORIZATION": "basic %s" % request_text}
        ok_(not basic_auth_api(request))
开发者ID:tianweidut,项目名称:ChemToolsWebService,代码行数:17,代码来源:tests.py

示例2: test_datastream_etag

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import META [as 别名]
    def test_datastream_etag(self):
        rqst = Mock()
        rqst.META = {}
        # DC
        etag = datastream_etag(rqst, self.obj.pid, 'DC')
        self.assertEqual(self.obj.dc.checksum, etag)

        # bogus dsid should not error
        etag = datastream_etag(rqst, self.obj.pid, 'bogus-datastream-id')
        self.assertEqual(None, etag)

        # range request 1 to end should return etag
        rqst.META = {'HTTP_RANGE': 'bytes=1-'}
        etag = datastream_etag(rqst, self.obj.pid, 'DC')
        self.assertEqual(self.obj.dc.checksum, etag)
开发者ID:WSULib,项目名称:eulfedora,代码行数:17,代码来源:test_views.py

示例3: test_get_ip_helper

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import META [as 别名]
def test_get_ip_helper(settings):
    settings.LOCAL_GEOLOCATION_IP = None

    # Given I have a request object with the `HTTP_X_FORWARDED_FOR`
    # variable set with local and remote IP addresses
    request = Mock()
    request.META = {"HTTP_X_FORWARDED_FOR": "127.0.0.1,10.0.0.1,150.164.211.1"}

    # When I call the get_ip helper, it should skip the local addresses
    # and give me the first remote address
    util.get_ip(request).should.equal("150.164.211.1")

    # If the request only contain local addresses, the output should be
    # the default unknown addr
    request.META = {"HTTP_X_FORWARDED_FOR": "127.0.0.1,10.0.0.1,10.1.1.25"}
    util.get_ip(request).should.equal("0.0.0.0")
开发者ID:Yipit,项目名称:eventlib,代码行数:18,代码来源:test_utils.py

示例4: test_process_request_empty_header

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import META [as 别名]
 def test_process_request_empty_header(self):
     request = Mock(path="/")
     request.method = "OPTIONS"
     request.META = {"HTTP_ACCESS_CONTROL_REQUEST_METHOD": ""}
     with settings_override(CORS_URLS_REGEX="^.*$"):
         response = self.middleware.process_request(request)
     self.assertIsInstance(response, HttpResponse)
开发者ID:Willet,项目名称:django-cors-headers,代码行数:9,代码来源:tests.py

示例5: test_desktop_browser_agent

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import META [as 别名]
 def test_desktop_browser_agent(self):
     request = Mock()
     request.META = {
         'HTTP_USER_AGENT': 'My Desktop Browser',
     }
     flavour = detect_mobile(request)
     self.assertEqual(flavour, 'full')
开发者ID:PCPartPicker,项目名称:django-mobile,代码行数:9,代码来源:test_base.py

示例6: test_mobile_browser_agent

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import META [as 别名]
 def test_mobile_browser_agent(self):
     request = Mock()
     request.META = {
         'HTTP_USER_AGENT': 'My Mobile Browser',
     }
     flavour = detect_mobile(request)
     self.assertEqual(flavour, 'mobile')
开发者ID:PCPartPicker,项目名称:django-mobile,代码行数:9,代码来源:test_base.py

示例7: test_sets_both

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import META [as 别名]
 def test_sets_both(self):
     """Test that both REMOTE_ADDR and HTTP_X_FORWARDED_FOR are always set"""
     mock_request = Mock()
     mock_request.META = {"HTTP_X_FORWARDED_FOR": u"8.8.8.8"}
     self.middleware.process_request(mock_request)
     self.assertEqual(mock_request.META["REMOTE_ADDR"], u"8.8.8.8")
     self.assertEqual(mock_request.META["HTTP_X_FORWARDED_FOR"], u"8.8.8.8")
开发者ID:lpatmo,项目名称:actionify_the_news,代码行数:9,代码来源:test_handle_ip.py

示例8: test_single_ip

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import META [as 别名]
 def test_single_ip(self):
     """Test that the correct IP is returned with a single remote IP"""
     mock_request = Mock()
     mock_request.META = {"HTTP_X_FORWARDED_FOR": u"8.8.8.8", "REMOTE_ADDR": u"10.228.26.24"}
     self.middleware.process_request(mock_request)
     self.assertEqual(mock_request.META["REMOTE_ADDR"], u"8.8.8.8")
     self.assertEqual(mock_request.META["HTTP_X_FORWARDED_FOR"], u"8.8.8.8")
开发者ID:lpatmo,项目名称:actionify_the_news,代码行数:9,代码来源:test_handle_ip.py

示例9: prepare_request_mock

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import META [as 别名]
    def prepare_request_mock(self, data, referer='http://localhost/user_with_workspaces/Public Workspace', user=None, extra_headers={}, GET=''):
        request = Mock()
        request.method = 'POST'
        request.get_host.return_value = 'localhost'
        GET_PARAMETERS = parse_qsl(GET)
        request.GET = MagicMock()
        request.GET.__len__.side_effect = lambda: len(GET_PARAMETERS)
        request.GET.__getitem__.side_effect = lambda key: GET_PARAMETERS[key]
        request.GET.urlencode.side_effect = lambda: GET
        request.COOKIES = {
            settings.SESSION_COOKIE_NAME: 'test',
        }
        request.META = {
            'HTTP_ACCEPT': 'application/json',
            'SERVER_PROTOCOL': 'http',
            'REMOTE_ADDR': '127.0.0.1',
            'content_type': 'application/json',
            'content_length': len(data),
            'HTTP_HOST': 'localhost',
            'HTTP_REFERER': referer,
            'HTTP_X_FI_WARE_OAUTH_TOKEN': 'true',
        }
        request.META.update(extra_headers)
        request.read.return_value = data
        if user is None:
            request.user = self.admin_mock
        else:
            request.user = user

        return request
开发者ID:GreenIDer-Donati,项目名称:wirecloud,代码行数:32,代码来源:proxy.py

示例10: test_raw_datastream_version

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import META [as 别名]
    def test_raw_datastream_version(self):
        rqst = Mock()
        rqst.method = 'GET'
        # return empty headers for ETag condition check
        rqst.META = {}

        self.obj.text.content = 'second version content'
        self.obj.text.save()

        # retrieve the view for each version and compare
        for version in self.obj.text.history().versions:

            # get the datastream version to compare with the response
            dsversion = self.obj.getDatastreamObject(self.obj.text.id,
                as_of_date=version.created)

            response = raw_datastream_old(rqst, self.obj.pid, self.obj.text.id,
                as_of_date=version.created)
            expected, got = 200, response.status_code
            self.assertEqual(expected, got,
                'Expected %s but returned %s for raw_datastream as of %s' \
                % (expected, got, version.created))
            expected, got = 'text/plain', response['Content-Type']
            self.assertEqual(expected, got,
                'Expected %s but returned %s for mimetype on raw_datastream as of %s' \
                    % (expected, got, version.created))
            # should use version-specific checksum and size
            self.assertEqual(dsversion.checksum, response['Content-MD5'],
                'datastream checksum should be set as Content-MD5 header in the response')
            self.assertEqual(dsversion.size, int(response['Content-Length']))
            # should retrieve appropriate version of the content
            self.assertEqual(dsversion.content, response.content)
开发者ID:WSULib,项目名称:eulfedora,代码行数:34,代码来源:test_views.py

示例11: test_get_ip_helper

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import META [as 别名]
def test_get_ip_helper():
    # Given I have a request object with the `HTTP_X_FORWARDED_FOR`
    # variable set with local and remote IP addresses
    request = Mock()
    request.META = {
        'HTTP_X_FORWARDED_FOR': '127.0.0.1,10.0.0.1,150.164.211.1'}

    # When I call the get_ip helper, it should skip the local addresses
    # and give me the first remote address
    util.get_ip(request).should.equal('150.164.211.1')

    # If the request only contain local addresses, the output should be
    # the default unknown addr
    request.META = {
        'HTTP_X_FORWARDED_FOR': '127.0.0.1,10.0.0.1,10.1.1.25'}
    util.get_ip(request).should.equal('0.0.0.0')
开发者ID:spulec,项目名称:eventlib,代码行数:18,代码来源:test_eventlib.py

示例12: test_process_request_empty_header

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import META [as 别名]
 def test_process_request_empty_header(self):
     request = Mock(path='/')
     request.method = 'OPTIONS'
     request.META = {'HTTP_ACCESS_CONTROL_REQUEST_METHOD': ''}
     with settings_override(CORS_URLS_REGEX='^.*$'):
         response = self.middleware.process_request(request)
     self.assertIsInstance(response, HttpResponse)
开发者ID:Mondego,项目名称:pyreco,代码行数:9,代码来源:allPythonContent.py

示例13: test_change_plan_form

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import META [as 别名]
 def test_change_plan_form(self):
     request = Mock()
     request.META = {}
     request.session = DummySession()
     user = get_user_model().objects.create_user(username="patrick")
     user.set_password("eldarion")
     user.save()
     PaymentPlan.objects.bulk_create(PLANS)
     customer = Customer.objects.create(
         stripe_id="cus_1",
         user=user
     )
     CurrentSubscription.objects.create(
         customer=customer,
         plan=PaymentPlan.objects.get(key="pro"),
         quantity=1,
         start=timezone.now(),
         status="active",
         cancel_at_period_end=False,
         amount=decimal.Decimal("19.99")
     )
     user = authenticate(username="patrick", password="eldarion")
     login(request, user)
     context = {
         "request": request
     }
     change_plan_form(context)
     self.assertTrue("form" in context)
开发者ID:justcompile,项目名称:django-stripe-payments,代码行数:30,代码来源:test_templatetags.py

示例14: test_random_source

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import META [as 别名]
 def test_random_source(self, authenticate_mock):
     backend = MozilliansAuthBackend()
     request_mock = Mock()
     request_mock.META = {'HTTP_REFERER': settings.SITE_URL + '/?source=foobar'}
     backend.request = request_mock
     backend.authenticate(request=request_mock)
     eq_(backend.referral_source, None)
开发者ID:JacksonIsaac,项目名称:mozillians,代码行数:9,代码来源:test_authbackend.py

示例15: test_is_idevice_helper

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import META [as 别名]
    def test_is_idevice_helper(self):
        """Verify that is_idevice detects iphone/ipad/ipod UAs."""
        request = Mock()
        request.META = {}

        # Detect iPad
        request.META['HTTP_USER_AGENT'] = (
            "Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) "
            "AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 "
            "Mobile/7B314 Safari/531.21.10")
        assert is_idevice(request)

        # Detect iPhone
        request.META['HTTP_USER_AGENT'] = (
            "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) "
            "AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 "
            "Safari/528.16")
        assert is_idevice(request)

        # Detect iPod
        request.META['HTTP_USER_AGENT'] = (
            "Mozilla/5.0 (iPod; U; CPU like Mac OS X; en) AppleWebKit/420.1 "
            "(KHTML,like Gecko) Version/3.0 Mobile/3A100a Safari/419.3")
        assert is_idevice(request)

        # Don't detect Firefox OS
        request.META['HTTP_USER_AGENT'] = (
            "Firefox OS UA - Mozilla/5.0 (Mobile; rv:12.0) Gecko/12.0 "
            "Firefox/12.0")
        assert not is_idevice(request)
开发者ID:runt18,项目名称:kitsune,代码行数:32,代码来源:test_helpers.py


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