Python app.app 模块,test_client() 实例源码

我们从Python开源项目中,提取了以下48个代码示例,用于说明如何使用app.app.test_client()

项目:KUBaM    作者:CiscoUcs    | 项目源码 | 文件源码
def test_currentsession(self):
        tester = app.test_client(self)
        response = tester.get('/api/v1/session' , content_type='application/json')
        #print response.data
        #self.assertIn(b'REDACTED', response.data)


#    def test_login_correct(self):
#        tester = app.test_client(self)
#        credentials =  { "credentials" : {
#                        "user" : "admin", 
#                         "password" : "nbv12345", 
#                         "server" : "172.28.225.163"
#                        }}
#        response = tester.post(
#                    '/api/v1/session' ,
#                    data = json.dumps(credentials),
#                    content_type='application/json'
#                    )
#        self.assertIn(b'success', response.data)
项目:coder_api    作者:seekheart    | 项目源码 | 文件源码
def setUp(self):
        """Setup method for spinning up a test instance of app"""
        app.config['TESTING'] = True
        app.config['WTF_CSRF_ENABLED'] = False
        self.app = app.test_client()
        self.app.testing = True
        self.authorization = {
            'Authorization': "Basic {user}".format(
                user=base64.b64encode(b"test:asdf").decode("ascii")
            )
        }
        self.content_type = 'application/json'
        self.dummy_name = 'dummy'
        self.dummy_user = json.dumps(
            {'username': 'dummy', 'languages': ['testLang']}
        )
        self.dummy_lang = json.dumps(
            {'name': 'dummy', 'users': ['No one']}
        )
项目:microflack_messages    作者:miguelgrinberg    | 项目源码 | 文件源码
def setUp(self):
        self.ctx = app.app_context()
        self.ctx.push()
        db.drop_all()  # just in case
        db.create_all()
        self.client = app.test_client()
项目:ecommerce_api    作者:nbschool    | 项目源码 | 文件源码
def setup_class(cls):
        """
        When a Test is created override the ``database`` attribute for all
        the tables with a SqliteDatabase in memory.
        """
        for table in TABLES:
            table._meta.database = cls.TEST_DB
            table.create_table(fail_silently=True)

        cls.app = app.test_client()
项目:BlogSpider    作者:hack4code    | 项目源码 | 文件源码
def setUp(self):
        app.config['TESTING'] = True
        self.app = app.test_client()
        self.app_context = app.app_context()
        self.app_context.push()
项目:sthacksWebsite    作者:Sthacks    | 项目源码 | 文件源码
def setUp(self):
        self.app = app.test_client()
项目:Adventure-Insecure    作者:colinnewell    | 项目源码 | 文件源码
def setUp(self):
        self.db_fd, self.db_filename = tempfile.mkstemp()
        # FIXME: this isn't actually working.
        app.config['DATABASE_URI'] = 'sqlite:///' + self.db_filename
        self.app = app.test_client()
        db.create_all()
项目:airbnb_clone    作者:bennettbuchanan    | 项目源码 | 文件源码
def setUp(self):
        '''Creates a test client, disables logging, connects to the database
        and creates state and city tables for temporary testing purposes.
        '''
        self.app = app.test_client()
        logging.disable(logging.CRITICAL)
        BaseModel.database.connect()
        BaseModel.database.create_tables([User, State, City, Place, PlaceBook])

        '''Create table items for ForeignKeyField requirements.'''
        self.app.post('/users', data=dict(
            first_name="test",
            last_name="test",
            email="test",
            password="test"
        ))

        self.app.post('/states', data=dict(
            name="test"
        ))

        self.app.post('/states/1/cities', data=dict(
            name="test",
            state=1
        ))

        self.app.post('/places', data=dict(
            owner=1,
            city=1,
            name="test",
            description="test",
            latitude=0,
            longitude=0
        ))
项目:airbnb_clone    作者:bennettbuchanan    | 项目源码 | 文件源码
def setUp(self):
        '''Creates a test client, disables logging, connects to the database
        and creates a table State for temporary testing purposes.
        '''
        self.app = app.test_client()
        logging.disable(logging.CRITICAL)
        BaseModel.database.connect()
        BaseModel.database.create_tables([State])
