Skip to content

Commit

Permalink
Merge pull request #564 from petrjasek/feat-publish-no-takes
Browse files Browse the repository at this point in the history
feat(publish): add `USE_TAKES` config option
  • Loading branch information
ioanpocol committed Sep 7, 2016
2 parents 580c56e + 656d9f1 commit 7fca944
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Added

- Add `USE_TAKES` (default: `True`) config to be able to turn off takes packages.

## [1.1] 2016-08-29

### Added
Expand Down
2 changes: 1 addition & 1 deletion apps/publish/content/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def update(self, id, updates, original):
if updates.get('associations'):
self._refresh_associated_items(updated) # updates got lost with update

if self.published_state != CONTENT_STATE.KILLED:
if self.published_state != CONTENT_STATE.KILLED and app.config.get('USE_TAKES', True):
self._process_takes_package(original, updated, updates)

self._update_archive(original, updates, should_insert_into_versions=auto_publish)
Expand Down
80 changes: 80 additions & 0 deletions features/http_push.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
@wip
Feature: HTTP Push publishing

@auth
@http_mock_adapter
Scenario: Publish a text item without takes package
Given config
"""
{"USE_TAKES": false}
"""
Given "products"
"""
[{"name": "all"}]
"""
Given "subscribers"
"""
[{
"name": "http",
"media_type": "media",
"subscriber_type": "digital",
"products": ["#products._id#"],
"destinations": [
{
"name": "destination1",
"format": "ninjs",
"delivery_type": "http_push",
"config": {
"resource_url": "mock://publish",
"assets_url": "mock://assets",
"packaged": "true"
}
}
]
}]
"""
Given "content_types"
"""
[{"_id": "foo", "schema": {}}]
"""
Given "desks"
"""
[{"name": "sports"}]
"""

When we post to "archive"
"""
{"profile": "foo", "type": "text", "task": {"desk": "#desks._id#"}}
"""

When we patch "archive/#archive._id#"
"""
{"slugline": "slug", "body_html": "body"}
"""

When we publish "#archive._id#" with "publish" type and "published" state
Then we get OK response

When we transmit published
Then we pushed 1 item
"""
[{"guid": "#archive.guid#", "profile": "foo", "type": "text", "body_html": "body", "version": "3"}]
"""

When we publish "#archive._id#" with "correct" type and "corrected" state
"""
{"body_html": "corrected"}
"""

When we transmit published
Then we pushed 1 item
"""
[{"guid": "#archive.guid#", "type": "text", "version": "4", "body_html": "corrected"}]
"""

When we publish "#archive._id#" with "kill" type and "killed" state
When we transmit published
Then we pushed 1 item
"""
[{"guid": "#archive.guid#", "type": "text", "pubstatus": "canceled", "version": "5"}]
"""
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ httmock
wooper
sphinx
sphinx-autobuild
requests-mock
28 changes: 28 additions & 0 deletions superdesk/tests/publish_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
# at https://www.sourcefabric.org/superdesk/license


import requests_mock
from flask import json
from behave import when, then # @UnresolvedImport
from apps.publish.enqueue import enqueue_published
from superdesk.tests.steps import assert_200, apply_placeholders, json_match
from wooper.general import fail_and_print_body
from wooper.assertions import assert_equal
from superdesk.publish import transmit


@when('we enqueue published')
Expand All @@ -33,3 +35,29 @@ def then_we_get_formatted_item(context):
context_data = json.loads(apply_placeholders(context, context.text))
assert_equal(json_match(context_data, formatted_item), True,
msg=str(context_data) + '\n != \n' + str(formatted_item))


@then('we pushed 1 item')
def then_we_pushed_1_item(context):
return then_we_pushed_x_items(context, 1)


@then('we pushed {count} items')
def then_we_pushed_x_items(context, count):
history = context.http_mock.request_history
assert count == len(history), 'there were %d calls' % (len(history), )
if context.text:
context_data = json.loads(apply_placeholders(context, context.text))
for i, _ in enumerate(context_data):
assert_equal(json_match(context_data[i], history[i].json()), True,
msg='item[%d]: %s' % (i, history[i]))


@when('we transmit published')
def when_we_transmit_published(context):
with requests_mock.Mocker() as m:
context.http_mock = m
m.post('mock://publish', text=json.dumps({}))
m.post('mock://assets', text=json.dumps({}))
transmit.apply_async()
transmit.apply_async()

0 comments on commit 7fca944

Please sign in to comment.