Skip to content

Commit

Permalink
[SDESK-419] Duplication of text archived items to be supported
Browse files Browse the repository at this point in the history
[SDESK-419] Adding changes to existing test case
  • Loading branch information
nrvikas authored and petrjasek committed Dec 12, 2016
1 parent fe14aa9 commit bfbbef7
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 20 deletions.
2 changes: 1 addition & 1 deletion apps/archive/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def _duplicate_item(self, original_doc):

new_doc = original_doc.copy()
self._remove_after_copy(new_doc)
on_duplicate_item(new_doc)
on_duplicate_item(new_doc, original_doc)
resolve_document_version(new_doc, SOURCE, 'PATCH', new_doc)

if original_doc.get('task', {}).get('desk') is not None and new_doc.get(ITEM_STATE) != CONTENT_STATE.SUBMITTED:
Expand Down
3 changes: 2 additions & 1 deletion apps/archive/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def set_default_source(doc):
doc['dateline'].get('date'), source)


def on_duplicate_item(doc):
def on_duplicate_item(doc, original_doc):
"""Make sure duplicated item has basic fields populated."""

doc[GUID_FIELD] = generate_guid(type=GUID_NEWSML)
Expand All @@ -274,6 +274,7 @@ def on_duplicate_item(doc):
set_sign_off(doc)
doc['force_unlock'] = True
doc[ITEM_OPERATION] = ITEM_DUPLICATE
doc['original_id'] = original_doc.get('item_id', original_doc.get('_id'))
set_default_source(doc)


Expand Down
33 changes: 30 additions & 3 deletions apps/duplication/archive_duplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
# For the full copyright and license information, please see the
# AUTHORS and LICENSE files distributed with this source code, or
# at https://www.sourcefabric.org/superdesk/license
import json

from eve.utils import config
from eve.utils import config, ParsedRequest
from flask import request

import superdesk
Expand All @@ -31,7 +32,15 @@ class DuplicateResource(Resource):
resource_title = endpoint_name

schema = {
'desk': Resource.rel('desks', False, required=True)
'desk': Resource.rel('desks', False, required=True),
'type': {
'type': 'string',
'required': True
},
'item_id': {
'type': 'string',
'required': False
}
}

url = 'archive/<{0}:guid>/duplicate'.format(item_url)
Expand All @@ -50,8 +59,26 @@ def create(self, docs, **kwargs):

for doc in docs:
archive_service = get_resource_service(ARCHIVE)
archived_doc = {}

if doc.get('type') == 'archived':
archived_service = get_resource_service('archived')
req = ParsedRequest()
query = {'query':
{'filtered':
{'filter':
{'bool':
{'must': [
{'term': {'item_id': doc.get('item_id')}}
]}}}}, "sort": [{"_current_version": "desc"}], "size": 1}
req.args = {'source': json.dumps(query)}
archived_docs = archived_service.get(req=req, lookup=None)
if archived_docs.count() > 0:
archived_doc = archived_docs[0]

else:
archived_doc = archive_service.find_one(req=None, _id=guid_of_item_to_be_duplicated)

archived_doc = archive_service.find_one(req=None, _id=guid_of_item_to_be_duplicated)
self._validate(archived_doc, doc, guid_of_item_to_be_duplicated)

archived_doc['versioncreated'] = utcnow()
Expand Down
74 changes: 60 additions & 14 deletions features/content_duplication.feature
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ Feature: Duplication of Content
Then we get list with 3 items
When we post to "/archive/123/duplicate"
"""
{"desk": "#desks._id#"}
{"desk": "#desks._id#","type": "archive"}
"""
When we get "/archive/#duplicate._id#"
Then we get existing resource
"""
{"state": "submitted", "_current_version": 4, "source": "AAP",
"task": {"desk": "#desks._id#", "stage": "#desks.working_stage#", "user": "#CONTEXT_USER_ID#"}}
"task": {"desk": "#desks._id#", "stage": "#desks.working_stage#", "user": "#CONTEXT_USER_ID#"},
"original_id": "123"}
"""
Then there is no "last_production_desk" in task
And there is no "last_authoring_desk" in task
Expand All @@ -67,7 +68,7 @@ Feature: Duplication of Content
Scenario: Duplicate a content with history doesn't change the state if it's submitted
When we post to "/archive/123/duplicate"
"""
{"desk": "#desks._id#"}
{"desk": "#desks._id#","type": "archive"}
"""
When we get "/archive/#duplicate._id#"
Then we get existing resource
Expand All @@ -88,7 +89,7 @@ Feature: Duplication of Content
Then we get OK response
When we post to "/archive/123/duplicate"
"""
{"desk": "#desks._id#"}
{"desk": "#desks._id#","type": "archive"}
"""
When we get "/archive/#duplicate._id#"
Then we get existing resource
Expand All @@ -112,7 +113,7 @@ Feature: Duplication of Content
Then we get "_id"
When we post to "/archive/#_id#/duplicate"
"""
{"desk": "#desks._id#"}
{"desk": "#desks._id#","type": "archive"}
"""
When we get "/archive?q=#desks._id#"
Then we get list with 13 items
Expand All @@ -136,7 +137,7 @@ Feature: Duplication of Content
"""
When we post to "/archive/123/duplicate"
"""
{"desk": "#desks._id#"}
{"desk": "#desks._id#","type": "archive"}
"""
Then we get OK response
When we get "/archive/#duplicate._id#"
Expand All @@ -153,7 +154,7 @@ Feature: Duplication of Content
"""
And we post to "/archive/123/duplicate"
"""
[{"desk": "#desks._id#"}]
[{"desk": "#desks._id#","type": "archive"}]
"""
Then we get response code 403

