Skip to content

Commit

Permalink
Merge pull request #688 from mdhaman/1.28
Browse files Browse the repository at this point in the history
Update cores 1.28
  • Loading branch information
Mayur Dhamanwala authored Apr 1, 2019
2 parents e7dc6e3 + 3cd14d4 commit 80dd28d
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 19 deletions.
4 changes: 2 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"license": "GPL-3.0",
"dependencies": {
"superdesk-core": "superdesk/superdesk-client-core#1129ae405",
"superdesk-planning": "superdesk/superdesk-planning#b2735c0",
"superdesk-analytics": "superdesk/superdesk-analytics#ea2ae6e"
"superdesk-planning": "superdesk/superdesk-planning#112e140",
"superdesk-analytics": "superdesk/superdesk-analytics#457ad07"
}
}
9 changes: 6 additions & 3 deletions server/aap/publish/transmitters/http_push_apple_news.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from superdesk.publish.publish_service import PublishService
from superdesk.publish import register_transmitter
from superdesk.errors import PublishHTTPPushError, PublishHTTPPushServerError, PublishHTTPPushClientError
from superdesk import get_resource_service
from superdesk import get_resource_service, config
from superdesk.metadata.item import ITEM_STATE, CONTENT_STATE


Expand Down Expand Up @@ -113,6 +113,7 @@ def _push_item(self, queue_item):
)

try:
response = None
if item.get(ITEM_STATE) not in {CONTENT_STATE.RECALLED, CONTENT_STATE.KILLED}:
headers['Content-Type'] = content_type
session = requests.Session()
Expand All @@ -136,9 +137,11 @@ def _push_item(self, queue_item):
logging.info('Apple News: Successfully transmitted {}.'.format(item.get('item_id')))
except Exception as ex:
logger.exception(ex)
if response:
if response is not None:
message = 'Error pushing item to apple news %s: %s' % (response.status_code, response.text)
self._raise_publish_error(response.status_code, Exception(message), destination)
else:
message = 'Failed to publish item to apple news. Queue Id: {}'.format(queue_item.get(config.ID_FIELD))
self._raise_publish_error(response.status_code, Exception(message), destination)

def _part(self, name, data, length, content_type):
part = RequestField(name, data)
Expand Down
32 changes: 32 additions & 0 deletions server/aap/publish/transmitters/http_push_apple_news_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from superdesk.tests import TestCase
from datetime import datetime
from .http_push_apple_news import HTTPAppleNewsPush
from superdesk.errors import PublishHTTPPushClientError
from hashlib import sha256


Expand Down Expand Up @@ -84,6 +85,17 @@ def delete_item_response(self, url, request):
'status_code': 204
}

@all_requests
def fail_item_response(self, url, request):
self.assertEqual(request.method, 'POST')
self.assertEqual(request.url, 'https://news-api.apple.com/channels/channel1234/articles')
self.assertIn('multipart/form-data', request.headers.get('Content-Type'))
self.assertEqual('application/json', request.headers.get('accept'))
return {
'status_code': 400,
'content': 'Failed to process request'.encode('UTF-8'),
}

def test_transmit_new_item(self):
queue_item = self.get_queue_item()
find_one = Mock(return_value={'item_id': '1', 'state': 'published'})
Expand Down Expand Up @@ -192,3 +204,23 @@ def test_get_headers(self):
self.assertIn(signature, headers.get('authorization'))
self.assertIn(api_key, headers.get('authorization'))
self.assertIn(current_date, headers.get('authorization'))

def test_transmit_fail(self):
queue_item = self.get_queue_item()
find_one = Mock(return_value={'item_id': '1', 'state': 'published'})
get_subscriber_reference = Mock(return_value=None)
insert_update_reference = Mock()
mocked_service = MagicMock()
mocked_service.return_value = MockedResourceService(
find_one=find_one,
get_subscriber_reference=get_subscriber_reference,
insert_update_reference=insert_update_reference
)
with patch('aap.publish.transmitters.http_push_apple_news.get_resource_service', mocked_service):
with HTTMock(self.fail_item_response):
with self.assertRaises(PublishHTTPPushClientError) as context:
self.http_push._push_item(queue_item)

self.assertTrue('HTTP push publish client error' in str(context.exception))
self.assertTrue('Failed to process request' in str(context.exception.system_exception))
self.assertEqual(context.exception.status_code, 400)
22 changes: 11 additions & 11 deletions server/features/sms_report.feature
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Feature: SMS Report
Then we get list with 1 items
"""
{"_items": [{
"start_epoch": 1530226800000,
"start_epoch": 1530223200000,
"interval": 86400000,
"with_sms": [0, 1, 1],
"without_sms": [1, 1, 0]
Expand Down Expand Up @@ -71,14 +71,14 @@ Feature: SMS Report
"type": "column",
"xAxis": 0,
"data": [0, 1, 1],
"pointStart": 1530226800000,
"pointStart": 1530223200000,
"pointInterval": 86400000
}, {
"name": "Without SMS",
"type": "column",
"xAxis": 0,
"data": [1, 1, 0],
"pointStart": 1530226800000,
"pointStart": 1530223200000,
"pointInterval": 86400000
}]
}]
Expand Down Expand Up @@ -106,7 +106,7 @@ Feature: SMS Report
Then we get list with 1 items
"""
{"_items": [{
"start_epoch": 1530313200000,
"start_epoch": 1530309600000,
"interval": 3600000,
"with_sms": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
"without_sms": [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Expand Down Expand Up @@ -155,15 +155,15 @@ Feature: SMS Report
"name": "With SMS",
"type": "column",
"xAxis": 0,
"data": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
"pointStart": 1530313200000,
"data": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
"pointStart": 1530309600000,
"pointInterval": 3600000
}, {
"name": "Without SMS",
"type": "column",
"xAxis": 0,
"data": [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"pointStart": 1530313200000,
"data": [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"pointStart": 1530309600000,
"pointInterval": 3600000
}]
}]
Expand Down Expand Up @@ -194,7 +194,7 @@ Feature: SMS Report
Then we get list with 1 items
"""
{"_items": [{
"start_epoch": 1529190000000,
"start_epoch": 1529186400000,
"interval": 604800000,
"with_sms": [1, 2],
"without_sms": [1, 1]
Expand Down Expand Up @@ -247,14 +247,14 @@ Feature: SMS Report
"type": "column",
"xAxis": 0,
"data": [1, 2],
"pointStart": 1529190000000,
"pointStart": 1529186400000,
"pointInterval": 604800000
}, {
"name": "Without SMS",
"type": "column",
"xAxis": 0,
"data": [1, 1],
"pointStart": 1529190000000,
"pointStart": 1529186400000,
"pointInterval": 604800000
}]
}]
Expand Down
6 changes: 3 additions & 3 deletions server/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ pyasn1==0.3.7
gtfs-realtime-bindings==0.0.5
protobuf3-to-dict==0.1.5

git+git://github.com/superdesk/superdesk-core.git@50ab5e104#egg=Superdesk-Core
git+git://github.com/superdesk/superdesk-planning.git@b2735c0#egg=superdesk-planning
git+git://github.com/superdesk/superdesk-analytics.git@ea2ae6e#egg=superdesk-analytics
git+git://github.com/superdesk/superdesk-core.git@c235985a2#egg=Superdesk-Core
git+git://github.com/superdesk/superdesk-planning.git@112e140#egg=superdesk-planning
git+git://github.com/superdesk/superdesk-analytics.git@457ad07#egg=superdesk-analytics

0 comments on commit 80dd28d

Please sign in to comment.