當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。