项目:airbnb_clone    作者:bennettbuchanan    | 项目源码 | 文件源码
def setUp(self):
        '''Creates a test client, disables logging, connects to the database
        and creates state and city tables for temporary testing purposes.
        '''
        self.app = app.test_client()
        logging.disable(logging.CRITICAL)
        BaseModel.database.connect()
        BaseModel.database.create_tables([User, City, Place, State, PlaceBook])

        '''Create items in tables for ForeignKeyField requirements'''
        self.app.post('/states', data=dict(name="test"))

        self.app.post('/states/1/cities', data=dict(
            name="test",
            state=1
        ))

        self.app.post('/users', data=dict(
            first_name="test",
            last_name="test",
            email="test",
            password="test"
        ))

        '''Create two places.'''
        for i in range(1, 3):
            self.create_place('/places', 'test_' + str(i))

        '''Create a book on place 1, belonging to user 1.'''
        self.app.post('/places/1/books', data=dict(
            place=1,
            user=1,
            date_start="2000/1/1 00:00:00",
            description="test",
            number_nights=10,
            latitude=0,
            longitude=0
        ))
项目:airbnb_clone    作者:bennettbuchanan    | 项目源码 | 文件源码
def setUp(self):
        '''Creates a test client, disables logging, connects to the database
        and creates state and city tables for temporary testing purposes.
        '''
        self.app = app.test_client()
        logging.disable(logging.CRITICAL)
        BaseModel.database.connect()
        BaseModel.database.create_tables([State, City])

        '''Create a state for routing purposes.'''
        self.app.post('/states', data=dict(name="test"))

        '''Create two new cities.'''
        for i in range(1, 3):
            res = self.create_city("test_" + str(i))
项目:airbnb_clone    作者:bennettbuchanan    | 项目源码 | 文件源码
def setUp(self):
        '''Creates a test client and propagates the exceptions to the test
        client.
        '''
        self.app = app.test_client()
        self.app.testing = True
项目:airbnb_clone    作者:bennettbuchanan    | 项目源码 | 文件源码
def setUp(self):
        '''Creates a test client, disables logging, connects to the database
        and creates a table User for temporary testing purposes.
        '''
        self.app = app.test_client()
        logging.disable(logging.CRITICAL)
        BaseModel.database.connect()
        BaseModel.database.create_tables([User, Place, Review, ReviewPlace,
                                          ReviewUser, City, State])

        '''Add two new users.'''
        for i in range(1, 3):
            self.app.post('/users', data=dict(first_name="user_" + str(i),
                                              last_name="user_" + str(i),
                                              email="user_" + str(i),
                                              password="user_" + str(i)))

        '''Add a state.'''
        self.app.post('/states', data=dict(name="state_1"))

        '''Add a city.'''
        self.app.post('/states/1/cities', data=dict(name="city_1", state=1))

        '''Add a place.'''
        self.app.post('/places', data=dict(owner=1, city=1, name="place_1",
                                           description="place_1", latitude=0,
                                           longitude=0))
项目:airbnb_clone    作者:bennettbuchanan    | 项目源码 | 文件源码
def setUp(self):
        '''Creates a test client, disables logging, connects to the database
        and creates a table User for temporary testing purposes.
        '''
        self.app = app.test_client()
        logging.disable(logging.CRITICAL)
        BaseModel.database.connect()
        BaseModel.database.create_tables([User])
项目:dark-chess    作者:AHAPX    | 项目源码 | 文件源码
def setUp(self):
        app.config['TESTING'] = True
        app.config['DEBUG'] = True
        self.client = app.test_client()
        super(TestCaseWeb, self).setUp()
项目:KUBaM    作者:CiscoUcs    | 项目源码 | 文件源码
def test_api(self):
        tester=app.test_client(self)
        response = tester.get('/', content_type='application/json')
        self.assertEqual(response.status_code,200)
项目:Feature-Request-Python-Flask    作者:jmcgrath207    | 项目源码 | 文件源码
def setUp(self):
        self.app = app
        self.app.config.from_object('app.config')
        self.app.config["NO_PASSWORD"] = False
        self.app.config["DEBUG"] = True
        self.app.config["TESTING"] = True
        self.app = app.test_client()
        db.create_all()
项目:neighborhood_mood_aws    作者:jarrellmark    | 项目源码 | 文件源码
def setUp(self):
        self.app = app.test_client()
