|
20 | 20 | from zope.annotation.interfaces import IAnnotations |
21 | 21 | from zope.component import getUtility |
22 | 22 | from zope.lifecycleevent import modified |
23 | | - |
| 23 | +from plone.app.discussion.interfaces import IConversation |
| 24 | +from zope.component import createObject |
24 | 25 | import json |
25 | 26 | import os |
26 | 27 | import shutil |
@@ -1484,6 +1485,50 @@ def test_reset_dates(self): |
1484 | 1485 | convert = catalog._catalog.indexes["modified"]._convert |
1485 | 1486 | self.assertEqual(indexdata["modified"], convert(reset_modification_date)) |
1486 | 1487 |
|
| 1488 | + def test_import_discussion(self): |
| 1489 | + app = self.layer["app"] |
| 1490 | + portal = self.layer["portal"] |
| 1491 | + login(app, SITE_OWNER_NAME) |
| 1492 | + doc1 = api.content.create( |
| 1493 | + container=portal, type="Document", id="doc1", title="Document 1" |
| 1494 | + ) |
| 1495 | + conversation = IConversation(doc1) |
| 1496 | + comment = createObject("plone.Comment") |
| 1497 | + comment.text = "Comment text" |
| 1498 | + conversation.addComment(comment) |
| 1499 | + transaction.commit() |
| 1500 | + |
| 1501 | + browser = self.open_page("@@export_discussion") |
| 1502 | + browser.getForm(action="@@export_discussion").submit(name="form.submitted") |
| 1503 | + contents = browser.contents |
| 1504 | + if not browser.contents: |
| 1505 | + contents = DATA[-1] |
| 1506 | + data = json.loads(contents) |
| 1507 | + self.assertEqual(data[0]["uuid"], doc1.UID()) |
| 1508 | + self.assertEqual( |
| 1509 | + data[0]["conversation"]["items"][0]["text"]["data"], "Comment text" |
| 1510 | + ) |
| 1511 | + |
| 1512 | + # Delete the comment to prepare the import |
| 1513 | + del conversation[comment.id] |
| 1514 | + self.assertEqual(len(conversation), 0) |
| 1515 | + |
| 1516 | + transaction.commit() |
| 1517 | + |
| 1518 | + browser = self.open_page("@@import_discussion") |
| 1519 | + browser.getForm(action="@@import_discussion").submit(name="form.submitted") |
| 1520 | + upload = browser.getControl(name="jsonfile") |
| 1521 | + upload.add_file(contents, "application/json", "export_discussion.json") |
| 1522 | + browser.getForm(action="@@import_discussion").submit() |
| 1523 | + |
| 1524 | + self.assertIn("Imported 1 comments", browser.contents) |
| 1525 | + |
| 1526 | + brains = api.content.find(portal_type="Discussion Item") |
| 1527 | + self.assertEqual(len(brains), 1) |
| 1528 | + conversation = IConversation(doc1) |
| 1529 | + |
| 1530 | + self.assertEqual(len(conversation), 1) |
| 1531 | + |
1487 | 1532 |
|
1488 | 1533 | def dateify(value): |
1489 | 1534 | return value.asdatetime().replace(microsecond=0) |
0 commit comments