Exemplo n.º 1
0
 def test_logout(self):
     tester = app.test_client(self)
     tester.post('/login',
                 data=dict(email="Manny@hdsalkfjal", password="******"),
                 follow_redirects=True)
     response = tester.get('/logout', follow_redirects=True)
     self.assertIn(b'You have successfully logged out', response.data)
Exemplo n.º 2
0
 def test_incorrect_login(self):
     tester = app.test_client(self)
     response = tester.post('/login',
                            data=dict(email="Manny@hdsalkfjal",
                                      password="******"),
                            follow_redirects=True)
     self.assertIn(b'Invalid login', response.data)
Exemplo n.º 3
0
 def test_main(self):
     with app.test_client() as client:
         # send data as POST form to endpoint
         sent = {'username': '******', 'password': '******'}
         response = client.post('/login', data=sent)
         print(response.data)
         assertTrue(self, response)
Exemplo n.º 4
0
 def test_index_page(self):
     tester = app.test_client(self)
     tester.post('/login',
                 data=dict(email="Manny@hdsalkfjal", password="******"),
                 follow_redirects=True)
     response = tester.get('/list', content_type='html/text')
     self.assertTrue(b'Books' in response.data)
Exemplo n.º 5
0
 def test_index(self):
     tester = app.test_client(self)
     tester.post('/login',
                 data=dict(email="Manny@hdsalkfjal", password="******"),
                 follow_redirects=True)
     response = tester.get('/list', content_type='html/text')
     self.assertEqual(response.status_code, 200)
Exemplo n.º 6
0
 def test_main_page(self):
     with app.test_client() as c:
         with c.session_transaction() as session:
             session['logged_in'] = True
             session['username'] = '******'
     response = self.app.get('/edit_template/1', follow_redirects=True)
     assertTrue(self, response)
     print(response.data)
Exemplo n.º 7
0
 def test_check_login(self):
     tester = app.test_client(self)
     response = tester.post('user/check_login',
                            data=json.dumps(
                                dict(email="Manny@hdsalkfjal",
                                     password_candidate="12345678")),
                            follow_redirects=True,
                            content_type='application/json')
     self.assertEqual(response.content_type, 'application/json')
Exemplo n.º 8
0
 def test_update_book(self):
     tester = app.test_client(self)
     tester.put('/book/14',
                data=json.dumps(
                    dict(isbn="7926410434",
                         title="Dubmo 2",
                         author="Steven spils",
                         date="1998")),
                follow_redirects=True,
                content_type='application/json')
     response = tester.get('/book/14')
     self.assertIn(b'"title": "Dubmo 2"', response.data)
Exemplo n.º 9
0
 def test_create_book(self):
     tester = app.test_client(self)
     tester.post('/book',
                 data=json.dumps(
                     dict(isbn="019374692",
                          title="NEW BOOK",
                          author="Steven spils",
                          date="1998",
                          userId="3")),
                 follow_redirects=True,
                 content_type='application/json')
     response = tester.get('/book/15', follow_redirects=True)
     self.assertIn(b'"author": "Steven spils"', response.data)
Exemplo n.º 10
0
    def setUp(self):
        #import config
        #from database import db
        app.config['TESTING'] = True
        #app.config['WTF_CSRF_ENABLED'] = False
        #app.config['DEBUG'] = False
        app.secret_key = 'secret123'
        self.app = app.test_client()
        #db.drop_all()
        #db.create_all()

        # Disable sending emails during unit testing
        #mail.init_app(app)
        self.assertEqual(app.debug, False)
Exemplo n.º 11
0
 def test_delete_article(self):
     with app.app_context():
         #articles=db.query_db('select * from articles_v')
         articles = db.Articles().query.all()
         #for article in articles:
         #print(article['id'])
     with app.test_client() as c:
         #app.config['DATABASE']='blue/site/Test.db'
         with c.session_transaction() as session:
             session['logged_in'] = True
             session['username'] = '******'
         # send data as POST form to endpoint
         for article in articles:
             #print(article['id'])
             #sent = {'title':'EDIT'+str(article['id']),'body':str(article['body'])+'-EDIT'}
             response = c.post('/delete_article/' + str(article.id))
             print(response.data)
             assertTrue(self, response)
