|
22 | 22 | """ |
23 | 23 |
|
24 | 24 | import pytest |
25 | | -from omeroweb.testlib import IWebTest, get_json, post |
| 25 | +from omeroweb.testlib import IWebTest, get_json |
26 | 26 | from django.urls import reverse, NoReverseMatch |
27 | 27 | from omeroweb.api import api_settings |
28 | 28 | from django.test import Client |
29 | 29 | from omero_marshal import OME_SCHEMA_URL |
30 | | -import json |
31 | 30 |
|
32 | 31 |
|
33 | 32 | class TestLogin(IWebTest): |
@@ -150,22 +149,28 @@ def test_login_invalid_csrf_token(self): |
150 | 149 | "Server: This field is required.")], |
151 | 150 | [{'username': 'nobody', 'password': 'fake', 'server': 1}, |
152 | 151 | ("Connection not available, " |
153 | | - "please check your user name and password.")] |
| 152 | + "please check your user name and password.")], |
| 153 | + [{'user': 1}, |
| 154 | + ("Username: This field is required. " |
| 155 | + "Password: This field is required. " |
| 156 | + "Server: This field is required.")] |
154 | 157 | ]) |
155 | 158 | def test_login_errors(self, credentials): |
156 | 159 | """ |
157 | 160 | Tests that we get expected form validation errors if try to login |
158 | 161 | without required fields, as 'guest' or with invalid username/password. |
159 | 162 | """ |
160 | | - django_client = self.django_root_client |
161 | | - # test the most recent version |
162 | | - version = api_settings.API_VERSIONS[-1] |
163 | | - request_url = reverse('api_login', kwargs={'api_version': version}) |
| 163 | + client = Client(enforce_csrf_checks=True) |
| 164 | + client.get(reverse("weblogin")) |
| 165 | + csrf_token = client.cookies["csrftoken"].value |
164 | 166 | data = credentials[0] |
165 | 167 | message = credentials[1] |
166 | | - rsp = post(django_client, request_url, data, status_code=403) |
167 | | - rsp = json.loads(rsp.content) |
168 | | - assert rsp['message'] == message |
| 168 | + rsp = client.post( |
| 169 | + self.get_login_url(), |
| 170 | + data, |
| 171 | + headers={"X-CSRFToken": csrf_token}) |
| 172 | + assert rsp.status_code == 403 |
| 173 | + assert rsp.json()['message'] == message |
169 | 174 |
|
170 | 175 | def test_login_example(self): |
171 | 176 | """ |
|
0 commit comments