Skip to content

Commit 6401db2

Browse files
committed
Before we mock out the db.
1 parent 59f5f75 commit 6401db2

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

app/ch14_testing/final/requirements-dev.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22

33
alembic
44

5-
5+
pytest
6+
pytest-cov
7+
webtest
8+
pytest-clarity
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from pypi_org.viewmodels.account.register_viewmodel import RegisterViewModel
2+
from tests.test_client import flask_app
3+
4+
5+
def test_example():
6+
print("Test example...")
7+
assert 1 + 2 == 3
8+
9+
10+
def test_register_validation_when_valid():
11+
# 3 A's of test: Arrange, Act, then Assert
12+
13+
# Arrange
14+
form_data = {
15+
'name': 'Michael',
16+
'email': '[email protected]',
17+
'password': 'a'*6
18+
}
19+
20+
with flask_app.test_request_context(path='/account/register', data=form_data):
21+
vm = RegisterViewModel()
22+
23+
# Act
24+
vm.validate()
25+
26+
# Assert
27+
assert vm.error is None
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# noinspection PyPackageRequirements
2+
import pytest
3+
4+
import sys
5+
import os
6+
7+
container_folder = os.path.abspath(os.path.join(
8+
os.path.dirname(__file__), '..'
9+
))
10+
sys.path.insert(0, container_folder)
11+
12+
from pypi_org.app import app as flask_app
13+
14+
15+
@pytest.fixture
16+
def client():
17+
flask_app.app.config['TESTING'] = True
18+
client = flask_app.app.test_client()
19+
20+
try:
21+
flask_app.register_blueprints()
22+
except:
23+
pass
24+
25+
flask_app.init_db()
26+
# client.post()
27+
28+
yield client

0 commit comments

Comments
 (0)