Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit d67db05

Browse files
authored
251 fix tests (#253)
* Fixed test_appended_error_message_using_save_with_invalid_key * Fixed test_appended_error_message_using_save_with_invalid_key response code and error message to correct values for `400 Bad Request`. * Made test check for Couch 1.6 if 500 error code. * Make test_get_search_result_without_query order independent * Made test_get_search_info checks not rely on indexing completion
1 parent 6a4cc7a commit d67db05

File tree

3 files changed

+34
-20
lines changed

3 files changed

+34
-20
lines changed

tests/unit/database_tests.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,11 +1378,11 @@ def test_get_search_result_without_query(self):
13781378
self.db.get_search_result('searchddoc001', 'searchindex001',
13791379
limit=10, include_docs=True)
13801380
err = cm.exception
1381-
self.assertEqual(
1382-
str(err),
1383-
'A single query/q parameter is required. '
1384-
'Found: {\'limit\': 10, \'include_docs\': True}'
1385-
)
1381+
# Validate that the error message starts as expected
1382+
self.assertTrue(str(err).startswith('A single query/q parameter is required.'))
1383+
# Validate that the error message includes the supplied parameters (in an order independent way)
1384+
self.assertTrue(str(err).find("'limit': 10") >= 0)
1385+
self.assertTrue(str(err).find("'include_docs': True") >= 0)
13861386

13871387
def test_get_search_result_with_invalid_query_type(self):
13881388
"""

tests/unit/design_document_tests.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -790,14 +790,18 @@ def test_get_search_info(self):
790790
ddoc.save()
791791
ddoc_remote = DesignDocument(self.db, '_design/ddoc001')
792792
ddoc_remote.fetch()
793+
793794
search_info = ddoc_remote.search_info('search001')
794-
search_info['search_index'].pop('disk_size')
795-
self.assertEqual(
796-
search_info,
797-
{'name': '_design/ddoc001/search001',
798-
'search_index': {'doc_del_count': 0, 'doc_count': 100,
799-
'pending_seq': 101, 'committed_seq': 0},
800-
})
795+
# Check the search index name
796+
self.assertEqual(search_info['name'], '_design/ddoc001/search001', 'The search index name should be correct.')
797+
# Validate the metadata
798+
search_index_metadata = search_info['search_index']
799+
self.assertIsNotNone(search_index_metadata)
800+
self.assertEquals(search_index_metadata['doc_del_count'], 0, 'There should be no deleted docs.')
801+
self.assertTrue(search_index_metadata['doc_count'] <= 100, 'There should be 100 or fewer docs.')
802+
self.assertEquals(search_index_metadata['committed_seq'], 0, 'The committed_seq should be 0.')
803+
self.assertTrue(search_index_metadata['pending_seq'] <= 101, 'The pending_seq should be 101 or fewer.')
804+
self.assertTrue(search_index_metadata['disk_size'] >0, 'The disk_size should be greater than 0.')
801805

802806
@unittest.skipUnless(
803807
os.environ.get('RUN_CLOUDANT_TESTS') is not None,

tests/unit/document_tests.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -273,14 +273,24 @@ def test_appended_error_message_using_save_with_invalid_key(self):
273273
with self.assertRaises(requests.HTTPError) as cm:
274274
doc.save()
275275
err = cm.exception
276-
self.assertEqual(
277-
str(err.response.reason),
278-
'Internal Server Error doc_validation Bad special document member: _invalid_key'
279-
)
280-
self.assertEqual(
281-
err.response.status_code,
282-
500
283-
)
276+
# Should be a 400 error code, but CouchDB 1.6 issues a 500
277+
if err.response.status_code == 500:
278+
#Check this is CouchDB 1.6
279+
self.assertTrue(self.client.r_session.head(self.url).headers['Server'].find('CouchDB/1.6.') >= 0,
280+
'500 returned but was not CouchDB 1.6.x')
281+
self.assertEqual(
282+
str(err.response.reason),
283+
'Internal Server Error doc_validation Bad special document member: _invalid_key'
284+
)
285+
else:
286+
self.assertEqual(
287+
str(err.response.reason),
288+
'Bad Request doc_validation Bad special document member: _invalid_key'
289+
)
290+
self.assertEqual(
291+
err.response.status_code,
292+
400
293+
)
284294

285295
def test_fetch_existing_document_with_docid_encoded_url(self):
286296
"""

0 commit comments

Comments
 (0)