WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit a904535

Browse files
committed
Added more tests
1 parent 63d053d commit a904535

File tree

9 files changed

+259
-16
lines changed

9 files changed

+259
-16
lines changed

MANIFEST.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
recursive-include dashboard/static *
2-
recursive-include dashboard/templates *
1+
recursive-include flask_monitoringdashboard/static *
2+
recursive-include flask_monitoringdashboard/templates *

docs/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# Documentation
2-
32
The documentation is generated using [Sphinx](http://www.sphinx-doc.org/en/master/).
43

54
If you want to generate the documentation, you can run:
@@ -13,3 +12,6 @@ The following packages are required to generate the documentation:
1312
pip install Sphinx
1413
pip install Flask-Sphinx-Themes
1514
```
15+
16+
# Read The Docs
17+
You can also find the documentation on see [this site](http://flask-monitoringdashboard.readthedocs.io).

flask_monitoringdashboard/test/db/test_monitor_rules.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import unittest
88

9-
from flask_monitoringdashboard.test.utils import set_test_environment, clear_db, add_fake_data, NAME
9+
from flask_monitoringdashboard.test.utils import set_test_environment, clear_db, add_fake_data, NAME, TIMES
1010

1111

1212
class TestMonitorRule(unittest.TestCase):
@@ -27,7 +27,7 @@ def test_get_monitor_rules(self):
2727
self.assertEqual(result[0].endpoint, NAME)
2828
self.assertTrue(result[0].monitor)
2929
self.assertEqual(result[0].version_added, config.version)
30-
self.assertIsNone(result[0].last_accessed)
30+
self.assertEqual(result[0].last_accessed, TIMES[0])
3131

3232
def test_get_monitor_names(self):
3333
"""

flask_monitoringdashboard/test/routings/test_export_data.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,42 @@
11
import unittest
2+
23
import jwt
4+
from flask import json
35

4-
from flask_monitoringdashboard.test.utils import set_test_environment, clear_db, add_fake_data, EXECUTION_TIMES, NAME, TIMES, GROUP_BY, \
5-
IP
6-
from flask import Flask, json
6+
from flask_monitoringdashboard.test.utils import set_test_environment, clear_db, add_fake_data, login, get_test_app, \
7+
EXECUTION_TIMES, NAME, GROUP_BY, IP, TIMES
78

89

910
class TestExportData(unittest.TestCase):
1011

1112
def setUp(self):
1213
set_test_environment()
13-
import flask_monitoringdashboard
14-
user_app = Flask(__name__)
15-
user_app.testing = True
16-
flask_monitoringdashboard.config.get_group_by = lambda: '12345'
17-
flask_monitoringdashboard.bind(app=user_app)
1814
clear_db()
1915
add_fake_data()
20-
self.app = user_app.test_client()
16+
self.app = get_test_app()
17+
18+
def test_download_csv(self):
19+
"""
20+
Just retrieve the content and check if nothing breaks
21+
"""
22+
self.assertEqual(302, self.app.get('dashboard/download-csv').status_code)
23+
login(self.app)
24+
self.assertEqual(200, self.app.get('dashboard/download-csv').status_code)
25+
26+
def test_export_data(self):
27+
"""
28+
Just retrieve the content and check if nothing breaks
29+
"""
30+
self.assertEqual(302, self.app.get('dashboard/export-data').status_code)
31+
login(self.app)
32+
self.assertEqual(200, self.app.get('dashboard/export-data').status_code)
33+
34+
def test_submit_test_results(self):
35+
"""
36+
Just retrieve the content and check if nothing breaks
37+
"""
38+
pass
39+
# TODO: Implement function
2140

2241
def test_get_json_data_from(self):
2342
"""
@@ -46,7 +65,7 @@ def test_get_json_monitor_rules(self):
4665
self.assertEqual(len(data), 1)
4766
row = data[0]
4867
self.assertEqual(row['endpoint'], NAME)
49-
self.assertEqual(row['last_accessed'], u'None')
68+
self.assertEqual(row['last_accessed'], str(TIMES[0]))
5069
self.assertTrue(row['monitor'])
5170
self.assertEqual(row['version_added'], config.version)
5271

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import unittest
2+
3+
from flask_monitoringdashboard.test.utils import set_test_environment, clear_db, add_fake_data, login, get_test_app
4+
5+
6+
class TestLogin(unittest.TestCase):
7+
8+
def setUp(self):
9+
set_test_environment()
10+
clear_db()
11+
add_fake_data()
12+
self.app = get_test_app()
13+
14+
def test_login(self):
15+
"""
16+
Just retrieve the content and check if nothing breaks
17+
"""
18+
self.assertEqual(200, self.app.get('dashboard/login').status_code)
19+
login(self.app)
20+
self.assertEqual(302, self.app.get('dashboard/login').status_code)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import unittest
2+
3+
from flask_monitoringdashboard.test.utils import set_test_environment, clear_db, add_fake_data, get_test_app, login
4+
5+
6+
class TestMeasurement(unittest.TestCase):
7+
8+
def setUp(self):
9+
set_test_environment()
10+
clear_db()
11+
add_fake_data()
12+
self.app = get_test_app()
13+
14+
def test_overview(self):
15+
"""
16+
Just retrieve the content and check if nothing breaks
17+
"""
18+
self.assertEqual(302, self.app.get('dashboard/measurements/overview').status_code)
19+
login(self.app)
20+
self.assertEqual(200, self.app.get('dashboard/measurements/overview').status_code)
21+
22+
def test_heatmap(self):
23+
"""
24+
Just retrieve the content and check if nothing breaks
25+
"""
26+
self.assertEqual(302, self.app.get('dashboard/measurements/heatmap').status_code)
27+
login(self.app)
28+
self.assertEqual(200, self.app.get('dashboard/measurements/heatmap').status_code)
29+
30+
def test_page_number_of_requests_per_endpoint(self):
31+
"""
32+
Just retrieve the content and check if nothing breaks
33+
"""
34+
self.assertEqual(302, self.app.get('dashboard/measurements/requests').status_code)
35+
login(self.app)
36+
self.assertEqual(200, self.app.get('dashboard/measurements/requests').status_code)
37+
38+
def test_page_boxplot_per_version(self):
39+
"""
40+
Just retrieve the content and check if nothing breaks
41+
"""
42+
self.assertEqual(302, self.app.get('dashboard/measurements/versions').status_code)
43+
login(self.app)
44+
self.assertEqual(200, self.app.get('dashboard/measurements/versions').status_code)
45+
46+
def test_page_boxplot_per_endpoint(self):
47+
"""
48+
Just retrieve the content and check if nothing breaks
49+
"""
50+
self.assertEqual(302, self.app.get('dashboard/measurements/endpoints').status_code)
51+
login(self.app)
52+
self.assertEqual(200, self.app.get('dashboard/measurements/endpoints').status_code)
53+
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import unittest
2+
3+
from flask_monitoringdashboard.test.utils import set_test_environment, clear_db, add_fake_data, get_test_app, login, \
4+
NAME
5+
6+
7+
class TestResult(unittest.TestCase):
8+
9+
def setUp(self):
10+
set_test_environment()
11+
clear_db()
12+
add_fake_data()
13+
self.app = get_test_app()
14+
15+
def test_result_heatmap(self):
16+
"""
17+
Just retrieve the content and check if nothing breaks
18+
"""
19+
self.assertEqual(302, self.app.get('dashboard/result/{}/heatmap'.format(NAME)).status_code)
20+
login(self.app)
21+
self.assertEqual(200, self.app.get('dashboard/result/{}/heatmap'.format(NAME)).status_code)
22+
23+
def test_result_time_per_hour(self):
24+
"""
25+
Just retrieve the content and check if nothing breaks
26+
"""
27+
self.assertEqual(302, self.app.get('dashboard/result/{}/time_per_hour'.format(NAME)).status_code)
28+
login(self.app)
29+
self.assertEqual(200, self.app.get('dashboard/result/{}/time_per_hour'.format(NAME)).status_code)
30+
31+
def test_result_hits_per_hour(self):
32+
"""
33+
Just retrieve the content and check if nothing breaks
34+
"""
35+
self.assertEqual(302, self.app.get('dashboard/result/{}/hits_per_hour'.format(NAME)).status_code)
36+
login(self.app)
37+
self.assertEqual(200, self.app.get('dashboard/result/{}/hits_per_hour'.format(NAME)).status_code)
38+
39+
def test_result_time_per_version_per_user(self):
40+
"""
41+
Just retrieve the content and check if nothing breaks
42+
"""
43+
self.assertEqual(302, self.app.get('dashboard/result/{}/time_per_version_per_user'.format(NAME)).status_code)
44+
login(self.app)
45+
self.assertEqual(200, self.app.get('dashboard/result/{}/time_per_version_per_user'.format(NAME)).status_code)
46+
47+
def test_result_time_per_version_per_ip(self):
48+
"""
49+
Just retrieve the content and check if nothing breaks
50+
"""
51+
self.assertEqual(302, self.app.get('dashboard/result/{}/time_per_version_per_ip'.format(NAME)).status_code)
52+
login(self.app)
53+
self.assertEqual(200, self.app.get('dashboard/result/{}/time_per_version_per_ip'.format(NAME)).status_code)
54+
55+
def test_result_time_per_version(self):
56+
"""
57+
Just retrieve the content and check if nothing breaks
58+
"""
59+
self.assertEqual(302, self.app.get('dashboard/result/{}/time_per_version'.format(NAME)).status_code)
60+
login(self.app)
61+
self.assertEqual(200, self.app.get('dashboard/result/{}/time_per_version'.format(NAME)).status_code)
62+
63+
def test_result_time_per_user(self):
64+
"""
65+
Just retrieve the content and check if nothing breaks
66+
"""
67+
self.assertEqual(302, self.app.get('dashboard/result/{}/time_per_user'.format(NAME)).status_code)
68+
login(self.app)
69+
self.assertEqual(200, self.app.get('dashboard/result/{}/time_per_user'.format(NAME)).status_code)
70+
71+
def test_result_outliers(self):
72+
"""
73+
Just retrieve the content and check if nothing breaks
74+
"""
75+
self.assertEqual(302, self.app.get('dashboard/result/{}/outliers'.format(NAME)).status_code)
76+
login(self.app)
77+
self.assertEqual(200, self.app.get('dashboard/result/{}/outliers'.format(NAME)).status_code)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import unittest
2+
3+
from flask_monitoringdashboard.test.utils import set_test_environment, clear_db, add_fake_data, get_test_app, login, \
4+
NAME
5+
6+
7+
class TestSetup(unittest.TestCase):
8+
9+
def setUp(self):
10+
set_test_environment()
11+
clear_db()
12+
add_fake_data()
13+
self.app = get_test_app()
14+
15+
def test_settings(self):
16+
"""
17+
Just retrieve the content and check if nothing breaks
18+
"""
19+
self.assertEqual(302, self.app.get('dashboard/settings').status_code)
20+
login(self.app)
21+
self.assertEqual(200, self.app.get('dashboard/settings').status_code)
22+
23+
def test_rules(self):
24+
"""
25+
Just retrieve the content and check if nothing breaks
26+
"""
27+
self.assertEqual(302, self.app.get('dashboard/rules').status_code)
28+
login(self.app)
29+
self.assertEqual(200, self.app.get('dashboard/rules').status_code)
30+
31+
def test_test_result(self):
32+
"""
33+
Just retrieve the content and check if nothing breaks
34+
"""
35+
self.assertEqual(302, self.app.get('dashboard/testmonitor/{}'.format(NAME)).status_code)
36+
login(self.app)
37+
self.assertEqual(200, self.app.get('dashboard/testmonitor/{}'.format(NAME)).status_code)
38+
39+
def test_testmonitor(self):
40+
"""
41+
Just retrieve the content and check if nothing breaks
42+
"""
43+
self.assertEqual(302, self.app.get('dashboard/testmonitor').status_code)
44+
login(self.app)
45+
self.assertEqual(200, self.app.get('dashboard/testmonitor').status_code)

flask_monitoringdashboard/test/utils.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"""
44
import datetime
55

6+
from flask import Flask
7+
68
NAME = 'main'
79
IP = '127.0.0.1'
810
GROUP_BY = '1'
@@ -42,7 +44,7 @@ def add_fake_data():
4244
# Add MonitorRule
4345
with session_scope() as db_session:
4446
db_session.add(MonitorRule(endpoint=NAME, monitor=True, time_added=datetime.datetime.now(),
45-
version_added=config.version))
47+
version_added=config.version, last_accessed=TIMES[0]))
4648

4749
# Add Tests
4850
with session_scope() as db_session:
@@ -54,5 +56,30 @@ def add_fake_data():
5456
db_session.add(TestsGrouped(endpoint=NAME, test_name=test_name))
5557

5658

59+
def get_test_app():
60+
"""
61+
:return: Flask Test Application with the right settings
62+
"""
63+
import flask_monitoringdashboard
64+
user_app = Flask(__name__)
65+
user_app.config['SECRET_KEY'] = flask_monitoringdashboard.config.security_token
66+
user_app.testing = True
67+
flask_monitoringdashboard.config.get_group_by = lambda: '12345'
68+
flask_monitoringdashboard.bind(app=user_app)
69+
return user_app.test_client()
70+
71+
72+
def login(test_app):
73+
"""
74+
Used for setting the sessions, such that you have a fake login to the dashboard.
75+
:param test_app:
76+
"""
77+
from flask_monitoringdashboard import config
78+
with test_app as c:
79+
with c.session_transaction() as sess:
80+
sess[config.link + '_logged_in'] = True
81+
sess[config.link + '_admin'] = True
82+
83+
5784
def mean(numbers):
5885
return float(sum(numbers)) / max(len(numbers), 1)

0 commit comments

Comments
 (0)