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


Python http.OK属性代码示例

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


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

示例1: request

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import OK [as 别名]
def request(self, method, url, content=None, state=http.OK, add_headers=None):
        body = None if content is None else client.FileBodyProducer(
            StringIO(content))
        headers = {'Content-Type': ['application/json'], 'X-WebAuth-User': ['tester']}
        if add_headers:
            headers.update(add_headers)
        response = yield self.client.request(method,
                                             self.url_prefix + url,
                                             Headers(headers),
                                             body)
        self.assertEqual(state, response.code)
        body_receiver = BodyReceiver()
        response.deliverBody(body_receiver)
        body = yield body_receiver.finished
        if response.headers.getRawHeaders('content-type') == ['application/json']:
            body = anyjson.loads(body)
        returnValue((response, body)) 
开发者ID:moira-alert,项目名称:worker,代码行数:19,代码来源:test_api.py

示例2: testEvents

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import OK [as 别名]
def testEvents(self):
        yield self.db.pushEvent({
            "trigger_id": self.trigger.id,
            "state": state.OK,
            "old_state": state.WARN,
            "timestamp": self.now - 120,
            "metric": "test metric"
        })
        yield self.db.pushEvent({
            "trigger_id": self.trigger.id,
            "state": state.WARN,
            "old_state": state.OK,
            "timestamp": self.now,
            "metric": "test metric"
        })
        response, events = yield self.request('GET', 'event/{0}'.format(self.trigger.id))
        self.assertEqual(2, len(events['list']))
        response, events = yield self.request('GET', 'event')
        self.assertEqual(2, len(events['list'])) 
开发者ID:moira-alert,项目名称:worker,代码行数:21,代码来源:test_api.py

示例3: testTriggerPatterns

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import OK [as 别名]
def testTriggerPatterns(self):
        pattern = 'MoiraFuncTest.supervisord.host.{4*,5*}.state'
        metric1 = 'MoiraFuncTest.supervisord.host.400.state'
        metric2 = 'MoiraFuncTest.supervisord.host.500.state'
        yield self.sendTrigger('{"name": "test trigger", "targets": ["movingAverage(' +
                               pattern + ',10)"], "warn_value": 20, "error_value": 50, "ttl":"600" }')
        json, trigger = yield self.db.getTrigger(self.trigger.id)
        self.assertEquals([pattern], trigger["patterns"])
        yield self.db.sendMetric(pattern, metric1, self.now, 1)
        yield self.db.sendMetric(pattern, metric2, self.now, 1)
        yield self.db.sendMetric(pattern, metric1, self.now - 60, 1)
        yield self.db.sendMetric(pattern, metric2, self.now - 60, 1)
        yield self.trigger.check()
        yield self.assert_trigger_metric('movingAverage(' +
                                         metric1 + ',10)', 1, state.OK)
        yield self.assert_trigger_metric('movingAverage(' +
                                         metric2 + ',10)', 1, state.OK)
        yield self.sendTrigger('{"name": "test trigger", "targets": ["movingAverage(' +
                               pattern + ',10)"], "warn_value": 20, "error_value": 50, "ttl":"600" }')
        json, trigger = yield self.db.getTrigger(self.trigger.id)
        self.assertEquals([pattern], trigger["patterns"]) 
开发者ID:moira-alert,项目名称:worker,代码行数:23,代码来源:test_data.py

示例4: testTriggerExpression

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import OK [as 别名]
def testTriggerExpression(self):
        metric1 = 'MoiraFuncTest.one'
        metric2 = 'MoiraFuncTest.two'
        yield self.sendTrigger('{"name": "test trigger", "targets": ["' + metric1 + '", \
                               "' + metric2 + '"], \
                               "expression": "ERROR if t1 > t2 else OK", \
                               "ttl":"600" }')
        json, trigger = yield self.db.getTrigger(self.trigger.id)
        yield self.db.sendMetric(metric1, metric1, self.now - 60, 1)
        yield self.db.sendMetric(metric2, metric2, self.now - 60, 2)
        yield self.trigger.check(now=self.now)
        yield self.assert_trigger_metric(metric1, 1, state.OK)
        yield self.assert_trigger_metric(metric2, 2, state.OK)
        yield self.db.sendMetric(metric1, metric1, self.now, 4)
        yield self.db.sendMetric(metric2, metric2, self.now, 3)
        yield self.trigger.check(now=self.now + 60)
        yield self.assert_trigger_metric(metric1, 4, state.ERROR)
        yield self.assert_trigger_metric(metric2, 3, state.ERROR) 
