File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
app/ch14_testing/final/tests Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change
1
+ from pypi_org .data .users import User
1
2
from pypi_org .viewmodels .account .register_viewmodel import RegisterViewModel
2
3
from tests .test_client import flask_app
3
4
import unittest .mock
@@ -27,3 +28,27 @@ def test_register_validation_when_valid():
27
28
28
29
# Assert
29
30
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
+
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
You can’t perform that action at this time.
0 commit comments