Exemplo n.º 12
0
    def test_edit_article(self):
        #app.config['DATABASE']='blue/site/Test.db'
        with app.app_context():
            articles = db.query_db('select * from articles_v')
        with app.test_client() as c:

            with c.session_transaction() as session:
                session['logged_in'] = True
                session['username'] = '******'
            # send data as POST form to endpoint
            for article in articles:
                print(article['id'], article['body'])
                sent = {
                    'title': 'EDIT' + str(article['id']),
                    'body': str(article['body']) + '-EDIT'
                }
                response = c.post('/edit_article/' + str(article['id']),
                                  data=sent)
                # check result from server with expected data
                assertTrue(self, response)
Exemplo n.º 13
0
 def test_open_article(self):
     with app.app_context():
         #articles=db.query_db('select * from articles_v')
         articles = db.Articles().query.all()
         #for article in articles:
         #print(article['id'])
     with app.test_client() as c:
         #c.DATABASE = 'Test.db'
         #app.config['DATABASE']='blue/site/Test.db'
         #c.config['DATABASE']='Test.db'
         with c.session_transaction() as session:
             session['logged_in'] = True
             session['username'] = '******'
         # send data as POST form to endpoint
         for article in articles:
             print(article.id)
             print('/article/' + str(article['id']))
             response = self.app.get('/article/' + str(article.id),
                                     follow_redirects=True)
             print(response.data)
             assertTrue(self, response)
Exemplo n.º 14
0
    def test_add_article(self):
        #app.config['DATABASE']='blue/site/Test.db'
        with app.app_context():
            for user in db.query_db('select * from users'):
                print(user['name'])
        with app.test_client() as c:
            #app.config['DATABASE']='blue/site/Test.db'
            with c.session_transaction() as session:
                session['logged_in'] = True
                session['username'] = '******'
            # send data as POST form to endpoint

            for x in range(5):
                sent = {
                    'title':
                    'test' + str(x),
                    'body':
                    'testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest'
                }
                response = c.post('/add_article', data=sent)
                # check result from server with expected data
                print(response.data)
                assertTrue(self, response)
Exemplo n.º 15
0
 def test_register_login(self):
     #with app.app_context():
     #for user in db.query_db('select * from users'):
     # print(user['name'])
     with app.test_client() as c:
         #app.config['DATABASE']='Test.db'
         #app.config['DATABASE']='blue/site/Test.db'
         for x in range(1):
             name = randomString(10)
             passw = randomString(10)
             sent = {
                 'name': 'test' + str(x),
                 'email': 'email@email' + str(x),
                 'username': name,
                 'password': passw
             }
             print(sent)
             response = c.post('/register', data=sent)
             sent = {'username': name, 'password': passw}
             request = c.post('/login', data=sent)
             print(request.data)
             # check result from server with expected data
             assertTrue(self, response)
             assertTrue(self, request)
Exemplo n.º 16
0
 def test_book_status(self):
     tester = app.test_client(self)
     response = tester.get('/book/2')
     self.assertEqual(response.content_type, 'application/json')
Exemplo n.º 17
0
 def test_routes_require_login(self):
     tester = app.test_client(self)
     response = tester.get('/dashboard', follow_redirects=True)
     self.assertIn(b'Unathorized, Please Login', response.data)
Exemplo n.º 18
0
 def test_all_book_status(self):
     tester = app.test_client(self)
     response = tester.get('/book?id=2')
     self.assertEqual(response.content_type, 'text/html; charset=utf-8')
Exemplo n.º 19
0
 def test_all_books(self):
     tester = app.test_client(self)
     response = tester.get('/book?id=2', follow_redirects=True)
     self.assertIn(b'"author": "Unknown"', response.data)
Exemplo n.º 20
0
 def test_login(self):
     tester = app.test_client(self)
     response = tester.get('/login', content_type='html/text')
     self.assertEqual(response.status_code, 200)
Exemplo n.º 21
0
 def test_book(self):
     tester = app.test_client(self)
     response = tester.get('/book/2')
     self.assertIn(b'"title": "Scarlet Letter"', response.data)
Exemplo n.º 22
0
 def test_index_page(self):
     tester = app.test_client(self)
     response = tester.get('/', content_type='html/text')
     self.assertTrue(b'Welcome To Your Book Wish List' in response.data)