Skip to content
This repository has been archived by the owner on Feb 13, 2019. It is now read-only.

Commit

Permalink
Liveblog firebase notify raises on error + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mparent61 committed Aug 31, 2016
1 parent 0133768 commit 1f1abc0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion bulbs/liveblog/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def firebase_update_timestamp(liveblog_id):
endpoint = getattr(settings, 'LIVEBLOG_FIREBASE_NOTIFY_ENDPOINT', None)
if endpoint:
url = endpoint.format(liveblog_id=liveblog_id)
requests.put(url, json={
resp = requests.put(url, json={
'updatedAt': timezone.now().timestamp() # TODO: What time format?
})
resp.raise_for_status()
30 changes: 30 additions & 0 deletions tests/liveblog/test_liveblog_tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from freezegun import freeze_time
from requests.exceptions import HTTPError
import requests_mock

from django.test import TestCase
from django.test.utils import override_settings

from bulbs.liveblog.tasks import firebase_update_timestamp


@override_settings(LIVEBLOG_FIREBASE_NOTIFY_ENDPOINT='http://firebase.local/{liveblog_id}.json')
class TestFiresbaseUpdateTimestamp(TestCase):

@freeze_time('2016-08-31 12:13:14')
def test_success(self):
with requests_mock.mock() as mocker:
mocker.put('http://firebase.local/123.json', status_code=200)

firebase_update_timestamp(123)

self.assertEqual(mocker.call_count, 1)
self.assertEqual(mocker.request_history[0].json(),
{'updatedAt': 1472645594.0})

def test_request_error(self):
with requests_mock.mock() as mocker:
mocker.put('http://firebase.local/123.json', status_code=500)

with self.assertRaises(HTTPError):
firebase_update_timestamp(123)

0 comments on commit 1f1abc0

Please sign in to comment.