python类test_client()的实例源码

test_endpoints.py 文件源码 项目:uberemind 作者: mayurbhangale 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
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)
test_endpoints.py 文件源码 项目:uberemind 作者: mayurbhangale 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
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)
test_endpoints.py 文件源码 项目:uberemind 作者: mayurbhangale 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
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)
test_endpoints.py 文件源码 项目:uberemind 作者: mayurbhangale 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
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)
test_endpoints.py 文件源码 项目:uberemind 作者: mayurbhangale 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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)
test_endpoints.py 文件源码 项目:uberemind 作者: mayurbhangale 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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)
test_endpoints.py 文件源码 项目:uberemind 作者: mayurbhangale 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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)
test_endpoints.py 文件源码 项目:uberemind 作者: mayurbhangale 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
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)
tests.py 文件源码 项目:lxc-rest 作者: lxc-webpanel 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
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()
tests.py 文件源码 项目:spotify-suggestions 作者: Jakeway 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def setUp(self):
        app.config.from_object(os.environ['APP_SETTINGS'])
        self.app = app.test_client()
        db.create_all()
tests.py 文件源码 项目:microflack_users 作者: miguelgrinberg 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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()
place_book.py 文件源码 项目:holbertonschool_airbnb_clone 作者: johndspence 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
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
        ))
state.py 文件源码 项目:holbertonschool_airbnb_clone 作者: johndspence 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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])
place.py 文件源码 项目:holbertonschool_airbnb_clone 作者: johndspence 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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
        ))
city.py 文件源码 项目:holbertonschool_airbnb_clone 作者: johndspence 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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))
index.py 文件源码 项目:holbertonschool_airbnb_clone 作者: johndspence 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def setUp(self):
        '''Creates a test client and propagates the exceptions to the test
        client.
        '''
        self.app = app.test_client()
        self.app.testing = True
review.py 文件源码 项目:holbertonschool_airbnb_clone 作者: johndspence 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
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))
user.py 文件源码 项目:holbertonschool_airbnb_clone 作者: johndspence 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
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])


问题


面经


文章

微信
公众号

扫码关注公众号