Skip to content

Commit

Permalink
back to Document
Browse files Browse the repository at this point in the history
  • Loading branch information
erral committed Oct 8, 2023
1 parent 7b94081 commit 0a1e339
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions src/plone/restapi/tests/test_services_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def setUp(self):
self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD)

self.api_session.post(
"/@types/DXTestDocument",
"/@types/Document",
json={
"factory": "fieldset",
"title": "Contact Info",
Expand All @@ -35,7 +35,7 @@ def setUp(self):
)

self.api_session.post(
"/@types/DXTestDocument",
"/@types/Document",
json={
"factory": "fieldset",
"title": "Location",
Expand All @@ -44,7 +44,7 @@ def setUp(self):
)

self.api_session.post(
"/@types/DXTestDocument",
"/@types/Document",
json={
"factory": "Email",
"title": "Author email",
Expand All @@ -53,7 +53,7 @@ def setUp(self):
)

self.api_session.post(
"/@types/DXTestDocument",
"/@types/Document",
json={
"factory": "URL",
"title": "Author url",
Expand All @@ -63,7 +63,7 @@ def setUp(self):

def tearDown(self):
# Remove all custom changed on Document
self.api_session.put("/@types/DXTestDocument", json={})
self.api_session.put("/@types/Document", json={})
self.api_session.close()

def test_get_types(self):
Expand All @@ -84,7 +84,7 @@ def test_get_types(self):

def test_get_types_document(self):
response = self.api_session.get(
"{}/@types/DXTestDocument".format(self.portal.absolute_url())
"{}/@types/Document".format(self.portal.absolute_url())
)

self.assertEqual(response.status_code, 200)
Expand All @@ -97,7 +97,7 @@ def test_get_types_document(self):
)

def test_get_types_document_edit(self):
response = self.api_session.get("/@types/DXTestDocument")
response = self.api_session.get("/@types/Document")

self.assertEqual(response.status_code, 200)

Expand All @@ -114,7 +114,7 @@ def test_get_types_document_edit(self):
) # noqa

def test_types_document_get_fieldset(self):
response = self.api_session.get("/@types/DXTestDocument/contact_info")
response = self.api_session.get("/@types/Document/contact_info")

self.assertEqual(response.status_code, 200)
self.assertEqual("Contact Info", response.json().get("title"))
Expand All @@ -125,7 +125,7 @@ def test_types_document_get_fieldset(self):
self.assertEqual([], response.json().get("fields"))

def test_types_document_get_field(self):
response = self.api_session.get("/@types/DXTestDocument/author_email")
response = self.api_session.get("/@types/Document/author_email")

self.assertEqual(response.status_code, 200)
self.assertEqual("Author email", response.json().get("title")) # noqa
Expand All @@ -142,7 +142,7 @@ def test_types_document_get_field(self):

def test_types_document_post_fieldset(self):
response = self.api_session.post(
"/@types/DXTestDocument",
"/@types/Document",
json={
"factory": "fieldset",
"title": "Foo bar",
Expand All @@ -158,7 +158,7 @@ def test_types_document_post_fieldset(self):

def test_types_document_post_field(self):
response = self.api_session.post(
"/@types/DXTestDocument",
"/@types/Document",
json={
"factory": "Email",
"title": "Email",
Expand All @@ -180,7 +180,7 @@ def test_types_document_post_field(self):

def test_types_document_patch_properties(self):
response = self.api_session.patch(
"/@types/DXTestDocument",
"/@types/Document",
json={
"properties": {
"author_email": {
Expand All @@ -194,15 +194,15 @@ def test_types_document_patch_properties(self):
# PATCH returns no content
self.assertEqual(response.status_code, 204)

response = self.api_session.get("/@types/DXTestDocument/author_email")
response = self.api_session.get("/@types/Document/author_email")
self.assertEqual(200, response.status_code)
self.assertEqual("[email protected]", response.json().get("default"))
self.assertEqual(5, response.json().get("minLength"))
self.assertEqual(100, response.json().get("maxLength"))

def test_types_document_patch_fieldsets(self):
response = self.api_session.patch(
"/@types/DXTestDocument",
"/@types/Document",
json={
"fieldsets": [
{
Expand All @@ -215,14 +215,14 @@ def test_types_document_patch_fieldsets(self):
)
self.assertEqual(response.status_code, 204)

response = self.api_session.get("/@types/DXTestDocument/contact_info")
response = self.api_session.get("/@types/Document/contact_info")
self.assertEqual(200, response.status_code)
self.assertEqual("Contact information", response.json().get("title"))
self.assertEqual(["author_email"], response.json().get("fields"))

def test_types_document_patch_one_fieldset(self):
response = self.api_session.patch(
"/@types/DXTestDocument/contact_info",
"/@types/Document/contact_info",
json={
"title": "Contact the author",
"description": "Reach the author",
Expand All @@ -234,7 +234,7 @@ def test_types_document_patch_one_fieldset(self):
)
self.assertEqual(response.status_code, 204)

response = self.api_session.get("/@types/DXTestDocument/contact_info")
response = self.api_session.get("/@types/Document/contact_info")
self.assertEqual(200, response.status_code)
self.assertEqual("Contact the author", response.json().get("title"))
self.assertEqual("Reach the author", response.json().get("description")) # noqa
Expand All @@ -244,7 +244,7 @@ def test_types_document_patch_one_fieldset(self):

def test_types_document_patch_one_field(self):
response = self.api_session.patch(
"/@types/DXTestDocument/author_email",
"/@types/Document/author_email",
json={
"title": "Author e-mail",
"description": "The e-mail address of the author",
Expand All @@ -255,7 +255,7 @@ def test_types_document_patch_one_field(self):
)
self.assertEqual(response.status_code, 204)

response = self.api_session.get("/@types/DXTestDocument/author_email")
response = self.api_session.get("/@types/Document/author_email")
self.assertEqual(200, response.status_code)
self.assertEqual("Author e-mail", response.json().get("title"))
self.assertEqual(
Expand All @@ -266,7 +266,7 @@ def test_types_document_patch_one_field(self):

def test_types_document_patch_create_missing(self):
response = self.api_session.patch(
"/@types/DXTestDocument",
"/@types/Document",
json={
"fieldsets": [
{"title": "Layout", "fields": ["blocks", "blocks_layout"]}
Expand Down Expand Up @@ -319,7 +319,7 @@ def test_types_document_patch_create_missing(self):
)
self.assertEqual(response.status_code, 204)

response = self.api_session.get("/@types/DXTestDocument")
response = self.api_session.get("/@types/Document")
self.assertEqual(200, response.status_code)

self.assertIn("blocks", response.json().get("properties"))
Expand All @@ -332,7 +332,7 @@ def test_types_document_patch_create_missing(self):

def test_types_document_update_min_max(self):
response = self.api_session.patch(
"/@types/DXTestDocument",
"/@types/Document",
json={
"properties": {
"custom_text": {
Expand All @@ -352,18 +352,18 @@ def test_types_document_update_min_max(self):
)
self.assertEqual(response.status_code, 204)

response = self.api_session.get("/@types/DXTestDocument/custom_text")
response = self.api_session.get("/@types/Document/custom_text")
self.assertEqual(200, response.status_code)
self.assertEqual(2, response.json().get("minLength"))
self.assertEqual(20, response.json().get("maxLength"))

response = self.api_session.get("/@types/DXTestDocument/custom_float")
response = self.api_session.get("/@types/Document/custom_float")
self.assertEqual(200, response.status_code)
self.assertEqual(2, response.json().get("minimum"))
self.assertEqual(14.0, response.json().get("maximum"))

def test_types_document_put(self):
response = self.api_session.get("/@types/DXTestDocument")
response = self.api_session.get("/@types/Document")
doc_json = response.json()
doc_json["layouts"] = ["thumbnail_view", "table_view"]
doc_json["fieldsets"] = [
Expand All @@ -388,10 +388,10 @@ def test_types_document_put(self):
"default": None,
}

response = self.api_session.put("/@types/DXTestDocument", json=doc_json)
response = self.api_session.put("/@types/Document", json=doc_json)
self.assertEqual(response.status_code, 204)

response = self.api_session.get("/@types/DXTestDocument")
response = self.api_session.get("/@types/Document")
self.assertEqual(200, response.status_code)

# Layouts updated
Expand Down Expand Up @@ -427,22 +427,22 @@ def test_types_document_put(self):

def test_types_document_remove_field(self):
response = self.api_session.delete(
"/@types/DXTestDocument/author_email",
"/@types/Document/author_email",
)
self.assertEqual(response.status_code, 204)

response = self.api_session.get("/@types/DXTestDocument")
response = self.api_session.get("/@types/Document")
self.assertEqual(200, response.status_code)

self.assertTrue("author_email" not in response.json().get("properties")) # noqa

def test_types_document_remove_fieldset(self):
response = self.api_session.delete(
"/@types/DXTestDocument/contact_info",
"/@types/Document/contact_info",
)
self.assertEqual(response.status_code, 204)

response = self.api_session.get("/@types/DXTestDocument")
response = self.api_session.get("/@types/Document")
self.assertEqual(200, response.status_code)

self.assertTrue(
Expand Down

0 comments on commit 0a1e339

Please sign in to comment.