Expand All @@ -170,7 +171,7 @@ Feature: Duplication of Content
When we switch user
And we post to "/archive/123/duplicate"
"""
{"desk": "#desks._id#"}
{"desk": "#desks._id#","type": "archive"}
"""
And we get "/archive/#duplicate._id#"
Then we get existing resource
Expand Down Expand Up @@ -232,7 +233,7 @@ Feature: Duplication of Content
"""
When we post to "/archive/tag:localhost:2015:515b895a-b336-48b2-a506-5ffaf561b916/duplicate"
"""
{"desk": "#desks._id#"}
{"desk": "#desks._id#","type": "archive"}
"""
When we get "/archive/#duplicate._id#"
Then there is no "linked_in_packages" in response
Expand Down Expand Up @@ -266,11 +267,27 @@ Feature: Duplication of Content
"""
When we post to "/archive/123/duplicate" with success
"""
{"desk": "#desks._id#"}
{"desk": "#desks._id#","type": "archive"}
"""
And we get "/archive/#duplicate._id#"
Then there is no "publish_schedule" in response

@auth @test
Scenario: Duplicate a published item and original item's ID is present in the duplicated item
Given "published"
"""
[{"_id":"1","item_id": "123", "state": "published"}]
"""
When we post to "/archive/#archive._id#/duplicate" with success
"""
{"desk": "#desks._id#","type": "archive"}
"""
And we get "/archive/#duplicate._id#"
Then we get existing resource
"""
{"original_id": "123"}
"""

@auth
Scenario: Duplicate an Updated and Highlighted Item
When we rewrite "123"
Expand All @@ -292,14 +309,14 @@ Feature: Duplication of Content
"""
When we post to "/archive/123/duplicate" with success
"""
{"desk": "#desks._id#"}
{"desk": "#desks._id#","type": "archive"}
"""
And we get "/archive/#duplicate._id#"
Then there is no "rewritten_by" in response
Then there is no "highlights" in response
When we post to "/archive/#REWRITE_ID#/duplicate" with success
"""
{"desk": "#desks._id#"}
{"desk": "#desks._id#","type": "archive"}
"""
And we get "/archive/#duplicate._id#"
Then there is no "rewrite_of" in response
Expand Down Expand Up @@ -333,9 +350,38 @@ Feature: Duplication of Content
Then we get OK response
When we post to "/archive/123/duplicate"
"""
{"desk": "#desks._id#"}
{"desk": "#desks._id#","type": "archive"}
"""
Then we get error 412
"""
{"_message": "Workflow transition is invalid."}
"""
"""

@auth @test
Scenario: Duplicate a archived item and the original ID of the archived item should be copied to duplicated item and the latest version of archived item should be picked
Given "archived"
"""
[{ "_id": "123_1", "state": "published", "type":"text", "headline": "test1", "guid": "123_1", "item_id": "123", "original_creator": "#CONTEXT_USER_ID#",
"source": "REUTERS", "subject":[{"qcode": "17004000", "name": "Statistics"}],
"body_html": "Test Document body", "_current_version": 1,
"task": {"desk": "#desks._id#", "stage": "#desks.working_stage#", "user": "#CONTEXT_USER_ID#"}},
{ "_id": "123_2", "state": "published", "type":"text", "headline": "test2", "guid": "123_2", "item_id": "123", "original_creator": "#CONTEXT_USER_ID#",
"source": "REUTERS", "subject":[{"qcode": "17004000", "name": "Statistics"}],
"body_html": "Test Document body", "_current_version": 2,
"task": {"desk": "#desks._id#", "stage": "#desks.working_stage#", "user": "#CONTEXT_USER_ID#"}
}]
"""
When we get "/archived"
Then we get list with 2 items
When we post to "/archive/123_1/duplicate" with success
"""
{"desk": "#desks._id#", "type": "archived", "item_id": "123"}
"""
When we get "/archive/#duplicate._id#"
Then we get existing resource
"""
{"state": "submitted", "_current_version": 3, "source": "AAP",
"task": {"desk": "#desks._id#", "stage": "#desks.working_stage#", "user": "#CONTEXT_USER_ID#"},
"original_id": "123", "headline": "test2"}
"""

2 changes: 1 addition & 1 deletion features/embargo.feature
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ Feature: Embargo Date and Time on an Article (User Story: https://dev.sourcefabr
Then we get response code 200
When we post to "/archive/123/duplicate" with success
"""
{"desk": "#desks._id#"}
{"desk": "#desks._id#","type": "archive"}
"""
And we get "/archive/#duplicate._id#"
Then there is no "embargo" in response
Expand Down

0 comments on commit bfbbef7

Please sign in to comment.