Skip to content

Commit

Permalink
API: Adjust tests to status code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nijel committed Aug 6, 2020
1 parent 8af634a commit 2f4d695
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions weblate/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def test_add_group(self):
kwargs={"username": User.objects.filter(is_active=True).first().username},
method="post",
superuser=True,
code=400,
code=422,
request={"group_id": -1},
)
self.do_request(
Expand Down Expand Up @@ -248,7 +248,7 @@ def test_get_notifications(self):
"api:user-notifications-details",
kwargs={"username": user.username, "subscription_id": -1},
method="get",
code=400,
code=422,
)
self.do_request(
"api:user-notifications-details",
Expand Down Expand Up @@ -402,7 +402,7 @@ def test_add_role(self):
kwargs={"id": Group.objects.get(name="Users").id},
method="post",
superuser=True,
code=400,
code=422,
request={"role_id": -1},
)
self.do_request(
Expand All @@ -427,7 +427,7 @@ def test_add_component(self):
kwargs={"id": Group.objects.get(name="Users").id},
method="post",
superuser=True,
code=400,
code=422,
request={"component_id": -1},
)
self.do_request(
Expand Down Expand Up @@ -462,7 +462,7 @@ def test_remove_component(self):
kwargs={"id": Group.objects.get(name="Users").id, "component_id": -1},
method="delete",
superuser=True,
code=400,
code=422,
)
self.do_request(
"api:group-delete-components",
Expand All @@ -489,7 +489,7 @@ def test_add_project(self):
kwargs={"id": Group.objects.get(name="Users").id},
method="post",
superuser=True,
code=400,
code=422,
request={"project_id": -1},
)
self.do_request(
Expand Down Expand Up @@ -524,7 +524,7 @@ def test_remove_project(self):
kwargs={"id": Group.objects.get(name="Users").id, "project_id": -1},
method="delete",
superuser=True,
code=400,
code=422,
)
self.do_request(
"api:group-delete-projects",
Expand All @@ -551,7 +551,7 @@ def test_add_language(self):
kwargs={"id": Group.objects.get(name="Users").id},
method="post",
superuser=True,
code=400,
code=422,
request={"language_code": "invalid"},
)
self.do_request(
Expand Down Expand Up @@ -586,7 +586,7 @@ def test_remove_language(self):
},
method="delete",
superuser=True,
code=400,
code=422,
)
self.do_request(
"api:group-delete-languages",
Expand All @@ -611,7 +611,7 @@ def test_add_componentlist(self):
kwargs={"id": Group.objects.get(name="Users").id},
method="post",
superuser=True,
code=400,
code=422,
request={"component_list_id": -1},
)
self.do_request(
Expand Down Expand Up @@ -648,7 +648,7 @@ def test_remove_componentlist(self):
kwargs={"id": Group.objects.get(name="Users").id, "component_list_id": -1},
method="delete",
superuser=True,
code=400,
code=422,
)
self.do_request(
"api:group-delete-componentlists",
Expand Down Expand Up @@ -736,7 +736,7 @@ def test_create(self):
"api:role-list",
method="post",
superuser=True,
code=400,
code=422,
format="json",
request={"name": "Role", "permissions": ["invalid.codename"]},
)
Expand Down Expand Up @@ -882,7 +882,7 @@ def test_repo_invalid(self):
self.do_request(
"api:project-repository",
self.project_kwargs,
code=400,
code=422,
method="post",
superuser=True,
request={"operation": "invalid"},
Expand Down Expand Up @@ -990,7 +990,7 @@ def test_create_with_source_language(self):
error_response = self.do_request(
"api:project-list",
method="post",
code=400,
code=422,
superuser=True,
format="json",
request={
Expand Down Expand Up @@ -1025,7 +1025,7 @@ def test_create_with_source_language_string(self, format="json"):
self.do_request(
"api:project-list",
method="post",
code=400,
code=422,
superuser=True,
format=format,
request=payload,
Expand Down Expand Up @@ -1090,7 +1090,7 @@ def test_create_component_no_format(self):
"api:project-components",
self.project_kwargs,
method="post",
code=400,
code=422,
superuser=True,
request={
"name": "API project",
Expand Down Expand Up @@ -1156,7 +1156,7 @@ def test_create_component_no_match(self):
"api:project-components",
self.project_kwargs,
method="post",
code=400,
code=422,
superuser=True,
request={
"name": "API project",
Expand Down Expand Up @@ -1370,7 +1370,7 @@ def test_create(self):
"api:language-list",
method="post",
superuser=True,
code=400,
code=422,
format="json",
request={"code": "new_lang", "name": "New Language", "direction": "rtl"},
)
Expand Down Expand Up @@ -1407,12 +1407,12 @@ def test_create(self):
method="get",
code=200,
)
# Creation with duplicate code gives 400
# Creation with duplicate code gives 422
response = self.do_request(
"api:language-list",
method="post",
superuser=True,
code=400,
code=422,
format="json",
request={
"code": "new_lang",
Expand Down Expand Up @@ -1560,7 +1560,7 @@ def test_upload_content(self):
reverse("api:translation-file", kwargs=self.translation_kwargs),
{"file": handle.read()},
)
self.assertEqual(response.status_code, 400)
self.assertEqual(response.status_code, 422)

def test_upload_overwrite(self):
self.test_upload()
Expand Down Expand Up @@ -1622,7 +1622,7 @@ def test_upload_invalid(self):
response = self.client.put(
reverse("api:translation-file", kwargs=self.translation_kwargs)
)
self.assertEqual(response.status_code, 400)
self.assertEqual(response.status_code, 422)

def test_upload_error(self):
self.authenticate()
Expand All @@ -1631,7 +1631,7 @@ def test_upload_error(self):
reverse("api:translation-file", kwargs=self.translation_kwargs),
{"file": handle},
)
self.assertEqual(response.status_code, 400)
self.assertEqual(response.status_code, 422)
self.assertIn("detail", response.data)

def test_repo_status_denied(self):
Expand Down Expand Up @@ -1700,7 +1700,7 @@ def test_autotranslate(self):
superuser=True,
method="post",
request={"mode": "invalid"},
code=400,
code=422,
)
response = self.do_request(
"api:translation-autotranslate",
Expand Down Expand Up @@ -1755,7 +1755,7 @@ def test_add_monolingual(self):
method="post",
superuser=True,
request={"key": "key", "value": "Source Language"},
code=400,
code=422,
)

def test_delete(self):
Expand Down Expand Up @@ -1829,7 +1829,7 @@ def test_upload_denied(self):
self.test_upload(False, 403)

def test_upload_invalid(self):
self.test_upload(True, 400, TEST_PO)
self.test_upload(True, 422, TEST_PO)

def test_create(self):
with open(TEST_SCREENSHOT, "rb") as handle:
Expand All @@ -1847,7 +1847,7 @@ def test_create(self):
self.do_request(
"api:screenshot-list",
method="post",
code=400,
code=422,
superuser=True,
data={
"detail": ErrorDetail(
Expand All @@ -1863,7 +1863,7 @@ def test_create(self):
self.do_request(
"api:screenshot-list",
method="post",
code=400,
code=422,
superuser=True,
data={
"result": "Unsuccessful",
Expand All @@ -1879,7 +1879,7 @@ def test_create(self):
self.do_request(
"api:screenshot-list",
method="post",
code=400,
code=422,
superuser=True,
data={
"result": "Unsuccessful",
Expand Down Expand Up @@ -1977,7 +1977,7 @@ def test_units_invalid(self):
reverse("api:screenshot-units", kwargs={"pk": Screenshot.objects.get().pk}),
{"unit_id": -1},
)
self.assertEqual(response.status_code, 400)
self.assertEqual(response.status_code, 422)

def test_units(self):
self.authenticate(True)
Expand All @@ -2002,7 +2002,7 @@ def test_units_delete(self):
kwargs={"pk": Screenshot.objects.get().pk, "unit_id": -1},
),
)
self.assertEqual(response.status_code, 400)
self.assertEqual(response.status_code, 422)
response = self.client.delete(
reverse(
"api:screenshot-delete-units",
Expand Down Expand Up @@ -2117,7 +2117,7 @@ def test_add_component(self):
kwargs={"slug": ComponentList.objects.get().slug},
method="post",
superuser=True,
code=400,
code=422,
request={"component_id": -1},
)
self.do_request(
Expand Down Expand Up @@ -2147,7 +2147,7 @@ def test_remove_component(self):
},
method="delete",
superuser=True,
code=400,
code=422,
)
self.do_request(
"api:componentlist-delete-components",
Expand Down

0 comments on commit 2f4d695

Please sign in to comment.