开发者ID:moira-alert,项目名称:worker,代码行数:20,代码来源:test_data.py

示例5: testEventGeneration3

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import OK [as 别名]
def testEventGeneration3(self):
        metric = 'MoiraFuncTest.metric.one'
        yield self.sendTrigger('{"name": "test trigger", "targets": ["' + metric +
                               '"],  "warn_value": 1, "error_value": 5, "ttl":"600", "ttl_state": "OK" }')
        yield self.db.sendMetric(metric, metric, self.now - 1, 1)
        yield self.trigger.check()
        self.assert_trigger_metric(metric, 1, state.WARN)
        yield self.trigger.check(now=self.now + 120)
        self.assert_trigger_metric(metric, 1, state.WARN)
        yield self.trigger.check(now=self.now + 601)
        yield self.trigger.check(now=self.now + 602)
        self.assert_trigger_metric(metric, None, state.OK)
        events, total = yield self.db.getEvents()
        self.assertEquals(total, 2)
        self.assertEquals(events[0]["state"], state.OK)
        self.assertEquals(events[0]["metric"], metric)
        self.assertNotIn("value", events[0])
        self.assertEquals(events[1]["state"], state.WARN)
        self.assertEquals(events[1]["metric"], metric)
        self.assertEquals(events[1]["value"], 1) 
开发者ID:moira-alert,项目名称:worker,代码行数:22,代码来源:test_data.py

示例6: testErrorNoRemind

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import OK [as 别名]
def testErrorNoRemind(self):
        metric = 'MoiraFuncTest.metric.one'
        yield self.sendTrigger('{"name": "test trigger", "targets": ["' +
                               metric + '"], "warn_value": 60, "error_value": 90, "ttl":600, "ttl_state": "OK" }')
        yield self.db.sendMetric(metric, metric, self.now, 0)
        yield self.trigger.check()
        yield self.assert_trigger_metric(metric, 0, state.OK)
        yield self.trigger.check(now=self.now + 660)
        yield self.trigger.check(now=self.now + 660)
        yield self.assert_trigger_metric(metric, None, state.OK)
        yield self.trigger.check(now=self.now + 88460)
        yield self.trigger.check(now=self.now + 88460)
        yield self.db.sendMetric(metric, metric, self.now + 88520, 100)
        yield self.db.sendMetric(metric, metric, self.now + 88580, 100)
        yield self.trigger.check(now=self.now + 88580)
        events, total = yield self.db.getEvents()
        self.assertEquals(total, 2)
        self.assertEquals(events[0]["state"], state.ERROR) 
开发者ID:moira-alert,项目名称:worker,代码行数:20,代码来源:test_data.py

示例7: testMapReduce

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import OK [as 别名]
def testMapReduce(self):
        pattern = 'MoiraFuncTest.*.metric.{free,total}'
        metric1 = 'MoiraFuncTest.one.metric.free'
        metric2 = 'MoiraFuncTest.one.metric.total'
        metric3 = 'MoiraFuncTest.two.metric.free'
        metric4 = 'MoiraFuncTest.two.metric.total'
        yield self.sendTrigger('{"name": "test trigger", "targets": \
                               ["aliasByNode(reduceSeries(mapSeries(' + pattern + ',1), \
                               \\"asPercent\\",3,\\"free\\",\\"total\\"),1)"], \
                               "warn_value": 60, "error_value": 90 }')
        yield self.db.sendMetric(pattern, metric1, self.now - 1, 60)
        yield self.db.sendMetric(pattern, metric2, self.now - 1, 100)
        yield self.db.sendMetric(pattern, metric3, self.now - 1, 30)
        yield self.db.sendMetric(pattern, metric4, self.now - 1, 60)
        yield self.trigger.check()
        yield self.assert_trigger_metric('one', 60, state.WARN)
        yield self.assert_trigger_metric('two', 50, state.OK) 
