def test__main__make_app__WillStartCataloger__WhenCalled( self, _, __, ___, mock_collector): make_app() collector_instance = mock_collector.return_value assert collector_instance.collect_reviews.called assert collector_instance.collect_releases.called
def test__main__make_app__WillInjectStoreIntoReviewsHandler__WhenCalled(self, mock_app, mock_review_store, mock_score_store, _, __): review_store_instance = mock_review_store.return_value score_store_instance = mock_score_store.return_value expected_arg = [ (r'/', ScoresHandler, {'store': score_store_instance}), (r'/public/(.*)', tornado.web.StaticFileHandler, {'path': PUBLIC_ROOT}), ('/reviews', ReviewsHandler, {'store': review_store_instance})] make_app() mock_app.assert_called_with(expected_arg)
def get_app(self): """ Overrides basic method, gets app """ # Assumption is environment has already been loaded by the test runner, # else the below will fail application = make_app() return application
def test__main__make_app__WillInjectSearcherIntoTheSearchHandler__WhenCalled( self, mock_app, mock_searcher): main_path = os.path.abspath( os.path.join(os.path.dirname(__file__), os.pardir)) searcher_instance = mock_searcher.return_value expected_args = [('/', HomePageHandler), ('/public/(.*)', StaticFileHandler, { 'path': main_path + '/static' }), ('/search', SearchHandler, { 'searcher': searcher_instance })] make_app() mock_app.assert_called_with(expected_args)
def test_sync(): app = make_app() @app.route('/test') def handler(request): return text('Hello') request, response = sanic_endpoint_test(app, uri='/test') assert response.text == 'Hello'
def test__main__make_app__WillInjectStoreIntoReviewsHandler__WhenCalled( self, mock_app, mock_review_store, mock_score_store, _, __): review_store_instance = mock_review_store.return_value score_store_instance = mock_score_store.return_value expected_arg = [(r'/', ScoresHandler, { 'store': score_store_instance }), (r'/public/(.*)', tornado.web.StaticFileHandler, { 'path': PUBLIC_ROOT }), ('/reviews', ReviewsHandler, { 'store': review_store_instance })] make_app() mock_app.assert_called_with(expected_arg)
def test__main__make_app__WillInitialiseTornadoApplicationWithCorrectHandlers__WhenCalled( self, mock_app, mock_sql): mock_sql_instance = mock_sql.return_value expected_args = [('/check-vulnerability', CheckVulnerabilityHandler, dict(spider=DVWASpider, injector=mock_sql_instance, crawled_site='dvwa')), ('/get-db-users', GetDbUsersHandler, dict(spider=DVWASpider, injector=mock_sql_instance, crawled_site='dvwa')), ('/get-db-version', GetDbVersionHandler, dict(spider=DVWASpider, injector=mock_sql_instance, crawled_site='dvwa'))] make_app() mock_app.assert_called_with(expected_args)
def get_app(self): class TestMeView(CacheMixin, JinjaTemplateMixin, RequestHandler): @gen.coroutine def get(self): self.write('chunk-1*') self.write('chunk-2*') self.write('chunk-3') self.application = main.make_app([ (r'/testme/', TestMeView), ]) return self.application
def insert_data(): from main import make_app, db app = make_app() with app.app_context(): with open('fake_data.csv', 'r', newline='') as file: reader = csv.DictReader(file) for row in reader: doctor = Doctor(name=row['name'], occupation=row['occupation']) address = Address(phone_number=int(row['phone_number']), street_address=row['street_address'], city=row['city'], state=row['state'], zipcode=int(row['zipcode']), long=float(row['long']), lat=float(row['lat'])) doctor.addresses.append(address) db.session.add(doctor) db.session.commit()
def get_app(self): class TestMeView( CacheMixin, JinjaTemplateMixin, RequestHandler ): @gen.coroutine def get(self): self.write('chunk-1*') self.write('chunk-2*') self.write('chunk-3') self.application = main.make_app( [ (r'/testme/', TestMeView), ] ) return self.application
def test__main__make_app__WillStartCollector__WhenCalled(self, _, __, ___, mock_collector): make_app() collector_instance = mock_collector.return_value assert collector_instance.start.called
def get_app(self): app = make_app() app.objects = peewee_async.Manager(db) return app
def get_app(self): return main.make_app()
def zeus(loop, aiohttp_client): app = make_app() return loop.run_until_complete(aiohttp_client(app))
def app(): app = make_app() yield app
def test__main__make_app__WillInstantiateTMDBSearcher__WhenCalled( self, mock_app, mock_searcher): make_app() mock_searcher.assert_called_with()
def get_app(self): from main import make_app return make_app()
def test__main__make_app__WillStartAggregatorService__WhenCalled( self, _, __, ___, mock_aggregator): make_app() aggregator_instance = mock_aggregator.return_value assert aggregator_instance.start.called
def get_app(self): self.app = make_app() return self.app
def get_app(self): import main return main.make_app()
import pytest from main import make_app from tornado.options import define import os define('static_path', default=os.path.join(os.path.dirname(__file__), "static"), help='static file path') application = make_app() @pytest.fixture def app(): return application @pytest.mark.gen_test def test_hello_world(http_client, base_url): response = yield http_client.fetch(f"{base_url}/ping") assert response.code == 200 assert response.body == b"Hello, world" @pytest.mark.gen_test def test_static(http_client, base_url): response = yield http_client.fetch(f"{base_url}/static/test.txt") assert response.code == 200 assert response.body == b"Hello, world from static!"
def test__main__make_app__WillStartAggregatorService__WhenCalled(self, _, __, ___, mock_aggregator): make_app() aggregator_instance = mock_aggregator.return_value assert aggregator_instance.start.called
import pytest, os from webtest import TestApp try: from main import make_app except ImportError: print( "If you see this, you didn't install the package before running the tests" ) print("Please install the pacakge with 'pip install -e .'") app = make_app() @pytest.fixture def testapp(): """A fixture to test the web application""" yield TestApp(app)
def run_dev(ctx): server = HTTPServer(make_app()) server.bind(PORT) server.start(0) tornado.ioloop.IOLoop.current().start()