项目:Cycling_admin    作者:Social-projects-Rivne    | 项目源码 | 文件源码
def test_controller_with_empty_db(self, db):
        """
        Imitate situation when there is no any user available in the db and
        sqlalchemy output becomes an empty list []. Message 'There are no
        users in the database' instead of users table is expected as default
        behavior in this case.
        """
        db.session.query.return_value.all.return_value = []
        with app.test_client() as test_client:
            responce = test_client.get('/users/all')
            data = responce.data
            self.assertIn('There are no users in the database.', data)
项目:Cycling_admin    作者:Social-projects-Rivne    | 项目源码 | 文件源码
def test_unavailable_db(self):
        """
        Check if "Can not access database" message appears if db is
        unavailable.
        """
        #break db uri to call exception inside controller
        app.config['SQLALCHEMY_DATABASE_URI'] = ''
        with app.test_client() as test_client:
            responce = test_client.get('/users/all')
            data = responce.data
            self.assertIn("Can not access database.", data)
            self.assertNotIn('<table class="table">', data)
项目:Cloud-Native-Python    作者:PacktPublishing    | 项目源码 | 文件源码
def setUp(self):
        # creates a test client
        self.app = app.test_client()
        # propagate the exceptions to the test client
        self.app.testing = True
项目:Cloud-Native-Python    作者:PacktPublishing    | 项目源码 | 文件源码
def setUp(self):
        # creates a test client
        self.app = app.test_client()
        # propagate the exceptions to the test client
        self.app.testing = True
项目:Cloud-Native-Python    作者:PacktPublishing    | 项目源码 | 文件源码
def setUp(self):
        # creates a test client
        self.app = app.test_client()
        # propagate the exceptions to the test client
        self.app.testing = True
项目:micro-blog    作者:nickChenyx    | 项目源码 | 文件源码
def setUp(self):
        app.config['TESTING'] = True
        app.config['WTF_CSRF_ENABLED'] = False
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'test.db')
        self.app = app.test_client()
        db.create_all()
项目:python_web    作者:lzhaoyang    | 项目源码 | 文件源码
def test_index(self):
        """initial test. ensure flask was set up correctly"""
        tester = app.test_client(self)
        response = tester.get('/', content_type='html/text')
        self.assertEqual(response.status_code, 200)
项目:python_web    作者:lzhaoyang    | 项目源码 | 文件源码
def setUp(self):
        """Set up a blank temp database before each test"""
        basedir = os.path.abspath(os.path.dirname(__file__))
        app.config['TESTING'] = True
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \
            os.path.join(basedir, TEST_DB)
        self.app = app.test_client()
        db.create_all()
项目:uberemind    作者:mayurbhangale    | 项目源码 | 文件源码
def setUp(self):
        # Necessary to disable SSLify
        app.debug = True
        self.test_app = app.test_client()
        self.session = app.requests_session
项目:uberemind    作者:mayurbhangale    | 项目源码 | 文件源码
def test_health_endpoint(self):
        """Assert that the health endpoint works."""
        response = app.test_client().get('/health')
        self.assertEquals(response.data, ';-)')
项目:uberemind    作者:mayurbhangale    | 项目源码 | 文件源码
def test_root_endpoint(self):
        """Assert that the / endpoint correctly redirects to login.uber.com."""
        response = app.test_client().get('/')
        self.assertIn('login.uber.com', response.data)
项目:uberemind    作者:mayurbhangale    | 项目源码 | 文件源码
def test_submit_endpoint_failure(self):
        """Assert that the submit endpoint returns no code in the response."""
        with app.test_client() as client:
            with client.session_transaction() as session:
                session['access_token'] = test_auth_token
            with Betamax(app.requests_session).use_cassette('submit_failure'):
                response = client.get('/submit?code=not_a_code')
        self.assertIn('None', response.data)
项目:uberemind    作者:mayurbhangale    | 项目源码 | 文件源码
def test_products_endpoint_returns_success(self):
        """Assert that the products endpoint returns success.

        When a valid key is passed in.
        """
        with app.test_client() as client:
            with client.session_transaction() as session:
                session['access_token'] = test_auth_token
            with Betamax(app.requests_session).use_cassette('products_success'):
                response = client.get('/products')
        self.assertIn('products', response.data)
        self.assertEquals(response.status_code, 200)
项目:uberemind    作者:mayurbhangale    | 项目源码 | 文件源码
def test_time_estimates_endpoint_returns_success(self):
        """Assert that the time estimates endpoint returns success.

        When a valid key is passed in.
        """
        with app.test_client() as client:
            with client.session_transaction() as session:
                session['access_token'] = test_auth_token
            with Betamax(app.requests_session).use_cassette('time_estimates_success'):
                response = client.get('/time')
        self.assertIn('times', response.data)
        self.assertEquals(response.status_code, 200)