开发者ID:moira-alert,项目名称:worker,代码行数:19,代码来源:test_data.py

示例8: testLateMetrics

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import OK [as 别名]
def testLateMetrics(self):
        yield self.sendTrigger('{"name": "test trigger", "targets": [" \
                               metric"], "warn_value": 1, "error_value": 2}')

        yield self.db.addPatternMetric("metric", "metric")
        yield self.db.sendMetric("metric", "metric", self.now, 0)
        yield self.trigger.check(now=self.now, cache_ttl=0)
        yield self.assert_trigger_metric("metric", 0, state.OK)

        yield self.db.sendMetric("metric", "metric", self.now - 60, 2)
        yield self.trigger.check(now=self.now + 60, cache_ttl=0)
        yield self.assert_trigger_metric("metric", 0, state.OK)

        yield self.db.sendMetric("metric", "metric", self.now + 120, 0)
        yield self.trigger.check(now=self.now + 120, cache_ttl=0)

        yield self.db.sendMetric("metric", "metric", self.now + 60, 1)
        yield self.trigger.check(now=self.now + 180, cache_ttl=0)
        yield self.assert_trigger_metric("metric", 0, state.OK)

        events, total = yield self.db.getEvents()
        self.assertEquals(total, 3)
        self.assertEquals(events[1]["state"], state.WARN) 
开发者ID:moira-alert,项目名称:worker,代码行数:25,代码来源:test_data.py

示例9: connectionMade

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import OK [as 别名]
def connectionMade(self):
        self._sendSASLMessage(self.START, self.sasl.mechanism)
        initial_message = yield deferToThread(self.sasl.process)
        self._sendSASLMessage(self.OK, initial_message)

        while True:
            status, challenge = yield self._receiveSASLMessage()
            if status == self.OK:
                response = yield deferToThread(self.sasl.process, challenge)
                self._sendSASLMessage(self.OK, response)
            elif status == self.COMPLETE:
                if not self.sasl.complete:
                    msg = "The server erroneously indicated that SASL " \
                          "negotiation was complete"
                    raise TTransport.TTransportException(msg, message=msg)
                else:
                    break
            else:
                msg = "Bad SASL negotiation status: %d (%s)" % (status, challenge)
                raise TTransport.TTransportException(msg, message=msg)

        self._sasl_negotiation_deferred = None
        ThriftClientProtocol.connectionMade(self) 
开发者ID:XiaoMi,项目名称:galaxy-sdk-python,代码行数:25,代码来源:TTwisted.py

示例10: test_invalidRangeRequest

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import OK [as 别名]
def test_invalidRangeRequest(self):
        """
        An incorrect range request (RFC 2616 defines a correct range request as
        a Bytes-Unit followed by a '=' character followed by a specific range.
        Only 'bytes' is defined) results in the range header value being logged
        and a normal 200 response being sent.
        """
        range = b'foobar=0-43'
        self.request.requestHeaders.addRawHeader(b'range', range)
        self.resource.render(self.request)
        expected = "Ignoring malformed Range header %r" % (range.decode(),)
        self._assertLogged(expected)
        self.assertEqual(b''.join(self.request.written), self.payload)
        self.assertEqual(self.request.responseCode, http.OK)
        self.assertEqual(
            self.request.responseHeaders.getRawHeaders(b'content-length')[0],
            intToBytes(len(self.payload))) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:19,代码来源:test_static.py

