-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestcases.py
54 lines (48 loc) · 1.99 KB
/
testcases.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'''
Importing the necessary libraries and the flask app for testing
'''
from app import app
import unittest
from flask_testing import TestCase
class FlaskTestcase(unittest.TestCase):
#set up the app
def setUp(self):
app.config['TESTING'] = True
app.config['DEBUG'] = False
app.config['WTF_CSRF_ENABLED'] = False #if this is true then the forms do not get submitted during local testing
self.app = app.test_client()
self.assertEqual(app.debug, False)
self.assertEqual(app.testing, True)
#test if the index page is loading or not
def test_index(self):
response = self.app.get('/', follow_redirects=True)
self.assertIn(b'Enter URL to start crawling: ', response.data) #checking if the correct page has loaded
self.assertEqual(response.status_code, 200)
#function to post forms
def post_form(self, url, levels):
return self.app.post(
'/',
data=dict(url=url, levels=levels),
follow_redirects=True
)
#test the form when a valid URL and valid Max Level are given
def test_valid_URL_form(self):
response = self.app.post(
'/',
data=dict(url='https://www.google.com', levels=1),
follow_redirects=True
)
self.assertEqual(response.status_code, 200)
self.assertIn(b'Bigram Cloud', response.data)
#give invalid level to test
def test_invalid_Level_form(self):
response = self.post_form('https://www.google.com', 3)
self.assertEqual(response.status_code, 200)
self.assertIn(b'Please enter a value between 1 and 2', response.data)
#invalid URL to test
def test_invalid_URL_form_2(self):
response = self.post_form('https://om', 1)
self.assertEqual(response.status_code, 200)
self.assertIn(b'Please enter a valid Base URL', response.data)
if __name__=="__main__":
unittest.main()