当前位置: 首页>>代码示例>>Python>>正文


Python TestApp.get方法代码示例

本文整理汇总了Python中flask.ext.webtest.TestApp.get方法的典型用法代码示例。如果您正苦于以下问题:Python TestApp.get方法的具体用法?Python TestApp.get怎么用?Python TestApp.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flask.ext.webtest.TestApp的用法示例。


在下文中一共展示了TestApp.get方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: IssPassTest

# 需要导入模块: from flask.ext.webtest import TestApp [as 别名]
# 或者: from flask.ext.webtest.TestApp import get [as 别名]
class IssPassTest(TestCase):
    """Test ISS-pass API"""
    def setUp(self):
        self.app = app
        self.w = TestApp(self.app)
        self.endpoint = '/iss-pass.json'

    def format_uri(self, lat, lon):
        return self.endpoint + '?lat={0}&lon={1}'.format(lat, lon) 
    
    def test_berkeley(self):
        berkeley = self.format_uri(37.8715926, -122.27274699999998)
        r = self.w.get(berkeley)
        r.charset = 'utf8'
        data = json.loads(r.text)
        self.assertEqual(r.status_code, 200)

    def test_no_passes_found(self):
        mcmurdo_station = self.format_uri(-77.8418779, 166.6863449)
        r = self.w.get(mcmurdo_station)
        self.assertEqual(r.status_code, 200)
        data = r.json
        self.assertEqual(len(data['response']), 0)

    def test_bad_lat(self):
        bad_lat = self.format_uri(-91, 50)
        r = self.w.get(bad_lat, expect_errors=True)
        self.assertEqual(r.status_code, 400)
开发者ID:margaret,项目名称:Open-Notify-API,代码行数:30,代码来源:api.py

示例2: AstrosTest

# 需要导入模块: from flask.ext.webtest import TestApp [as 别名]
# 或者: from flask.ext.webtest.TestApp import get [as 别名]
class AstrosTest(TestCase):
    """Test the number of astros API"""

    def setUp(self):
        self.app = app
        self.w = TestApp(self.app)

    def test_load_astros(self):
        r = self.w.get('/astros.json')
        self.assertFalse(r.flashes)
        r = self.w.get('/astros/')
        self.assertFalse(r.flashes)
        r = self.w.get('/astros/v1')
        self.assertFalse(r.flashes)

    def test_data(self):
        r = self.w.get('/astros.json')
        r.charset = 'utf8'
        try:
            data = json.loads(r.text)
        except:
            self.fail("ISS API not a valid JSON responce")

        # Success message
        self.assertEqual(data['message'], "success", "ISS API Did not return 'sucess' message")

        # data exists
        self.assertTrue('number' in data)
        self.assertEqual(type(data['number']), int)
        self.assertTrue('people' in data)
开发者ID:margaret,项目名称:Open-Notify-API,代码行数:32,代码来源:api.py

示例3: IssNowTest

# 需要导入模块: from flask.ext.webtest import TestApp [as 别名]
# 或者: from flask.ext.webtest.TestApp import get [as 别名]
class IssNowTest(TestCase):
    """Test the ISS-now API"""

    def setUp(self):
        self.app = app
        self.w = TestApp(self.app)

    def test_load(self):
        # Test the endpoints
        r = self.w.get('/iss-now.json')
        self.assertFalse(r.flashes)
        r = self.w.get('/iss-now/')
        self.assertFalse(r.flashes)
        r = self.w.get('/iss-now/v1')
        self.assertFalse(r.flashes)

    def test_data(self):
        r = self.w.get('/iss-now.json')
        r.charset = 'utf8'
        try:
            data = json.loads(r.text)
        except:
            self.fail("ISS API not a valid JSON response")

        # Success message
        self.assertEqual(data['message'], "success", "ISS API Did not return 'sucess' message")

        # timestamp exists
        self.assertTrue('timestamp' in data)

        # position data
        self.assertTrue('iss_position' in data)
        self.assertTrue('latitude' in data['iss_position'])
        self.assertTrue('longitude' in data['iss_position'])
开发者ID:margaret,项目名称:Open-Notify-API,代码行数:36,代码来源:api.py

示例4: TestPosts

