Exemplo n.º 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'}
Exemplo n.º 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)
Exemplo n.º 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!"
Exemplo n.º 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'
Exemplo n.º 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)
Exemplo n.º 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'
Exemplo n.º 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
Exemplo n.º 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'
Exemplo n.º 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"
Exemplo n.º 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
Exemplo n.º 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"
Exemplo n.º 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)
Exemplo n.º 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
Exemplo n.º 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'
Exemplo n.º 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'
Exemplo n.º 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'
Exemplo n.º 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'}
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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'
Exemplo n.º 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'
Exemplo n.º 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)
Exemplo n.º 25
0
def test_bottle_sniffer_implements_api_version_2():
    # https://bottlepy.org/docs/dev/plugindev.html
    assert BottleSniffer().api == 2
Exemplo n.º 26
0
def test_bottle_sniffer_is_an_http_sniffer():
    assert isinstance(BottleSniffer(), HTTPSniffer)