-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_tests.py
116 lines (97 loc) · 4.02 KB
/
run_tests.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import yagmail
import requests
import unittest
import pdb
import ast
from datetime import datetime, timedelta
import numpy as np
class TestArgovisWebappRunning(unittest.TestCase):
def check_status_code(self, resp):
self.assertEqual(resp.status_code // 100, 2, "Error: Unexpected response {0}".format(resp))
def check_profile_order(self, resp):
dict_str = resp.content.decode("UTF-8")
profs = ast.literal_eval(dict_str)
dates = [ datetime.strptime(prof['date'], '%Y-%m-%dT%H:%M:%S.%fZ') for prof in profs ]
self.assertTrue( all(np.diff(dates) <= timedelta(0)) )
def test_check_home_module(self):
url = "https://argovis.colorado.edu/ng/home"
resp = requests.get(url)
self.check_status_code(resp)
def test_check_ar_module(self):
url = "https://argovis.colorado.edu/ng/ar"
resp = requests.get(url)
self.check_status_code(resp)
def test_check_covar_module(self):
url = "https://argovis.colorado.edu/ng/covar"
resp = requests.get(url)
self.check_status_code(resp)
def test_check_grid_module(self):
url = "https://argovis.colorado.edu/ng/grid"
resp = requests.get(url)
self.check_status_code(resp)
def test_check_profview_module(self):
url = "https://argovis.colorado.edu/ng/profview"
resp = requests.get(url)
self.check_status_code(resp)
def test_check_covar_module(self):
url = "https://argovis.colorado.edu/ng/covar"
resp = requests.get(url)
self.check_status_code(resp)
def test_check_not_a_module(self):
url = "https://argovis.colorado.edu/catalog/profiles/2902536_900/page"
resp = requests.get(url)
self.check_status_code(resp)
def test_check_current_database(self):
url = "https://argovis.colorado.edu/selection/overview"
resp = requests.get(url)
self.check_status_code(resp)
dict_str = resp.content.decode("UTF-8")
overview = ast.literal_eval(dict_str)
dateUpdated = datetime.strptime(overview["lastAdded"], '%Y-%m-%dT%H:%M:%S.%fZ')
today = datetime.now()
dt = today - dateUpdated
self.assertTrue(dt.days == 0, "date updated does not match todays date")
def test_profile_query(self):
baseUrl = 'https://argovis.colorado.edu/catalog/profiles/'
profs = ['4902911_1']
urls = [ baseUrl + prof + '/page' for prof in profs]
resps = [ requests.get(url) for url in urls]
[self.check_status_code(resp) for resp in resps]
def test_platform_query(self):
baseUrl = 'https://argovis.colorado.edu/catalog/platforms/'
profs = [ '4902911', '6902849', '4903237', '4903254', '4901598' ]
urls = [ baseUrl + prof + '/map' for prof in profs]
resps = [ requests.get(url) for url in urls]
[self.check_status_code(resp) for resp in resps]
[self.check_profile_order(resp) for resp in resps]
def test_selection_query(self):
pass
def run_tests():
testsRun = []
testsRun.append( check_home_module() )
testsRun.append( check_grid_module() )
testsRun.append( check_ar_module() )
testsRun.append( check_covar_module() )
testsRun.append( check_profview_module() )
testsRun.append( dummy_test_that_always_fails() )
failedTests = [ test for test in testsRun if isinstance(test, str) ]
write_report(failedTests)
if not len(failedTests)==0:
send_email()
def write_report(failedTests):
with open('test-report.txt', 'w') as filehandle:
filehandle.writelines("%s\n" % test for test in failedTests)
def send_email():
receiver = "argovistesting@gmail.com"
body = "Hello there from Yagmail"
password = input("Type your password and press enter: ")
filename='./test-report.txt'
yag = yagmail.SMTP(receiver, password)
yag.send(
to=receiver,
subject="Yagmail test with attachment",
contents=body,
attachments=filename,
)
if __name__ == '__main__':
unittest.main()