|
23 | 23 | """ |
24 | 24 |
|
25 | 25 | import unittest |
| 26 | +import mock |
26 | 27 | import requests |
27 | 28 | import posixpath |
28 | 29 | import os |
@@ -92,13 +93,28 @@ def test_retrieve_creds(self): |
92 | 93 |
|
93 | 94 | def test_exists(self): |
94 | 95 | """ |
95 | | - Test database exists fucntionality |
| 96 | + Tests that the result of True is expected when the database exists, |
| 97 | + and False is expected when the database is nonexistent remotely. |
96 | 98 | """ |
97 | 99 | self.assertTrue(self.db.exists()) |
98 | 100 | # Construct a database object that does not exist remotely |
99 | 101 | fake_db = self.client._DATABASE_CLASS(self.client, 'no-such-db') |
100 | 102 | self.assertFalse(fake_db.exists()) |
101 | 103 |
|
| 104 | + def test_exists_raises_httperror(self): |
| 105 | + """ |
| 106 | + Test database exists raises an HTTPError. |
| 107 | + """ |
| 108 | + # Mock HTTPError when running against CouchDB and Cloudant |
| 109 | + resp = requests.Response() |
| 110 | + resp.status_code = 400 |
| 111 | + self.client.r_session.head = mock.Mock(return_value=resp) |
| 112 | + with self.assertRaises(requests.HTTPError) as cm: |
| 113 | + self.db.exists() |
| 114 | + err = cm.exception |
| 115 | + self.assertEqual(err.response.status_code, 400) |
| 116 | + self.client.r_session.head.assert_called_with(self.db.database_url) |
| 117 | + |
102 | 118 | def test_create_db_delete_db(self): |
103 | 119 | """ |
104 | 120 | Test creating and deleting a database |
@@ -749,6 +765,26 @@ def test_update_doc_with_update_handler(self): |
749 | 765 | 'message': 'hello'} |
750 | 766 | ) |
751 | 767 |
|
| 768 | + def test_update_handler_raises_httperror(self): |
| 769 | + """ |
| 770 | + Test update_handler_result raises an HTTPError. |
| 771 | + """ |
| 772 | + # Mock HTTPError when running against CouchDB or Cloudant |
| 773 | + resp = requests.Response() |
| 774 | + resp.status_code = 400 |
| 775 | + self.client.r_session.put = mock.Mock(return_value=resp) |
| 776 | + with self.assertRaises(requests.HTTPError) as cm: |
| 777 | + self.db.update_handler_result('ddoc001', 'update001', 'julia001', |
| 778 | + field='new_field', value='new_value', |
| 779 | + data={'message': 'hello'}) |
| 780 | + err = cm.exception |
| 781 | + self.assertEqual(err.response.status_code, 400) |
| 782 | + ddoc = DesignDocument(self.db, 'ddoc001') |
| 783 | + self.client.r_session.put.assert_called_with( |
| 784 | + '/'.join([ddoc.document_url, '_update', 'update001', 'julia001']), |
| 785 | + data={'message': 'hello'}, |
| 786 | + params={'field': 'new_field', 'value': 'new_value'}) |
| 787 | + |
752 | 788 | @unittest.skipUnless( |
753 | 789 | os.environ.get('RUN_CLOUDANT_TESTS') is not None, |
754 | 790 | 'Skipping Cloudant specific Database tests' |
|
0 commit comments