<s> """<STR_LIT>""" <EOL> from flask import g <EOL> from mongoengine . connection import ConnectionError <EOL> from py . test import fixture , exit <EOL> from tentd import create_app <EOL> from tentd . documents import collections , Entity , Post , Follower , Following <EOL> def pytest_report_header ( config ) : <EOL> from tentd import __version__ <EOL> return "<STR_LIT>" . format ( __version__ ) <EOL> def pytest_addoption ( parser ) : <EOL> """<STR_LIT>""" <EOL> parser . addoption ( '<STR_LIT>' , action = '<STR_LIT:store>' , default = '<STR_LIT>' , <EOL> help = "<STR_LIT>" ) <EOL> parser . addoption ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = "<STR_LIT>" ) <EOL> def pytest_configure ( config ) : <EOL> """<STR_LIT>""" <EOL> if not config . getoption ( '<STR_LIT>' ) : <EOL> from warnings import resetwarnings , filterwarnings <EOL> filterwarnings ( action = '<STR_LIT:error>' , module = '<STR_LIT>' ) <EOL> def pytest_generate_tests ( metafunc ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in metafunc . fixturenames : <EOL> metafunc . parametrize ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , ) , <EOL> '<STR_LIT:all>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> } [ metafunc . config . getoption ( '<STR_LIT>' ) ] , indirect = True , scope = "<STR_LIT>" ) <EOL> def pytest_runtest_teardown ( item , nextitem ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in item . fixturenames : <EOL> for collection in collections : <EOL> collection . drop_collection ( ) <EOL> def pytest_runtest_makereport ( item , call ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( call . excinfo , '<STR_LIT:type>' ) : <EOL> if call . excinfo . type is ConnectionError : <EOL> exit ( "<STR_LIT>" ) <EOL> @ fixture <EOL> def app ( request ) : <EOL> """<STR_LIT>""" <EOL> config = { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : request . param , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> app = create_app ( config ) <EOL> app . client = app . test_client ( ) <EOL> app . test_mode = request . param <EOL> ctx = app . test_request_context ( ) <EOL> ctx . push ( ) <EOL> request . addfinalizer ( ctx . pop ) <EOL> return app <EOL> @ fixture <EOL> def entity ( request , app ) : <EOL> name = app . user_name if app . user_mode == '<STR_LIT>' else '<STR_LIT>' <EOL> g . entity = Entity . new ( <EOL> name = name , <EOL> identity = "<STR_LIT>" , <EOL> servers = [ "<STR_LIT>" ] ) . save ( ) <EOL> @ request . addfinalizer <EOL> def delete_entity ( ) : <EOL> if hasattr ( g , '<STR_LIT>' ) : <EOL> del g . entity <EOL> return g . entity <EOL> @ fixture <EOL> def post ( request , entity ) : <EOL> """<STR_LIT>""" <EOL> schema = '<STR_LIT>' <EOL> post = Post ( entity = entity , schema = schema ) <EOL> post . new_version ( <EOL> content = { <EOL> '<STR_LIT:text>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : [ <NUM_LIT:0> , <NUM_LIT:0> ] , <EOL> } , <EOL> mention = [ ] ) <EOL> post . new_version ( <EOL> content = { <EOL> '<STR_LIT:text>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : [ <NUM_LIT:1> , <NUM_LIT:1> ] , <EOL> } , <EOL> mention = [ ] ) <EOL> post . new_version ( <EOL> content = { <EOL> '<STR_LIT:text>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : [ <NUM_LIT:2> , <NUM_LIT:2> ] } , <EOL> mentions = [ { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ] ) <EOL> post . save ( ) <EOL> post = Post . objects . get ( entity = entity , schema = schema ) <EOL> request . addfinalizer ( post . delete ) <EOL> return post <EOL> @ fixture <EOL> def follower ( request , entity ) : <EOL> """<STR_LIT>""" <EOL> follower = Follower ( <EOL> entity = entity , <EOL> identity = '<STR_LIT>' , <EOL> servers = [ '<STR_LIT>' ] , <EOL> notification_path = '<STR_LIT>' ) <EOL> request . addfinalizer ( follower . delete ) <EOL> return follower . save ( ) <EOL> @ fixture <EOL> def following ( request , entity ) : <EOL> """<STR_LIT>""" <EOL> following = Following ( <EOL> entity = entity , <EOL> identity = '<STR_LIT>' ) <EOL> request . addfinalizer ( following . delete ) <EOL> return following . save ( ) </s>