示例11: _modifiedTest

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import OK [as 别名]
def _modifiedTest(self, modifiedSince=None, etag=None):
        """
        Given the value C{modifiedSince} for the I{If-Modified-Since} header or
        the value C{etag} for the I{If-Not-Match} header, verify that a response
        with a 200 code, a default Content-Type, and the resource as the body is
        returned.
        """
        if modifiedSince is not None:
            validator = b"If-Modified-Since: " + modifiedSince
        else:
            validator = b"If-Not-Match: " + etag
        for line in [b"GET / HTTP/1.1", validator, b""]:
            self.channel.dataReceived(line + b'\r\n')
        result = self.transport.getvalue()
        self.assertEqual(httpCode(result), http.OK)
        self.assertEqual(httpBody(result), b"correct")
        self.assertEqual(httpHeader(result, b"Content-Type"), b"text/html") 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:19,代码来源:test_web.py

示例12: test_path

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import OK [as 别名]
def test_path(self):
        """
        ``/VolumeDriver.Path`` returns the mount path of the given volume if
        it is currently known.
        """
        name = u"myvol"

        d = self.create(name)
        # The dataset arrives as state:
        d.addCallback(lambda _: self.flocker_client.synchronize_state())

        d.addCallback(lambda _: self.assertResponseCode(
            b"POST", b"/VolumeDriver.Mount", {u"Name": name}, OK))
        d.addCallback(lambda _:
                      self.flocker_client.list_datasets_configuration())
        d.addCallback(lambda datasets_config:
                      self.assertResult(
                          b"POST", b"/VolumeDriver.Path",
                          {u"Name": name}, OK,
                          {u"Err": u"",
                           u"Mountpoint": u"/flocker/{}".format(
                               datasets_config.datasets.keys()[0])}))
        return d 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:25,代码来源:test_api.py

示例13: test_path_existing

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import OK [as 别名]
def test_path_existing(self):
        """
        ``/VolumeDriver.Path`` returns the mount path of the given volume if
        it is currently known, including for a dataset that was created
        not by the plugin.
        """
        name = u"myvol"

        d = self.flocker_client.create_dataset(
            self.NODE_A, int(DEFAULT_SIZE.to_Byte()),
            metadata={NAME_FIELD: name})

        def created(dataset):
            self.flocker_client.synchronize_state()
            return self.assertResult(
                b"POST", b"/VolumeDriver.Path",
                {u"Name": name}, OK,
                {u"Err": u"",
                 u"Mountpoint": u"/flocker/{}".format(dataset.dataset_id)})
        d.addCallback(created)
        return d 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:23,代码来源:test_api.py

示例14: test_get

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import OK [as 别名]
def test_get(self):
        """
        ``/VolumeDriver.Get`` returns the mount path of the given volume if
        it is currently known.
        """
        name = u"myvol"

        d = self.create(name)
        # The dataset arrives as state:
        d.addCallback(lambda _: self.flocker_client.synchronize_state())

        d.addCallback(lambda _: self.assertResponseCode(
            b"POST", b"/VolumeDriver.Mount", {u"Name": name}, OK))
        d.addCallback(lambda _:
                      self.flocker_client.list_datasets_configuration())
        d.addCallback(lambda datasets_config:
                      self.assertResult(
                          b"POST", b"/VolumeDriver.Get",
                          {u"Name": name}, OK,
                          {u"Err": u"",
                           u"Volume": {
                               u"Name": name,
                               u"Mountpoint": u"/flocker/{}".format(
                                   datasets_config.datasets.keys()[0])}}))
        return d 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:27,代码来源:test_api.py

示例15: test_get_existing

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import OK [as 别名]
def test_get_existing(self):
        """
        ``/VolumeDriver.Get`` returns the mount path of the given volume if
        it is currently known, including for a dataset that was created
        not by the plugin.
        """
        name = u"myvol"

        d = self.flocker_client.create_dataset(
            self.NODE_A, int(DEFAULT_SIZE.to_Byte()),
            metadata={NAME_FIELD: name})

        def created(dataset):
            self.flocker_client.synchronize_state()
            return self.assertResult(
                b"POST", b"/VolumeDriver.Get",
                {u"Name": name}, OK,
                {u"Err": u"",
                 u"Volume": {
                     u"Name": name,
                     u"Mountpoint":
                     u"/flocker/{}".format(dataset.dataset_id)}})
        d.addCallback(created)
        return d 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:26,代码来源:test_api.py


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