# 需要导入模块: from flask.ext.webtest import TestApp [as 别名]
# 或者: from flask.ext.webtest.TestApp import get [as 别名]
class TestPosts(DbTestCase, LoggedInUserCase):
    def setUp(self):
        self.w = TestApp(self.app)
        self.user = UserFactory(password="myprecious")
        self.user.save()

    def test_can_create(self):
        self._login(self.w, self.user)

        res = self.w.get(url_for("user.add_post"))

        form = res.forms["newPost"]

        form['title'] = "test post please ignore"
        form['subreddit'] = "reddit.com"
        form['body'] = "This is a test post."
        form['distinguish'] = False
        form['sticky'] = False
        form['scheduled_hour'] = 12
        form['scheduled_minute'] = 00

        res = form.submit().follow()
        assert_equal(res.status_code, 200)

    def test_can_submit_edit_form_without_changes(self):
        self._login(self.w, self.user)

        post = PostFactory()

        self.user.posts.append(post)
        self.user.save()

        res = self.w.get(url_for('user.edit_post', id=post.id))
        form = res.forms["newPost"]
        res = form.submit().follow()

    def test_can_edit(self):
        self._login(self.w, self.user)

        post = PostFactory()

        self.user.posts.append(post)
        self.user.save()

        res = self.w.get(url_for('user.edit_post', id=post.id))

        new_title = "this is a test title"

        form = res.forms["newPost"]

        previous_day_value = form['monday']

        form['title'] = new_title
        form['monday'] = not previous_day_value

        res = form.submit().follow()
        assert_equal(post.title, new_title)
        assert_equal(post.days.monday, not previous_day_value)
开发者ID:Widdershin,项目名称:autoposter,代码行数:60,代码来源:webtest_tests.py

示例5: TestLoggingIn

# 需要导入模块: from flask.ext.webtest import TestApp [as 别名]
# 或者: from flask.ext.webtest.TestApp import get [as 别名]
class TestLoggingIn(DbTestCase):

    def setUp(self):
        self.w = TestApp(self.app)
        self.user = UserFactory(password="myprecious")
        self.user.save()

    def test_can_log_in(self):
        # Goes to homepage
        res = self.w.get("/")
        # Fills out login form in navbar
        form = res.forms['loginForm']
        form['username'] = self.user.username
        form['password'] = 'myprecious'
        # Submits
        res = form.submit().maybe_follow()
        assert_equal(res.status_code, 200)

    def _login(self, username, password):
        res = self.w.get("/")
        # Fills out login form in navbar
        form = res.forms['loginForm']
        form['username'] = username
        form['password'] = password
        # Submits
        res = form.submit().maybe_follow()
        return res

    def test_sees_alert_on_log_out(self):
        res = self._login(self.user.username, 'myprecious')
        res = self.w.get(url_for('public.logout')).maybe_follow()
        # sees alert
        assert_in('You are logged out.', res)

    def test_sees_error_message_if_password_is_incorrect(self):
        # Goes to homepage
        res = self.w.get("/")
        # Fills out login form, password incorrect
        form = res.forms['loginForm']
        form['username'] = self.user.username
        form['password'] = 'wrong'
        # Submits
        res = form.submit()
        # sees error
        assert_in("Invalid password", res)

    def test_sees_error_message_if_username_doesnt_exist(self):
        # Goes to homepage
        res = self.w.get("/")
        # Fills out login form, password incorrect
        form = res.forms['loginForm']
        form['username'] = 'unknown'
        form['password'] = 'myprecious'
        # Submits
        res = form.submit()
        # sees error
        assert_in("Unknown user", res)
开发者ID:Anioko,项目名称:cookiecutter-flask,代码行数:59,代码来源:webtest_tests.py

示例6: test_init

# 需要导入模块: from flask.ext.webtest import TestApp [as 别名]
# 或者: from flask.ext.webtest.TestApp import get [as 别名]
    def test_init(self):
        w = TestApp(self.app)
        self.assertEqual(w.get('/').status_code, 200)

        original_server_name = self.app.config['SERVER_NAME']
        try:
            self.app.config['SERVER_NAME'] = 'webtest-app.local'
            w = TestApp(self.app)
            self.assertEqual(w.get('/').status_code, 200)
        finally:
            self.app.config['SERVER_NAME'] = original_server_name
