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


Python app.test_client函数代码示例

本文整理汇总了Python中twitter_clone.main.app.test_client函数的典型用法代码示例。如果您正苦于以下问题:Python test_client函数的具体用法?Python test_client怎么用?Python test_client使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_profile_authenticated_get

 def test_profile_authenticated_get(self):
     with app.test_client() as client:
         client.post("/login", data={"username": "testuser1", "password": "1234"}, follow_redirects=True)
         response = client.get("/profile")
         self.assertEqual(response.status_code, 200)
         self.assertIn("<form", response.data)
         self.assertIn("testuser1", response.data)
开发者ID:Zizibaluba,项目名称:pyp-w4-gw-twitter-clone,代码行数:7,代码来源:test_main.py

示例2: test_authenticated_login_redirects_next

 def test_authenticated_login_redirects_next(self):
     with app.test_client() as client:
         client.post('/login',
                     data={'username': 'testuser1',
                           'password': '1234'},
                     follow_redirects=True)
         response = client.get('/login')
         self.assertEqual(response.status_code, 302)
         self.assertEqual(response.location, 'http://localhost/')
开发者ID:bdauer,项目名称:pyp-w4-gw-twitter-clone,代码行数:9,代码来源:test_main.py

示例3: test_login_correct

 def test_login_correct(self):
     with app.test_client() as client:
         response = client.post(
             '/login',
             data={'username': 'testuser1', 'password': '1234'},
             follow_redirects=True)
         self.assertEqual(response.status_code, 200)
         self.assertEqual(session['user_id'], 1)
         self.assertEqual(session['username'], 'testuser1')
开发者ID:bdauer,项目名称:pyp-w4-gw-twitter-clone,代码行数:9,代码来源:test_main.py

示例4: test_feed_authenticated_get_other_users_feed

 def test_feed_authenticated_get_other_users_feed(self):
     with app.test_client() as client:
         client.post("/login", data={"username": "testuser1", "password": "1234"}, follow_redirects=True)
         response = client.get("/testuser2")  # different as logged in
         self.assertEqual(response.status_code, 200)
         self.assertFalse("<form" in response.data)
         self.assertTrue("Tweet 1 testuser2" in response.data)
         self.assertFalse("Tweet 1 testuser1" in response.data)
         self.assertFalse("Tweet 2 testuser1" in response.data)
开发者ID:Zizibaluba,项目名称:pyp-w4-gw-twitter-clone,代码行数:9,代码来源:test_main.py

示例5: test_profile_authenticated_get

 def test_profile_authenticated_get(self):
     with app.test_client() as client:
         client.post(
             '/login',
             data={'username': 'testuser1', 'password': '1234'},
             follow_redirects=True)
         response = client.get('/profile')
         self.assertEqual(response.status_code, 200)
         self.assertIn('<form', response.data)
         self.assertIn('testuser1', response.data)
开发者ID:bdauer,项目名称:pyp-w4-gw-twitter-clone,代码行数:10,代码来源:test_main.py

示例6: test_feed_authenticated_get

 def test_feed_authenticated_get(self):
     with app.test_client() as client:
         client.post("/login", data={"username": "testuser1", "password": "1234"}, follow_redirects=True)
         response = client.get("/testuser1")
         self.assertEqual(response.status_code, 200)
         self.assertTrue("<form" in response.data)
         self.assertEqual(response.data.count("<form"), 3)  # textarea and 2 tweet delete buttons
         self.assertTrue("Tweet 1 testuser1" in response.data)
         self.assertTrue("Tweet 2 testuser1" in response.data)
         self.assertFalse("Tweet 1 testuser2" in response.data)
开发者ID:Zizibaluba,项目名称:pyp-w4-gw-twitter-clone,代码行数:10,代码来源:test_main.py

示例7: test_profile_authenticated_post

 def test_profile_authenticated_post(self):
     with app.test_client() as client:
         client.post("/login", data={"username": "testuser1", "password": "1234"}, follow_redirects=True)
         response = client.post(
             "/profile",
             data={"username": "testuser1", "first_name": "Test", "last_name": "User", "birth_date": "2016-01-30"},
         )
         self.assertEqual(response.status_code, 200)
         profile = self.db.execute("select * from user where id = 1;").fetchone()
         expected = (1, u"testuser1", u"81dc9bdb52d04dc20036dbd8313ed055", u"Test", u"User", "2016-01-30")
         self.assertEqual(profile, expected)
开发者ID:Zizibaluba,项目名称:pyp-w4-gw-twitter-clone,代码行数:11,代码来源:test_main.py

示例8: setUp

    def setUp(self):
        app.config["TESTING"] = True
        app.config["SECRET_KEY"] = "testing secret key"
        app.config["DATABASE"] = tempfile.mkstemp()

        # set up testing database
        db = connect_db(db_name=app.config["DATABASE"][1])
        self.db = db
        self.load_fixtures()

        self.client = app.test_client()
开发者ID:Zizibaluba,项目名称:pyp-w4-gw-twitter-clone,代码行数:11,代码来源:test_main.py

示例9: test_feed_authenticated_get_other_users_feed

 def test_feed_authenticated_get_other_users_feed(self):
     with app.test_client() as client:
         client.post(
             '/login',
             data={'username': 'testuser1', 'password': '1234'},
             follow_redirects=True)
         response = client.get('/testuser2')  # different as logged in
         self.assertEqual(response.status_code, 200)
         self.assertFalse('<form' in response.data)
         self.assertTrue('Tweet 1 testuser2' in response.data)
         self.assertFalse('Tweet 1 testuser1' in response.data)
         self.assertFalse('Tweet 2 testuser1' in response.data)
