|
1 | 1 | import os
|
2 | 2 |
|
3 | 3 | import unittest
|
| 4 | +import recastfrontend.server |
4 | 5 | from recastfrontend.server import create_app
|
5 | 6 | from recastfrontend.server import db
|
6 | 7 | import recastdb.models
|
7 | 8 | from flask import url_for
|
8 |
| - |
| 9 | +import json |
9 | 10 |
|
10 | 11 | class FlaskClientTestCase(unittest.TestCase):
|
11 | 12 | def setUp(self):
|
12 | 13 | self.app = create_app()
|
| 14 | + self.app.testing = True |
13 | 15 | self.app_context = self.app.app_context()
|
14 | 16 | self.app_context.push()
|
15 |
| - db.create_all() |
16 |
| - self.client = self.app.test_client(use_cookies=True) |
| 17 | + |
| 18 | + with self.app.app_context(): |
| 19 | + db.create_all() |
| 20 | + self.client = self.app.test_client() |
17 | 21 |
|
18 | 22 | def tearDown(self):
|
19 | 23 | db.session.remove()
|
20 | 24 | self.app_context.pop()
|
21 |
| - |
22 | 25 |
|
| 26 | + def test_setup(self): |
| 27 | + self.assertTrue(self.app is not None) |
| 28 | + self.assertTrue(self.client is not None) |
| 29 | + |
23 | 30 | def test_home_page(self):
|
24 |
| - #response = self.client.get(url_for('./')) |
| 31 | + response = self.client.get('/') |
| 32 | + self.assertTrue(response.status_code == 200) |
| 33 | + #json_response = json.loads(response.data.decode('utf-8')) |
25 | 34 | #self.assetTrue('Stranger' in response.get_data(as_text=True))
|
26 | 35 | #print self.client.get(url_for('about'))
|
27 | 36 | pass
|
28 | 37 |
|
| 38 | + def test_about_page(self): |
| 39 | + response = self.client.get('/about') |
| 40 | + self.assertTrue(response.status_code == 200) |
| 41 | + |
| 42 | + def test_analysis_page(self): |
| 43 | + response = self.client.get('/analyses') |
| 44 | + self.assertTrue(response.status_code == 200) |
| 45 | + |
| 46 | + def test_show_last_analysis(self): |
| 47 | + query = recastdb.models.Analysis.query.all() |
| 48 | + self.assertTrue(len(query) > 0) |
| 49 | + response = self.client.get('/analysis/'+str(len(query))) |
| 50 | + self.assertTrue(response.status_code == 200) |
| 51 | + |
| 52 | + def test_requests(self): |
| 53 | + response = self.client.get('/requests') |
| 54 | + self.assertTrue(response.status_code == 200) |
| 55 | + |
| 56 | + def test_subscriptions(self): |
| 57 | + response = self.client.get('/subscriptions') |
| 58 | + self.assertTrue(response.status_code == 200) |
| 59 | + |
| 60 | + def test_analysis_form(self): |
| 61 | + response = self.client.get('analysis_form') |
| 62 | + self.assertTrue(response.status_code == 200) |
| 63 | + |
| 64 | + def test_show_last_request(self): |
| 65 | + query = recastdb.models.ScanRequest.query.all() |
| 66 | + self.assertTrue(len(query) > 0) |
| 67 | + response = self.client.get('request_form/'+str(len(query))) |
| 68 | + self.assertTrue(response.status_code == 200) |
| 69 | + |
29 | 70 | def test_db(self):
|
30 | 71 | user = recastdb. models. User( name="Test User", email="[email protected]")
|
31 | 72 | db.session.add(user)
|
|
0 commit comments