1
|
|
|
import os |
2
|
|
|
import sys |
3
|
|
|
import unittest |
4
|
|
|
from datetime import date |
5
|
|
|
|
6
|
|
|
import transaction |
7
|
|
|
import webtest |
8
|
|
|
|
9
|
|
|
from ..models import Base, User, DBSession, Address |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class FunctionalTests(unittest.TestCase): |
13
|
|
|
@classmethod |
14
|
|
|
def setUpClass(cls): |
15
|
|
|
|
16
|
|
|
from .. import main |
17
|
|
|
|
18
|
|
|
settings = { |
19
|
|
|
"sqlalchemy.url": "sqlite://", |
20
|
|
|
"auth.secret": "seekrit", |
21
|
|
|
} |
22
|
|
|
app = main({}, **settings) |
23
|
|
|
cls.testapp = webtest.TestApp(app) |
24
|
|
|
cls.dbsession = DBSession() |
25
|
|
|
cls.engine = cls.dbsession.bind |
26
|
|
|
Base.metadata.create_all(bind=cls.engine) |
27
|
|
|
|
28
|
|
|
for i in range(30): |
29
|
|
|
with transaction.manager: |
30
|
|
|
address = Address(description="Address#2" + str(i).rjust(2, "0")) |
31
|
|
|
|
32
|
|
|
cls.dbsession.add(address) |
33
|
|
|
|
34
|
|
|
user = User( |
35
|
|
|
name="User#1" + str(i).rjust(2, "0"), |
36
|
|
|
birthday=date(1980 + i % 8, i % 12 + 1, i % 10 + 1), |
37
|
|
|
) |
38
|
|
|
|
39
|
|
|
user.address = address |
40
|
|
|
|
41
|
|
|
cls.dbsession.add(user) |
42
|
|
|
|
43
|
|
|
@classmethod |
44
|
|
|
def tearDownClass(cls): |
45
|
|
|
Base.metadata.drop_all(bind=cls.engine) |
46
|
|
|
|
47
|
|
|
def test_nr_of_users_in_db(self): |
48
|
|
|
nr_of_users_in_db = self.dbsession.query(User).count() |
49
|
|
|
self.assertEqual(nr_of_users_in_db, 30) |
50
|
|
|
|
51
|
|
|
def test_home(self): |
52
|
|
|
res = self.testapp.get("/") |
53
|
|
|
self.assertIn("Alchemy Scaffold for The Pyramid Web Framework", res.text) |
54
|
|
|
|
55
|
|
|
def test_home2(self): |
56
|
|
|
res = self.testapp.get("/") |
57
|
|
|
self.assertIn("Alchemy Scaffold for The Pyramid Web Framework", res.text) |
58
|
|
|
|
59
|
|
|
def test_home3(self): |
60
|
|
|
res = self.testapp.get("/dt_110x_advanced_column_search") |
61
|
|
|
self.assertIn("Alchemy Scaffold for The Pyramid Web Framework", res.text) |
62
|
|
|
|