开发者ID:liushaochan,项目名称:cn486,代码行数:13,代码来源:test.py

示例7: TestSQLAlchemyFeatures

# 需要导入模块: from flask.ext.webtest import TestApp [as 别名]
# 或者: from flask.ext.webtest.TestApp import get [as 别名]
class TestSQLAlchemyFeatures(unittest.TestCase):
    def setUp(self):
        self.app = create_app()
        self.w_without_scoping = TestApp(self.app)
        self.w = TestApp(self.app, db=db, use_session_scopes=True)

        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()

    def tearDown(self):
        db.drop_all()
        self.app_context.pop()

    def test_1(self):
        user = User(name='Anton')
        db.session.add(user)
        db.session.commit()

        r = self.w.get('/user/%i/' % user.id)
        self.assertEqual(r.body, 'Hello, Anton!')

        # Note: we did not commit the change to `user`!
        user.name = 'Petr'

        r = self.w_without_scoping.get('/user/%i/' % user.id)
        self.assertEqual(r.body, 'Hello, Petr!')

        r = self.w.get('/user/%i/' % user.id)
        self.assertEqual(r.body, 'Hello, Anton!')

    def test_2(self):
        user = User(name='Anton')
        db.session.add(user)
        db.session.commit()

        r = self.w.get('/user/%i/' % user.id)
        self.assertEqual(r.body, 'Hello, Anton!')

        r = self.w.post('/user/%i/preview/' % user.id, {
            'greeting': 'Hi, %s.',
        })
        self.assertEqual(r.body, 'Hi, Anton.')
        db.session.refresh(user)

        r = self.w_without_scoping.post('/user/%i/preview/' % user.id, {
            'greeting': 'Hi, %s.',
        })
        self.assertEqual(r.body, 'Hi, Anton.')
        self.assertRaises(
            sqlalchemy.exc.InvalidRequestError,
            lambda: db.session.refresh(user))
开发者ID:liushaochan,项目名称:cn486,代码行数:54,代码来源:test.py

示例8: TestRegistering

# 需要导入模块: from flask.ext.webtest import TestApp [as 别名]
# 或者: from flask.ext.webtest.TestApp import get [as 别名]
class TestRegistering(DbTestCase):

    def setUp(self):
        self.w = TestApp(self.app)

    def test_can_register(self):
        # Goes to homepage
        res = self.w.get("/")
        # Clicks Create Account button
        res = res.click("Create account")
        # Fills out the form
        form = res.forms["registerForm"]
        form['username'] = 'foobar'
        form['email'] = '[email protected]'
        form['password'] = 'secret'
        form['confirm'] = 'secret'
        # Submits
        res = form.submit().maybe_follow()
        assert_equal(res.status_code, 200)
        # A new user was created
        assert_equal(len(User.query.all()), 1)

    def test_sees_error_message_if_passwords_dont_match(self):
        # Goes to registration page
        res = self.w.get(url_for("public.register"))
        # Fills out form, but passwords don't match
        form = res.forms["registerForm"]
        form['username'] = 'foobar'
        form['email'] = '[email protected]'
        form['password'] = 'secret'
        form['confirm'] = 'secrets'
        # Submits
        res = form.submit()
        # sees error message
        assert_in("Passwords must match", res)

    def test_sees_error_message_if_user_already_registered(self):
        user = UserFactory(active=True)  # A registered user
        user.save()
        # Goes to registration page
        res = self.w.get(url_for("public.register"))
        # Fills out form, but username is already registered
        form = res.forms["registerForm"]
        form['username'] = user.username
        form['email'] = '[email protected]'
        form['password'] = 'secret'
        form['confirm'] = 'secret'
        # Submits
        res = form.submit()
        # sees error
        assert_in("Username already registered", res)
开发者ID:Anioko,项目名称:cookiecutter-flask,代码行数:53,代码来源:webtest_tests.py

示例9: MyTests