项目:uberemind    作者:mayurbhangale    | 项目源码 | 文件源码
def test_time_estimates_endpoint_returns_failure(self):
        """Assert that the time estimates endpoint returns failure.

        When an invalid key is passed in.
        """
        with app.test_client() as client:
            with client.session_transaction() as session:
                session['access_token'] = 'NOT_A_CODE'
            with Betamax(app.requests_session).use_cassette('time_estimates_failure'):
                response = client.get('/time')
        self.assertEquals(response.status_code, 401)
项目:uberemind    作者:mayurbhangale    | 项目源码 | 文件源码
def test_price_estimates_endpoint_returns_success(self):
        """Assert that the price estimates endpoint returns success.

        When a valid key is passed in.
        """
        with app.test_client() as client:
            with client.session_transaction() as session:
                session['access_token'] = test_auth_token
            with Betamax(app.requests_session).use_cassette('price_estimates_success'):
                response = client.get('/price')
        self.assertIn('prices', response.data)
        self.assertEquals(response.status_code, 200)
项目:uberemind    作者:mayurbhangale    | 项目源码 | 文件源码
def test_price_estimates_endpoint_returns_failure(self):
        """Assert that the price estimates endpoint returns failure.

        When an invalid key is passed in.
        """
        with app.test_client() as client:
            with client.session_transaction() as session:
                session['access_token'] = 'NOT_A_CODE'
            with Betamax(app.requests_session).use_cassette('price_estimates_failure'):
                response = client.get('/price')
        self.assertEquals(response.status_code, 401)
项目:uberemind    作者:mayurbhangale    | 项目源码 | 文件源码
def test_history_endpoint_returns_success(self):
        """Assert that the history endpoint returns success.

        When a valid key is passed in.
        """
        with app.test_client() as client:
            with client.session_transaction() as session:
                session['access_token'] = test_auth_token
            with Betamax(app.requests_session).use_cassette('history_success'):
                response = client.get('/history')
        self.assertIn('history', response.data)
        self.assertEquals(response.status_code, 200)
项目:uberemind    作者:mayurbhangale    | 项目源码 | 文件源码
def test_me_endpoint_returns_success(self):
        """Assert that the me endpoint returns success.

        When a valid key is passed in.
        """
        with app.test_client() as client:
            with client.session_transaction() as session:
                session['access_token'] = test_auth_token
            with Betamax(app.requests_session).use_cassette('me_success'):
                response = client.get('/me')
        self.assertIn('picture', response.data)
        self.assertEquals(response.status_code, 200)
项目:uberemind    作者:mayurbhangale    | 项目源码 | 文件源码
def test_me_endpoint_returns_failure(self):
        """Assert that the me endpoint returns failure.

        When an invalid key is passed in.
        """
        with app.test_client() as client:
            with client.session_transaction() as session:
                session['access_token'] = 'NOT_A_CODE'
            with Betamax(app.requests_session).use_cassette('me_failure'):
                response = client.get('/me')
        self.assertEquals(response.status_code, 401)
项目:lxc-rest    作者:lxc-webpanel    | 项目源码 | 文件源码
def setUp(self):
        self.db_fd, app.config['DATABASE'] = tempfile.mkstemp()
        app.config[
            'SQLALCHEMY_DATABASE_URI'] = 'sqlite:///%s \
            ' % app.config['DATABASE']
        app.testing = True
        self.app = app.test_client()
        with app.app_context():
            db.create_all()
            populate_db._run()
项目:spotify-suggestions    作者:Jakeway    | 项目源码 | 文件源码
def setUp(self):
        app.config.from_object(os.environ['APP_SETTINGS'])
        self.app = app.test_client()
        db.create_all()
项目:microflack_users    作者:miguelgrinberg    | 项目源码 | 文件源码
def setUp(self):
        self.ctx = app.app_context()
        self.ctx.push()
        db.drop_all()  # just in case
        db.create_all()
        self.client = app.test_client()
