Skip to content

Commit 546c2e0

Browse files
committed
testing registration existing user.
1 parent 59ab3eb commit 546c2e0

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

app/ch14_testing/final/tests/account_tests.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from pypi_org.data.users import User
12
from pypi_org.viewmodels.account.register_viewmodel import RegisterViewModel
23
from tests.test_client import flask_app
34
import unittest.mock
@@ -27,3 +28,27 @@ def test_register_validation_when_valid():
2728

2829
# Assert
2930
assert vm.error is None
31+
32+
33+
def test_register_validation_for_existing_user():
34+
# 3 A's of test: Arrange, Act, then Assert
35+
36+
# Arrange
37+
form_data = {
38+
'name': 'Michael',
39+
'email': '[email protected]',
40+
'password': 'a'*6
41+
}
42+
43+
with flask_app.test_request_context(path='/account/register', data=form_data):
44+
vm = RegisterViewModel()
45+
46+
# Act
47+
target = 'pypi_org.services.user_service.find_user_by_email'
48+
test_user = User(email=form_data.get('email'))
49+
with unittest.mock.patch(target, return_value=test_user):
50+
vm.validate()
51+
52+
# Assert
53+
assert vm.error is not None
54+
assert 'already exists' in vm.error

0 commit comments

Comments
 (0)