コード例 #1
0
 def test_the_response_headers_are_captured(self):
     test_app = webtest.TestApp(app)
     sniffer = BottleSniffer()
     app.install(sniffer)
     test_app.post('/success')
     response = sniffer.transactions[0].response
     assert response.headers == {'The-More': 'The-Merrier'}
コード例 #2
0
def test_a_transaction_is_captured():
    test_app = webtest.TestApp(app)
    sniffer = BottleSniffer()
    app.install(sniffer)
    test_app.get('/success')
    assert len(sniffer.transactions) == 1
    assert isinstance(sniffer.transactions[0], Transaction)
コード例 #3
0
 def test_the_response_body_is_captured(self):
     test_app = webtest.TestApp(app)
     sniffer = BottleSniffer()
     app.install(sniffer)
     test_app.post('/success')
     response = sniffer.transactions[0].response
     assert response.body == "To infinity and beyond!"
コード例 #4
0
 def test_status_code_is_captured_when_http_response_is_raised(self):
     test_app = webtest.TestApp(app)
     sniffer = BottleSniffer()
     app.install(sniffer)
     test_app.get('/http-response')
     response = sniffer.transactions[0].response
     assert response.status == '300 Multiple Choices'
コード例 #5
0
 def test_sniffer_does_not_interfere(self):
     test_app = webtest.TestApp(app)
     app.install(BottleSniffer())
     with pytest.raises(webtest.app.AppError) as excinfo:
         test_app.get('/error')
     assert '400 Bad Request' in str(excinfo.value)
     assert 'Object already exists with that name' in str(excinfo.value)
コード例 #6
0
 def test_the_url_path_is_captured(self):
     test_app = webtest.TestApp(app)
     sniffer = BottleSniffer()
     app.install(sniffer)
     test_app.get('/success')
     request = sniffer.transactions[0].request
     assert request.url_path == '/success'
コード例 #7
0
 def test_the_request_method_is_captured(self, method_call, method_name):
     test_app = webtest.TestApp(app)
     sniffer = BottleSniffer()
     app.install(sniffer)
     getattr(test_app, method_call)('/success')
     request = sniffer.transactions[0].request
     assert request.method == method_name
コード例 #8
0
 def test_the_response_status_code_is_captured(self):
     test_app = webtest.TestApp(app)
     sniffer = BottleSniffer()
     app.install(sniffer)
     test_app.post('/success')
     response = sniffer.transactions[0].response
     assert response.status == '200 OK'
コード例 #9
0
 def test_the_request_body_is_captured(self):
     test_app = webtest.TestApp(app)
     sniffer = BottleSniffer()
     app.install(sniffer)
     test_app.post('/success', "Dreams + work")
     request = sniffer.transactions[0].request
     assert request.body == b"Dreams + work"
コード例 #10
0
 def test_the_url_path_is_captured(self, url):
     test_app = webtest.TestApp(app)
     sniffer = BottleSniffer()
     app.install(sniffer)
     with pytest.raises(webtest.app.AppError):
         test_app.get(url)
     request = sniffer.transactions[0].request
     assert request.url_path == url
コード例 #11
0
 def test_the_request_body_is_captured(self, url):
     test_app = webtest.TestApp(app)
     sniffer = BottleSniffer()
     app.install(sniffer)
     with pytest.raises(webtest.app.AppError):
         test_app.post(url, '2 + 2 = 5')
     request = sniffer.transactions[0].request
     assert request.body == b"2 + 2 = 5"
コード例 #12
0
 def test_a_transaction_is_captured(self, url):
     test_app = webtest.TestApp(app)
     sniffer = BottleSniffer()
     app.install(sniffer)
     with pytest.raises(webtest.app.AppError):
         test_app.get(url)
     assert len(sniffer.transactions) == 1
     assert isinstance(sniffer.transactions[0], Transaction)
コード例 #13
0
 def test_the_response_body_is_captured(self):
     test_app = webtest.TestApp(app)
     sniffer = BottleSniffer()
     app.install(sniffer)
     with pytest.raises(webtest.app.AppError):
         test_app.get('/error')
     response = sniffer.transactions[0].response
     assert 'Object already exists with that name' in response.body
コード例 #14
0
 def test_status_code_is_captured_when_an_exception_is_raised(self):
     test_app = webtest.TestApp(app)
     sniffer = BottleSniffer()
     app.install(sniffer)
     with pytest.raises(webtest.app.AppError):
         test_app.post('/exception')
     response = sniffer.transactions[0].response
     assert response.status == '500 Internal Server Error'
