-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtests.py
144 lines (107 loc) · 4.4 KB
/
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from flask import Flask
from negocio123 import app, db, Step
from flask.ext.testing import TestCase
class NoStepsTestCase(TestCase):
def create_app(self):
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/empty.db'
return app
def setUp(self):
db.create_all()
def tearDown(self):
db.drop_all()
def test_navbar_is_empty(self):
rv = self.client.get('/')
assert 'w-nav-link' not in rv.data
def test_step_view_returns_404(self):
rv = self.client.get('/1/')
self.assertEquals(404, rv.status_code)
class StepsTestCase(TestCase):
def create_app(self):
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/full.db'
return app
def setUp(self):
db.create_all()
steps = []
steps.append(Step(nombre_de_agencia='Departamento de Estado', titulo_corto_de_agencia='Dept Estado', descripcion='Es el primer paso para incorporar tu negocio.', duracion='El tramite se realiza en el dia.', tramite_online=True, costo_de_tramite='150 USD para corporaciones con fines de lucro. 5 USD para corporaciones sin fines de lucro. 10 USD por el tramite de certificado de existencia'))
steps.append(Step(nombre_de_agencia='IRS (Internal Revenue Service)', titulo_corto_de_agencia='IRS', descripcion='Es el segundo paso para incorporar tu negocio. En este paso obtendras el EIN ( Numero de Identificacion de Empleador)', duracion='El tramite se realiza en el dia.', tramite_online=True, costo_de_tramite='El tramite es gratuito'))
for step in steps:
db.session.add(step)
db.session.commit()
def tearDown(self):
db.session.remove()
db.drop_all()
def test_navbar_is_not_empty(self):
rv = self.client.get('/')
assert 'w-nav-link' in rv.data
def test_step_view_returns_200(self):
rv = self.client.get('/1/')
self.assertEquals(200, rv.status_code)
def test_step_view_upper_limit_return_404(self):
rv = self.client.get('/3/')
self.assertEquals(404, rv.status_code)
class LoginTestCase(TestCase):
def create_app(self):
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///dump.sqlite3'
return app
def setUp(self):
pass
def tearDown(self):
pass
def login(self, email, password):
return self.client.post('/login', data=dict(
email=email,
password=password)
, follow_redirects=True)
def logout(self):
return self.client.get('/logout', follow_redirects=True)
def test_invalid_login(self):
rv = self.login('[email protected]', 'noaccount')
assert 'Username or Password invalid' in rv.data
def test_valid_login(self):
rv = self.login('[email protected]', 'coquicoders')
assert 'Logged in succesfully' in rv.data
def test_admin_unaccessible_without_login(self):
rv = self.client.get('/admin', follow_redirects=True)
assert 'Step' not in rv.data
def test_admin_accessible_with_login(self):
self.login('[email protected]', 'coquicoders')
rv = self.client.get('/admin', follow_redirects=True)
assert 'Step' in rv.data
def test_unauthenticated_admin_should_redirect_to_login(self):
rv = self.client.get('/admin/')
self.assertRedirects(rv, '/login?next=%2Fadmin')
def test_successful_login_redirects_to_next(self):
rv = self.client.post('/login?next=%2Fadmin', data=dict(
email='[email protected]',
password='coquicoders'))
self.assertRedirects(rv, '/admin')
class MunicipioTestCase(TestCase):
render_templates = False
def create_app(self):
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///dump.sqlite3'
return app
def test_municipio_template_used_on_municipio(self):
rv = self.client.get('/4/')
self.assert_template_used('municipios.html')
def test_municipio_template_not_used_on_other_steps(self):
rv = self.client.get('/1/')
self.assert_template_used('step.html')
class NavigationTestCase(TestCase):
def create_app(self):
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///dump.sqlite3'
return app
def setUp(self):
self.driver = webdriver.Chrome()
def tearDown(self):
self.driver.close()
def test_steps_begin(self):
driver = self.driver
driver.get('http://localhost:5000/')
btn = driver.find_element_by_id('comenzar')
btn.send_keys(Keys.RETURN)
self.assertEquals('http://localhost:5000/1/', driver.current_url)
if __name__ == '__main__':
unittest.main()