# 需要导入模块: from flask.ext.webtest import TestApp [as 别名]
# 或者: from flask.ext.webtest.TestApp import get [as 别名]
class MyTests(TestCase):

    def setUp(self):
        self.app = app
        self.w = TestApp(self.app)

    def test_base_url_returns_response(self):
        r = self.w.get('/')
        self.assertFalse(r.flashes)
开发者ID:basilleaf,项目名称:base_flask_redis_app,代码行数:11,代码来源:tests.py

示例10: ViewsTestCase

# 需要导入模块: from flask.ext.webtest import TestApp [as 别名]
# 或者: from flask.ext.webtest.TestApp import get [as 别名]
class ViewsTestCase(TestCase):

    def setUp(self):
        self.app = app
        self.w = TestApp(self.app)

    def test_home(self):

        r = self.w.get('/')

        self.assertEquals(r.status_code, 200)
开发者ID:charliequinn,项目名称:pythonglasgow,代码行数:13,代码来源:test_views.py

示例11: TestMainFeatures

# 需要导入模块: from flask.ext.webtest import TestApp [as 别名]
# 或者: from flask.ext.webtest.TestApp import get [as 别名]
class TestMainFeatures(unittest.TestCase):
    def setUp(self):
        self.app = app1
        self.w = TestApp(self.app)

    def test_single_template(self):
        r = self.w.get('/')
        self.assertFalse(r.flashes)
        self.assertEqual(len(r.contexts), 1)

        self.assertEqual(r.context['text'], 'Hello!')
        self.assertEqual(r.template, 'template.html')
        self.assertNotIn('qwerty', r.session)

    def test_two_templates_and_flash_messages(self):
        r = self.w.get('/').form.submit()
        self.assertEqual(len(r.contexts), 2)

        if flask_gte_0_10:
            self.assertEqual(len(r.flashes), 2)
            category, message = r.flashes[0]
            self.assertEqual(message, 'You have pressed "Quit"...')
            
            category, message = r.flashes[1]
            self.assertEqual(message, 'Flash message that will never be shown')
        else:
            self.assertEqual(len(r.flashes), 1)
            category, message = r.flashes[0]
            self.assertEqual(message, 'You have pressed "Quit"...')

        with self.assertRaises(AssertionError):
            r.context  # Because there are more than one used templates
        self.assertEqual(
            r.contexts['template.html']['text'],
            'Goodbye!')
        self.assertEqual(
            r.contexts['extra-template.html']['extra_text'],
            'Some text.')
开发者ID:titovanton,项目名称:flask-webtest,代码行数:40,代码来源:test.py

示例12: FrontPageTest

# 需要导入模块: from flask.ext.webtest import TestApp [as 别名]
# 或者: from flask.ext.webtest.TestApp import get [as 别名]
class FrontPageTest(TestCase):
    """Test that the front page is rendering"""

    def setUp(self):
        self.app = app
        self.w = TestApp(self.app)

    def test(self):
        r = self.w.get('/')

        # Assert there was no messages flashed
        self.assertFalse(r.flashes)

        # Assert that we got an index template
        self.assertEqual(r.template, 'index.html')
开发者ID:margaret,项目名称:Open-Notify-API,代码行数:17,代码来源:web.py

示例13: TestMainFeatures

