def test_profile_authenticated_get(self):
     with app.test_client() as client:
         client.post("/login", data={"username": "******", "password": "******"}, follow_redirects=True)
         response = client.get("/profile")
         self.assertEqual(response.status_code, 200)
         self.assertIn("<form", response.data)
         self.assertIn("testuser1", response.data)
 def test_feed_authenticated_get_other_users_feed(self):
     with app.test_client() as client:
         client.post("/login", data={"username": "******", "password": "******"}, 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)
Beispiel #3
0
 def test_login_correct(self):
     with app.test_client() as client:
         response = client.post(
             '/login',
             data={'username': '******', 'password': '******'},
             follow_redirects=True)
         self.assertEqual(response.status_code, 200)
         self.assertEqual(session['user_id'], 1)
         self.assertEqual(session['username'], 'testuser1')
 def test_authenticated_login_redirects_next(self):
     with app.test_client() as client:
         client.post('/login',
                     data={'username': '******',
                           'password': '******'},
                     follow_redirects=True)
         response = client.get('/login')
         self.assertEqual(response.status_code, 302)
         self.assertEqual(response.location, 'http://localhost/')
Beispiel #5
0
 def test_authenticated_login_redirects_next(self):
     with app.test_client() as client:
         client.post('/login',
                     data={'username': '******',
                           'password': '******'},
                     follow_redirects=True)
         response = client.get('/login')
         self.assertEqual(response.status_code, 302)
         self.assertEqual(response.location, 'http://localhost/')
 def test_login_correct(self):
     with app.test_client() as client:
         response = client.post(
             '/login',
             data={'username': '******', 'password': '******'},
             follow_redirects=True)
         self.assertEqual(response.status_code, 200)
         self.assertEqual(session['user_id'], 1)
         self.assertEqual(session['username'], 'testuser1')
 def test_profile_authenticated_get(self):
     with app.test_client() as client:
         client.post(
             '/login',
             data={'username': '******', 'password': '******'},
             follow_redirects=True)
         response = client.get('/profile')
         self.assertEqual(response.status_code, 200)
         self.assertIn('<form', response.data)
         self.assertIn('testuser1', response.data)
 def test_profile_authenticated_get(self):
     with app.test_client() as client:
         client.post(
             '/login',
             data={'username': '******', 'password': '******'},
             follow_redirects=True)
         response = client.get('/profile')
         self.assertEqual(response.status_code, 200)
         self.assertIn('<form'.encode('utf-8'), response.data)
         self.assertIn('testuser1'.encode('utf-8'), response.data)
 def test_feed_authenticated_get(self):
     with app.test_client() as client:
         client.post("/login", data={"username": "******", "password": "******"}, 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)
 def test_profile_authenticated_post(self):
     with app.test_client() as client:
         client.post("/login", data={"username": "******", "password": "******"}, follow_redirects=True)
         response = client.post(
             "/profile",
             data={"username": "******", "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)
    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()
    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()
    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()
 def test_feed_authenticated_get_other_users_feed(self):
     with app.test_client() as client:
         client.post(
             '/login',
             data={'username': '******', 'password': '******'},
             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)
 def test_feed_authenticated_get_other_users_feed(self):
     with app.test_client() as client:
         client.post(
             '/login',
             data={'username': '******', 'password': '******'},
             follow_redirects=True)
         response = client.get('/testuser2')  # different as logged in
         self.assertEqual(response.status_code, 200)
         self.assertFalse('<form'.encode('utf-8') in response.data)
         self.assertTrue('Tweet 1 testuser2'.encode('utf-8') in response.data)
         self.assertFalse('Tweet 1 testuser1'.encode('utf-8') in response.data)
         self.assertFalse('Tweet 2 testuser1'.encode('utf-8') in response.data)
    def test_logout(self):
        with app.test_client() as client:
            response = client.post("/login", data={"username": "******", "password": "******"}, 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)
 def test_feed_authenticated_post(self):
     with app.test_client() as client:
         client.post("/login", data={"username": "******", "password": "******"}, 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)
 def test_feed_authenticated_get(self):
     with app.test_client() as client:
         client.post(
             '/login',
             data={'username': '******', 'password': '******'},
             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)
 def test_feed_authenticated_get(self):
     with app.test_client() as client:
         client.post(
             '/login',
             data={'username': '******', 'password': '******'},
             follow_redirects=True)
         response = client.get('/testuser1')
         self.assertEqual(response.status_code, 200)
         self.assertTrue('<form'.encode('utf-8') in response.data)
         self.assertEqual(response.data.count('<form'.encode('utf-8')), 3)  # textarea and 2 tweet delete buttons
         self.assertTrue('Tweet 1 testuser1'.encode('utf-8') in response.data)
         self.assertTrue('Tweet 2 testuser1'.encode('utf-8') in response.data)
         self.assertFalse('Tweet 1 testuser2'.encode('utf-8') in response.data)
    def test_logout(self):
        with app.test_client() as client:
            response = client.post(
                '/login',
                data={'username': '******', 'password': '******'},
                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)
Beispiel #21
0
    def test_logout(self):
        with app.test_client() as client:
            response = client.post(
                '/login',
                data={'username': '******', 'password': '******'},
                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)
    def test_delete_tweet_authenticated(self):
        with app.test_client() as client:
            client.post("/login", data={"username": "******", "password": "******"}, 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)
 def test_feed_authenticated_post(self):
     with app.test_client() as client:
         client.post(
             '/login',
             data={'username': '******', 'password': '******'},
             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'.encode('utf-8') in response.data)
         self.assertEqual(response.data.count('<form'.encode('utf-8')), 4)  # textarea and 3 tweet delete buttons
         self.assertTrue('Tweet 1 testuser1'.encode('utf-8') in response.data)
         self.assertTrue('Tweet 2 testuser1'.encode('utf-8') in response.data)
         self.assertTrue('This tweet is new'.encode('utf-8') in response.data)
         self.assertFalse('Tweet 1 testuser2'.encode('utf-8') in response.data)
 def test_feed_authenticated_post(self):
     with app.test_client() as client:
         client.post(
             '/login',
             data={'username': '******', 'password': '******'},
             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)
Beispiel #25
0
 def test_profile_authenticated_post(self):
     with app.test_client() as client:
         client.post(
             '/login',
             data={'username': '******', 'password': '******'},
             follow_redirects=True)
         response = client.post(
             '/profile',
             data={'username': '******',
                   '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)
 def test_profile_authenticated_post(self):
     with app.test_client() as client:
         client.post(
             '/login',
             data={'username': '******', 'password': '******'},
             follow_redirects=True)
         response = client.post(
             '/profile',
             data={'username': '******',
                   '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)
    def test_delete_tweet_authenticated(self):
        with app.test_client() as client:
            client.post(
                '/login',
                data={'username': '******', 'password': '******'},
                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()), 2)
Beispiel #28
0
    def test_delete_tweet_authenticated(self):
        with app.test_client() as client:
            client.post(
                '/login',
                data={'username': '******', 'password': '******'},
                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)
 def test_authenticated_login_redirects_next(self):
     with app.test_client() as client:
         client.post("/login", data={"username": "******", "password": "******"}, follow_redirects=True)
         response = client.get("/login")
         self.assertEqual(response.status_code, 302)
         self.assertEqual(response.location, "http://localhost/")
 def test_login_correct(self):
     with app.test_client() as client:
         response = client.post("/login", data={"username": "******", "password": "******"}, follow_redirects=True)
         self.assertEqual(response.status_code, 200)
         self.assertEqual(session["user_id"], 1)
         self.assertEqual(session["username"], "testuser1")