Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
pbauer committed Feb 28, 2024
1 parent 292733e commit d12f4ec
Showing 1 changed file with 50 additions and 27 deletions.
77 changes: 50 additions & 27 deletions src/collective/exportimport/tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,27 @@ def test_export_members(self):
if member["username"] == TEST_USER_ID:
self.assertTrue(member["roles"], ["Member"])

def test_export_indirect_members(self):
direct = api.group.create("Direct")
indirect = api.group.create("Indirect")
api.group.add_user(group=direct, username=TEST_USER_ID)
# Make user a indirect member of the group indirect
api.group.add_user(group=direct, user=indirect)

transaction.commit()
browser = self.open_page("@@export_members")
browser.getForm(action="@@export_members").submit(name="form.submitted")
contents = browser.contents
if not browser.contents:
contents = DATA[-1]
data = json.loads(contents)
self.assertIn("groups", data.keys())
self.assertIn("members", data.keys())
member_data = data["members"][0]
self.assertEqual(member_data["username"], TEST_USER_ID)
# Only direct membership is exported
self.assertEqual(member_data["groups"], ["Direct"])

def test_export_defaultpages_empty(self):
browser = self.open_page("@@export_defaultpages")
browser.getForm(action="@@export_defaultpages").submit(name="form.submitted")
Expand Down Expand Up @@ -437,9 +458,9 @@ def test_export_relations(self):
data,
[
{
u"to_uuid": doc2.UID(),
u"relationship": u"relatedItems",
u"from_uuid": doc1.UID(),
"to_uuid": doc2.UID(),
"relationship": "relatedItems",
"from_uuid": doc1.UID(),
}
],
)
Expand All @@ -453,7 +474,7 @@ def test_export_discussion(self):
)
conversation = IConversation(doc1)
comment = createObject("plone.Comment")
comment.text = u"Comment text"
comment.text = "Comment text"
conversation.addComment(comment)
transaction.commit()

Expand Down Expand Up @@ -558,8 +579,8 @@ def test_export_redirects(self):
self.assertDictEqual(
data,
{
u"/plone/doc1": u"/plone/doc1-moved",
u"/plone/doc2": u"/plone/doc2-moved",
"/plone/doc1": "/plone/doc1-moved",
"/plone/doc2": "/plone/doc2-moved",
},
)

Expand Down Expand Up @@ -602,7 +623,7 @@ def test_export_versions(self):
# in Plone 4.3 this is somehow not set...
IAnnotations(request)[
"plone.app.versioningbehavior-changeNote"
] = u"initial_version_changeNote"
] = "initial_version_changeNote"
doc1 = api.content.create(
container=portal,
type="Document",
Expand All @@ -624,16 +645,16 @@ def test_export_versions(self):
description="A Description",
)

doc1.title = u"Document 1 with changed title"
doc1.title = "Document 1 with changed title"
modified(doc1)
doc2.title = u"Document 2 with changed title"
IAnnotations(request)["plone.app.versioningbehavior-changeNote"] = u"Föö bar"
doc2.title = "Document 2 with changed title"
IAnnotations(request)["plone.app.versioningbehavior-changeNote"] = "Föö bar"
modified(doc2)

doc2.description = u"New description in revision 3"
IAnnotations(request)["plone.app.versioningbehavior-changeNote"] = u"I am new!"
doc2.description = "New description in revision 3"
IAnnotations(request)["plone.app.versioningbehavior-changeNote"] = "I am new!"
modified(doc2)
folder1.title = u"Folder 1 with changed title"
folder1.title = "Folder 1 with changed title"
modified(folder1)

transaction.commit()
Expand Down Expand Up @@ -674,19 +695,19 @@ def test_export_versions(self):
self.assertEqual(len(versions), 2)

# check first version
self.assertEqual(versions["0"]["title"], u"Document 2")
self.assertEqual(versions["0"]["description"], u"A Description")
self.assertEqual(versions["0"]["changeNote"], u"initial_version_changeNote")
self.assertEqual(versions["0"]["title"], "Document 2")
self.assertEqual(versions["0"]["description"], "A Description")
self.assertEqual(versions["0"]["changeNote"], "initial_version_changeNote")

# check version 2
self.assertEqual(versions["1"]["title"], u"Document 2 with changed title")
self.assertEqual(versions["1"]["description"], u"A Description")
self.assertEqual(versions["1"]["changeNote"], u"Föö bar")
self.assertEqual(versions["1"]["title"], "Document 2 with changed title")
self.assertEqual(versions["1"]["description"], "A Description")
self.assertEqual(versions["1"]["changeNote"], "Föö bar")

# final/current version is the item itself
self.assertEqual(item["title"], u"Document 2 with changed title")
self.assertEqual(item["description"], u"New description in revision 3")
self.assertEqual(item["changeNote"], u"I am new!")
self.assertEqual(item["title"], "Document 2 with changed title")
self.assertEqual(item["description"], "New description in revision 3")
self.assertEqual(item["changeNote"], "I am new!")

def test_export_blob_as_base64(self):
# First create some content with blobs.
Expand All @@ -702,9 +723,9 @@ def test_export_blob_as_base64(self):
container=portal,
type="File",
id="file1",
title=u"File 1",
title="File 1",
)
file1.file = NamedBlobFile(data=file_data, filename=u"file.pdf")
file1.file = NamedBlobFile(data=file_data, filename="file.pdf")
transaction.commit()

# Now export
Expand Down Expand Up @@ -753,9 +774,9 @@ def test_export_blob_as_download_urls(self):
container=portal,
type="File",
id="file1",
title=u"File 1",
title="File 1",
)
file1.file = NamedBlobFile(data=file_data, filename=u"file.pdf")
file1.file = NamedBlobFile(data=file_data, filename="file.pdf")
transaction.commit()

# Now export
Expand Down Expand Up @@ -787,5 +808,7 @@ def test_export_blob_as_download_urls(self):
self.assertEqual(info["title"], file1.Title())
self.assertEqual(info["file"]["content-type"], "application/pdf")
self.assertEqual(info["file"]["filename"], "file.pdf")
self.assertEqual(info["file"]["download"], "http://nohost/plone/file1/@@download/file")
self.assertEqual(
info["file"]["download"], "http://nohost/plone/file1/@@download/file"
)
self.assertEqual(info["file"]["size"], 8561)

0 comments on commit d12f4ec

Please sign in to comment.