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

Commit

Permalink
Add functional test for database failing to restart
Browse files Browse the repository at this point in the history
  • Loading branch information
karenc authored and mmulich committed Feb 18, 2015
1 parent 1e339cd commit 1b2446a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions cnxauthoring/tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -2853,6 +2853,31 @@ def test_service_unavailable_response(self):
expect_errors=True)
self.assertEqual(response.status, '503 Service Unavailable')

@mock.patch('cnxauthoring.views.logger')
def test_database_restart_failed(self, logger):
import psycopg2
from ..storage import storage

self.addCleanup(setattr, storage, 'conn',
psycopg2.connect(storage.conn.dsn))

storage.conn.close()

with mock.patch.object(storage, 'restart') as mock_restart:
mock_restart.side_effect = storage.Error

response = self.testapp.post_json(
'/users/contents',
{'title': 'Test Document'},
status=503)
self.assertEqual(mock_restart.call_count, 1)

self.assertEqual(logger.exception.call_count, 3)
args1, args2, args3 = logger.exception.call_args_list
self.assertEqual(args1[0], ('Storage failure',))
self.assertEqual(args2[0], ('Storage failed to abort',))
self.assertEqual(args3[0], ('Storage failed to restart',))


class PublicationTests(BaseFunctionalTestCase):

Expand Down

0 comments on commit 1b2446a

Please sign in to comment.