<s> from unittest . mock import patch <EOL> import pytest <EOL> import muffin <EOL> def test_app ( app ) : <EOL> assert app . name == '<STR_LIT>' <EOL> assert app . cfg <EOL> with pytest . raises ( AttributeError ) : <EOL> app . local <EOL> with pytest . raises ( RuntimeError ) : <EOL> app . cfg . OPTION = <NUM_LIT> <EOL> with pytest . raises ( RuntimeError ) : <EOL> app . ps . PLUGIN = <NUM_LIT> <EOL> def test_app_logging_cfg ( ) : <EOL> dummy = { '<STR_LIT>' : '<STR_LIT>' } <EOL> with patch ( '<STR_LIT>' ) as m : <EOL> muffin . Application ( <EOL> '<STR_LIT>' , <EOL> LOGGING = dummy <EOL> ) <EOL> m . assert_called_once_with ( dummy ) <EOL> def test_view ( app , client ) : <EOL> @ app . register <EOL> def view ( request ) : <EOL> return '<STR_LIT>' <EOL> response = client . get ( '<STR_LIT>' ) <EOL> assert response . text == '<STR_LIT>' <EOL> def test_str ( app , client ) : <EOL> @ app . register ( '<STR_LIT>' ) <EOL> def str ( request ) : <EOL> return '<STR_LIT>' <EOL> response = client . get ( '<STR_LIT>' ) <EOL> assert response . text == '<STR_LIT>' <EOL> def test_bytes ( app , client ) : <EOL> @ app . register ( '<STR_LIT>' ) <EOL> def bytes ( request ) : <EOL> return b'<STR_LIT>' <EOL> response = client . get ( '<STR_LIT>' ) <EOL> assert response . headers [ '<STR_LIT:Content-Type>' ] == '<STR_LIT>' <EOL> assert response . text == '<STR_LIT>' <EOL> def test_custom_methods ( app , client ) : <EOL> @ app . register ( '<STR_LIT>' , methods = '<STR_LIT>' ) <EOL> def propfind ( request ) : <EOL> return b'<STR_LIT>' <EOL> response = client . request ( '<STR_LIT>' , method = '<STR_LIT>' ) <EOL> assert response . text == '<STR_LIT>' <EOL> def test_static ( app , client ) : <EOL> assert app . cfg . STATIC_FOLDERS == [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> response = client . get ( '<STR_LIT>' ) <EOL> assert response . status_code == <NUM_LIT:200> <EOL> response = client . get ( '<STR_LIT>' ) <EOL> assert response . status_code == <NUM_LIT:200> <EOL> def test_manage ( app , capsys ) : <EOL> @ app . manage . command <EOL> def hello ( name , lower = False ) : <EOL> if lower : <EOL> name = name . lower ( ) <EOL> print ( "<STR_LIT>" + name ) <EOL> with pytest . raises ( SystemExit ) : <EOL> app . manage ( * '<STR_LIT:hello>' . split ( ) ) <EOL> out , err = capsys . readouterr ( ) <EOL> assert not out <EOL> assert err <EOL> with pytest . raises ( SystemExit ) : <EOL> app . manage ( * '<STR_LIT>' . split ( ) ) <EOL> out , err = capsys . readouterr ( ) <EOL> assert "<STR_LIT>" == out <EOL> with pytest . raises ( SystemExit ) : <EOL> app . manage ( * '<STR_LIT>' . split ( ) ) <EOL> out , err = capsys . readouterr ( ) <EOL> assert "<STR_LIT>" == out <EOL> def test_signature ( ) : <EOL> assert muffin . utils . create_signature ( '<STR_LIT>' , '<STR_LIT:message>' ) <EOL> def test_password_hash ( ) : <EOL> pwhash = muffin . utils . generate_password_hash ( '<STR_LIT>' ) <EOL> assert pwhash <EOL> assert not muffin . utils . check_password_hash ( '<STR_LIT>' , pwhash ) <EOL> assert muffin . utils . check_password_hash ( '<STR_LIT>' , pwhash ) <EOL> def test_error_pages ( client , loop , app ) : <EOL> def handle_404 ( request ) : <EOL> return muffin . Response ( text = '<STR_LIT>' , status = <NUM_LIT> ) <EOL> app . register ( muffin . HTTPNotFound ) ( handle_404 ) <EOL> loop . run_until_complete ( app . start ( ) ) <EOL> response = client . get ( '<STR_LIT>' , status = <NUM_LIT> ) <EOL> assert '<STR_LIT>' == response . text <EOL> @ app . register ( '<STR_LIT>' ) <EOL> def raise_400 ( request ) : <EOL> raise muffin . HTTPBadRequest ( ) <EOL> @ app . register ( muffin . HTTPBadRequest ) <EOL> def handle_400 ( request ) : <EOL> return muffin . Response ( text = '<STR_LIT>' , status = <NUM_LIT> ) <EOL> response = client . get ( '<STR_LIT>' , status = <NUM_LIT> ) <EOL> assert '<STR_LIT>' == response . text <EOL> @ app . register ( '<STR_LIT>' , muffin . HTTPInternalServerError ) <EOL> def handle_500 ( request ) : <EOL> return muffin . Response ( text = '<STR_LIT>' , status = <NUM_LIT> ) <EOL> @ app . register ( '<STR_LIT>' ) <EOL> def raise_500 ( request ) : <EOL> raise muffin . HTTPInternalServerError ( ) <EOL> response = client . get ( '<STR_LIT>' , status = <NUM_LIT> ) <EOL> assert '<STR_LIT>' == response . text <EOL> response = client . get ( '<STR_LIT>' , status = <NUM_LIT> ) <EOL> assert '<STR_LIT>' == response . text </s>