项目:holbertonschool_airbnb_clone    作者:johndspence    | 项目源码 | 文件源码
def setUp(self):
        '''Creates a test client, disables logging, connects to the database
        and creates state and city tables for temporary testing purposes.
        '''
        self.app = app.test_client()
        logging.disable(logging.CRITICAL)
        BaseModel.database.connect()
        BaseModel.database.create_tables([User, State, City, Place, PlaceBook])

        '''Create table items for ForeignKeyField requirements.'''
        self.app.post('/users', data=dict(
            first_name="test",
            last_name="test",
            email="test",
            password="test"
        ))

        self.app.post('/states', data=dict(
            name="test"
        ))

        self.app.post('/states/1/cities', data=dict(
            name="test",
            state=1
        ))

        self.app.post('/places', data=dict(
            owner=1,
            city=1,
            name="test",
            description="test",
            latitude=0,
            longitude=0
        ))
项目:holbertonschool_airbnb_clone    作者:johndspence    | 项目源码 | 文件源码
def setUp(self):
        '''Creates a test client, disables logging, connects to the database
        and creates a table State for temporary testing purposes.
        '''
        self.app = app.test_client()
        logging.disable(logging.CRITICAL)
        BaseModel.database.connect()
        BaseModel.database.create_tables([State])
项目:holbertonschool_airbnb_clone    作者:johndspence    | 项目源码 | 文件源码
def setUp(self):
        '''Creates a test client, disables logging, connects to the database
        and creates state and city tables for temporary testing purposes.
        '''
        self.app = app.test_client()
        logging.disable(logging.CRITICAL)
        BaseModel.database.connect()
        BaseModel.database.create_tables([User, City, Place, State, PlaceBook])

        '''Create items in tables for ForeignKeyField requirements'''
        self.app.post('/states', data=dict(name="test"))

        self.app.post('/states/1/cities', data=dict(
            name="test",
            state=1
        ))

        self.app.post('/users', data=dict(
            first_name="test",
            last_name="test",
            email="test",
            password="test"
        ))

        '''Create two places.'''
        for i in range(1, 3):
            self.create_place('/places', 'test_' + str(i))

        '''Create a book on place 1, belonging to user 1.'''
        self.app.post('/places/1/books', data=dict(
            place=1,
            user=1,
            date_start="2000/1/1 00:00:00",
            description="test",
            number_nights=10,
            latitude=0,
            longitude=0
        ))
项目:holbertonschool_airbnb_clone    作者:johndspence    | 项目源码 | 文件源码
def setUp(self):
        '''Creates a test client, disables logging, connects to the database
        and creates state and city tables for temporary testing purposes.
        '''
        self.app = app.test_client()
        logging.disable(logging.CRITICAL)
        BaseModel.database.connect()
        BaseModel.database.create_tables([State, City])

        '''Create a state for routing purposes.'''
        self.app.post('/states', data=dict(name="test"))

        '''Create two new cities.'''
        for i in range(1, 3):
            res = self.create_city("test_" + str(i))
项目:holbertonschool_airbnb_clone    作者:johndspence    | 项目源码 | 文件源码
def setUp(self):
        '''Creates a test client and propagates the exceptions to the test
        client.
        '''
        self.app = app.test_client()
        self.app.testing = True
项目:holbertonschool_airbnb_clone    作者:johndspence    | 项目源码 | 文件源码
def setUp(self):
        '''Creates a test client, disables logging, connects to the database
        and creates a table User for temporary testing purposes.
        '''
        self.app = app.test_client()
        logging.disable(logging.CRITICAL)
        BaseModel.database.connect()
        BaseModel.database.create_tables([User, Place, Review, ReviewPlace,
                                          ReviewUser, City, State])

        '''Add two new users.'''
        for i in range(1, 3):
            self.app.post('/users', data=dict(first_name="user_" + str(i),
                                              last_name="user_" + str(i),
                                              email="user_" + str(i),
                                              password="user_" + str(i)))

        '''Add a state.'''
        self.app.post('/states', data=dict(name="state_1"))

        '''Add a city.'''
        self.app.post('/states/1/cities', data=dict(name="city_1", state=1))

        '''Add a place.'''
        self.app.post('/places', data=dict(owner=1, city=1, name="place_1",
                                           description="place_1", latitude=0,
                                           longitude=0))
项目:holbertonschool_airbnb_clone    作者:johndspence    | 项目源码 | 文件源码
def setUp(self):
        '''Creates a test client, disables logging, connects to the database
        and creates a table User for temporary testing purposes.
        '''
        self.app = app.test_client()
        logging.disable(logging.CRITICAL)
        BaseModel.database.connect()
        BaseModel.database.create_tables([User])