コード例 #15
0
 def test_status_code_is_captured_when_http_error_is_raised(self):
     test_app = webtest.TestApp(app)
     sniffer = BottleSniffer()
     app.install(sniffer)
     with pytest.raises(webtest.app.AppError):
         test_app.get('/http-error')
     response = sniffer.transactions[0].response
     assert response.status == '404 Not Found'
コード例 #16
0
 def test_the_response_status_code_is_captured(self):
     test_app = webtest.TestApp(app)
     sniffer = BottleSniffer()
     app.install(sniffer)
     with pytest.raises(webtest.app.AppError):
         test_app.post('/error')
     response = sniffer.transactions[0].response
     assert response.status == '400 Bad Request'
コード例 #17
0
 def test_the_response_headers_are_captured(self):
     test_app = webtest.TestApp(app)
     sniffer = BottleSniffer()
     app.install(sniffer)
     with pytest.raises(webtest.app.AppError):
         test_app.post('/error')
     response = sniffer.transactions[0].response
     assert response.headers == {'Today-Is': 'No-Way'}
コード例 #18
0
 def test_the_request_method_is_captured(self, url, method_call,
                                         method_name):
     test_app = webtest.TestApp(app)
     sniffer = BottleSniffer()
     app.install(sniffer)
     with pytest.raises(webtest.app.AppError):
         getattr(test_app, method_call)('/error')
     request = sniffer.transactions[0].request
     assert request.method == method_name
コード例 #19
0
 def test_the_elapsed_time_is_captured(self):
     test_app = webtest.TestApp(app)
     sniffer = BottleSniffer()
     app.install(sniffer)
     REQUEST_TIME = 4.5
     time.time.return_value = REQUEST_TIME
     test_app.get('/success')
     request = sniffer.transactions[0].request
     expected_elapsed = REQUEST_TIME - CAPTURE_START_TIME
     assert abs(request.elapsed - expected_elapsed) < 0.0001
コード例 #20
0
def test_multiple_requests_are_captured():
    test_app = webtest.TestApp(app)
    sniffer = BottleSniffer()
    app.install(sniffer)
    for _ in range(100):
        test_app.get('/success').status
        with pytest.raises(webtest.app.AppError):
            test_app.get('/error').status
        with pytest.raises(webtest.app.AppError):
            test_app.get('/exception').status
    assert len(sniffer.transactions) == 300
コード例 #21
0
 def test_the_elapsed_time_is_captured(self, url):
     test_app = webtest.TestApp(app)
     sniffer = BottleSniffer()
     app.install(sniffer)
     REQUEST_TIME = 4.5
     time.time.return_value = REQUEST_TIME
     with pytest.raises(webtest.app.AppError):
         test_app.get(url)
     response = sniffer.transactions[0].response
     expected_elapsed = (
         REQUEST_TIME - CAPTURE_START_TIME + ERROR_PROCESSING_TIME)
     assert abs(response.elapsed - expected_elapsed) < 0.0001
コード例 #22
0
 def test_the_request_headers_are_captured(self):
     test_app = webtest.TestApp(app)
     sniffer = BottleSniffer()
     app.install(sniffer)
     test_app.get(
         '/success',
         headers={
             'Content-Type': 'application/json',
             'Some-Header': 'Some value'
         })
     request = sniffer.transactions[0].request
     # not comparing dictionaries because WebTest adds extra headers
     assert request.headers['Content-Type'] == 'application/json'
     assert request.headers['Some-Header'] == 'Some value'
コード例 #23
0
 def test_sniffer_does_not_interfere(self):
     test_app = webtest.TestApp(app)
     app.install(BottleSniffer())
     assert test_app.get('/success').status == '200 OK'
コード例 #24
0
 def test_sniffer_does_not_interfere_with_error_due_to_exceptions(self):
     test_app = webtest.TestApp(app)
     app.install(BottleSniffer())
     with pytest.raises(webtest.app.AppError) as excinfo:
         test_app.get('/exception')
     assert '500 Internal Server Error' in str(excinfo.value)
コード例 #25
0
def test_bottle_sniffer_implements_api_version_2():
    # https://bottlepy.org/docs/dev/plugindev.html
    assert BottleSniffer().api == 2
コード例 #26
0
def test_bottle_sniffer_is_an_http_sniffer():
    assert isinstance(BottleSniffer(), HTTPSniffer)