开发者ID:bdauer,项目名称:pyp-w4-gw-twitter-clone,代码行数:12,代码来源:test_main.py

示例10: test_logout

    def test_logout(self):
        with app.test_client() as client:
            response = client.post("/login", data={"username": "testuser1", "password": "1234"}, follow_redirects=True)
            self.assertEqual(response.status_code, 200)
            self.assertEqual(session["user_id"], 1)
            self.assertEqual(session["username"], "testuser1")

            response = client.get("/logout")
            self.assertEqual(response.status_code, 302)
            self.assertEqual("http://localhost/", response.location)
            self.assertFalse("user_id" in session)
            self.assertFalse("username" in session)
开发者ID:Zizibaluba,项目名称:pyp-w4-gw-twitter-clone,代码行数:12,代码来源:test_main.py

示例11: test_feed_authenticated_get

 def test_feed_authenticated_get(self):
     with app.test_client() as client:
         client.post(
             '/login',
             data={'username': 'testuser1', 'password': '1234'},
             follow_redirects=True)
         response = client.get('/testuser1')
         self.assertEqual(response.status_code, 200)
         self.assertTrue('<form' in response.data)
         self.assertEqual(response.data.count('<form'), 3)  # textarea and 2 tweet delete buttons
         self.assertTrue('Tweet 1 testuser1' in response.data)
         self.assertTrue('Tweet 2 testuser1' in response.data)
         self.assertFalse('Tweet 1 testuser2' in response.data)
开发者ID:bdauer,项目名称:pyp-w4-gw-twitter-clone,代码行数:13,代码来源:test_main.py

示例12: test_feed_authenticated_post

 def test_feed_authenticated_post(self):
     with app.test_client() as client:
         client.post("/login", data={"username": "testuser1", "password": "1234"}, follow_redirects=True)
         response = client.post("/testuser1", data={"tweet": "This tweet is new"})
         self.assertEqual(response.status_code, 200)
         cursor = self.db.execute("select * from tweet where user_id = 1;")
         self.assertEqual(len(cursor.fetchall()), 3)
         self.assertTrue("<form" in response.data)
         self.assertEqual(response.data.count("<form"), 4)  # textarea and 3 tweet delete buttons
         self.assertTrue("Tweet 1 testuser1" in response.data)
         self.assertTrue("Tweet 2 testuser1" in response.data)
         self.assertTrue("This tweet is new" in response.data)
         self.assertFalse("Tweet 1 testuser2" in response.data)
开发者ID:Zizibaluba,项目名称:pyp-w4-gw-twitter-clone,代码行数:13,代码来源:test_main.py

示例13: test_delete_tweet_authenticated

    def test_delete_tweet_authenticated(self):
        with app.test_client() as client:
            client.post("/login", data={"username": "testuser1", "password": "1234"}, follow_redirects=True)

            # pre condition, must be 2 tweets
            cursor = self.db.execute("select * from tweet where user_id = 1;")
            self.assertEqual(len(cursor.fetchall()), 2)

            # delete tweet with id=1
            response = client.post("/tweets/1/delete")
            self.assertEqual(response.status_code, 302)
            self.assertEqual("http://localhost/", response.location)

            cursor = self.db.execute("select * from tweet where user_id = 1;")
            self.assertEqual(len(cursor.fetchall()), 1)
开发者ID:Zizibaluba,项目名称:pyp-w4-gw-twitter-clone,代码行数:15,代码来源:test_main.py

示例14: test_logout

    def test_logout(self):
        with app.test_client() as client:
            response = client.post(
                '/login',
                data={'username': 'testuser1', 'password': '1234'},
                follow_redirects=True)
            self.assertEqual(response.status_code, 200)
            self.assertEqual(session['user_id'], 1)
            self.assertEqual(session['username'], 'testuser1')

            response = client.get('/logout')
            self.assertEqual(response.status_code, 302)
            self.assertEqual('http://localhost/', response.location)
            self.assertFalse('user_id' in session)
            self.assertFalse('username' in session)
开发者ID:bdauer,项目名称:pyp-w4-gw-twitter-clone,代码行数:15,代码来源:test_main.py

示例15: test_feed_authenticated_post

 def test_feed_authenticated_post(self):
     with app.test_client() as client:
         client.post(
             '/login',
             data={'username': 'testuser1', 'password': '1234'},
             follow_redirects=True)
         response = client.post('/testuser1', data={'tweet': 'This tweet is new'})
         self.assertEqual(response.status_code, 200)
         cursor = self.db.execute("select * from tweet where user_id = 1;")
         self.assertEqual(len(cursor.fetchall()), 3)
         self.assertTrue('<form' in response.data)
         self.assertEqual(response.data.count('<form'), 4)  # textarea and 3 tweet delete buttons
         self.assertTrue('Tweet 1 testuser1' in response.data)
         self.assertTrue('Tweet 2 testuser1' in response.data)
         self.assertTrue('This tweet is new' in response.data)
         self.assertFalse('Tweet 1 testuser2' in response.data)
开发者ID:bdauer,项目名称:pyp-w4-gw-twitter-clone,代码行数:16,代码来源:test_main.py


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