# 需要导入模块: from flask.ext.webtest import TestApp [as 别名]
# 或者: from flask.ext.webtest.TestApp import get [as 别名]
class TestMainFeatures(unittest.TestCase):
    def setUp(self):
        self.app = create_app()
        self.w = TestApp(self.app)

    def test_single_template(self):
        r = self.w.get('/')
        self.assertFalse(r.flashes)
        self.assertEqual(len(r.contexts), 1)

        self.assertEqual(r.context['text'], 'Hello!')
        self.assertEqual(r.template, 'template.html')
        self.assertNotIn('qwerty', r.session)

    def test_two_templates_and_flash_messages(self):
        r = self.w.get('/').form.submit()
        self.assertEqual(len(r.contexts), 2)

        if flask_gte_0_10:
            self.assertEqual(len(r.flashes), 2)
            category, message = r.flashes[0]
            self.assertEqual(message, 'You have pressed "Quit"...')

            category, message = r.flashes[1]
            self.assertEqual(message, 'Flash message that will never be shown')
        else:
            self.assertEqual(len(r.flashes), 1)
            category, message = r.flashes[0]
            self.assertEqual(message, 'You have pressed "Quit"...')

        with self.assertRaises(AssertionError):
            r.context  # Because there are more than one used templates
        self.assertEqual(
            r.contexts['template.html']['text'],
            'Goodbye!')
        self.assertEqual(
            r.contexts['extra-template.html']['extra_text'],
            'Some text.')

    def test_session_transaction(self):
        r = self.w.get('/whoami/')
        self.assertEqual(r.body, 'nobody')

        with self.w.session_transaction() as sess:
            sess['username'] = 'aromanovich'

        r = self.w.get('/whoami/')

        self.assertEqual(r.session['username'], 'aromanovich')
        self.assertEqual(r.body, 'aromanovich')

    def test_init(self):
        w = TestApp(self.app)
        self.assertEqual(w.get('/').status_code, 200)

        original_server_name = self.app.config['SERVER_NAME']
        try:
            self.app.config['SERVER_NAME'] = 'webtest-app.local'
            w = TestApp(self.app)
            self.assertEqual(w.get('/').status_code, 200)
        finally:
            self.app.config['SERVER_NAME'] = original_server_name
开发者ID:liushaochan,项目名称:cn486,代码行数:64,代码来源:test.py

示例14: TestMainFeatures

# 需要导入模块: from flask.ext.webtest import TestApp [as 别名]
# 或者: from flask.ext.webtest.TestApp import get [as 别名]
class TestMainFeatures(unittest.TestCase):
    def setUp(self):
        self.app = create_app()
        self.w = TestApp(self.app)
        self.app.config['TESTING'] = True

    def login(self, username, password):
        return self.w.post('/account/login', {
            'email': username,
            'password': password
        })

    def logout(self):
        return self.w.get('/account/logout')

    def test_home(self):
        r = self.w.get('/entry/')
        self.assertFalse(r.flashes)
        self.assertEqual(r.json, {u'code': ResultCode.SUCCESS})

    def test_curd(self):
        # add

        # 登录
        # r = self.login('[email protected]', 'admin888')
        # print r
        # assert 'You were logged in' in r.data

        r = self.w.post('/entry/v1/create?category_id=1', {
            'creater_id': 1,
            'modifier_id': 1,

            'entry_type': EntryType.software,

            'title': '文章测试123',
            'content': '文章测试内容123',
            'summary': '123',
            'tags': 'tag1,tag2,tag3',

            'logo': '/1.gif',
            'feature_image': '/1.png',

            'source_title': '',
            'source_url': '',

            'source_type': EntrySourceType.original,

            'slug': 'ar/1',

            'recommend': 1

        })

        if r.json['code'] != ResultCode.SUCCESS:
            print r.json['message']

        print r

        self.assertFalse(r.flashes)
        self.assertIn(r.json['code'], [ResultCode.SUCCESS, ResultCode.DATA_EXISTED])

        # update
        r = self.w.post('/entry/v1/edit?category_id=1&entry_id=1', {
            'title': '文章测试123, edit',
        })

        print r
        if r.json['code'] != ResultCode.SUCCESS:
            print r.json['message']

        self.assertFalse(r.flashes)
        self.assertIn(r.json['code'], [ResultCode.SUCCESS, ResultCode.DATA_EXISTED])

        return
        # get
        r = self.w.get('/device/%s' % device_id)

        self.assertFalse(r.flashes)
        self.assertEqual(r.json['code'], ResultCode.SUCCESS)
        self.assertTrue(r.json['metadata'])

        # get_list
        r = self.w.get('/device/list?search=%s' % 'len')

        self.assertFalse(r.flashes)
        self.assertEqual(r.json['code'], ResultCode.SUCCESS)
        self.assertTrue(r.json['device_total'] >= 0)

        # del
        r = self.w.post('/device/delete', {
            'device_id': device_id, })

        self.assertFalse(r.flashes)
        self.assertIn(r.json['code'], [ResultCode.SUCCESS, ResultCode.DATA_EXISTED])
开发者ID:liushaochan,项目名称:cn486,代码行数:96,代码来源:test_entry.py


注:本文中的flask.ext.webtest.TestApp.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。