2
2
from plone .app .testing import SITE_OWNER_PASSWORD
3
3
from plone .app .testing import TEST_USER_PASSWORD
4
4
from plone .restapi .permissions import UseRESTAPI
5
+ from plone .restapi .testing import set_request_body
5
6
from plone .restapi .testing import PLONE_RESTAPI_DX_INTEGRATION_TESTING
6
7
from unittest import TestCase
7
8
from zExceptions import Unauthorized
@@ -40,16 +41,19 @@ def test_login_without_credentials_fails(self):
40
41
self .assertNotIn ("token" , res )
41
42
42
43
def test_login_with_invalid_credentials_fails (self ):
43
- self .request [ "BODY" ] = '{"login": "admin", "password": "admin"}'
44
+ set_request_body ( self .request , '{"login": "admin", "password": "admin"}' )
44
45
service = self .traverse ()
45
46
res = service .reply ()
46
47
self .assertIn ("error" , res )
47
48
self .assertNotIn ("token" , res )
48
49
49
50
def test_successful_login_returns_token (self ):
50
- self .request ["BODY" ] = '{{"login": "{}", "password": "{}"}}' .format (
51
- SITE_OWNER_NAME ,
52
- SITE_OWNER_PASSWORD ,
51
+ set_request_body (
52
+ self .request ,
53
+ '{{"login": "{}", "password": "{}"}}' .format (
54
+ SITE_OWNER_NAME ,
55
+ SITE_OWNER_PASSWORD ,
56
+ ),
53
57
)
54
58
service = self .traverse ()
55
59
res = service .reply ()
@@ -69,9 +73,12 @@ def test_expired_token_returns_400(self):
69
73
70
74
def test_login_without_api_permission (self ):
71
75
self .portal .manage_permission (UseRESTAPI , roles = [])
72
- self .request ["BODY" ] = '{{"login": "{}", "password": "{}"}}' .format (
73
- SITE_OWNER_NAME ,
74
- SITE_OWNER_PASSWORD ,
76
+ set_request_body (
77
+ self .request ,
78
+ '{{"login": "{}", "password": "{}"}}' .format (
79
+ SITE_OWNER_NAME ,
80
+ SITE_OWNER_PASSWORD ,
81
+ ),
75
82
)
76
83
service = self .traverse ()
77
84
res = service .render ()
@@ -82,8 +89,9 @@ def test_login_with_zope_user_fails_without_pas_plugin(self):
82
89
uf .plugins .users .addUser ("zopeuser" , "zopeuser" , TEST_USER_PASSWORD )
83
90
if "jwt_auth" in uf :
84
91
uf ["jwt_auth" ].manage_activateInterfaces ([])
85
- self .request ["BODY" ] = (
86
- '{"login": "zopeuser", "password": "' + TEST_USER_PASSWORD + '"}'
92
+ set_request_body (
93
+ self .request ,
94
+ '{"login": "zopeuser", "password": "' + TEST_USER_PASSWORD + '"}' ,
87
95
)
88
96
service = self .traverse ()
89
97
res = service .reply ()
@@ -97,8 +105,9 @@ def test_login_with_zope_user(self):
97
105
self .layer ["app" ].acl_users .plugins .users .addUser (
98
106
"zopeuser" , "zopeuser" , TEST_USER_PASSWORD
99
107
)
100
- self .request ["BODY" ] = (
101
- '{"login": "zopeuser", "password": "' + TEST_USER_PASSWORD + '"}'
108
+ set_request_body (
109
+ self .request ,
110
+ '{"login": "zopeuser", "password": "' + TEST_USER_PASSWORD + '"}' ,
102
111
)
103
112
service = self .traverse ()
104
113
res = service .reply ()
0 commit comments