def test_create_a_search_index_no_kwargs(self):
     """
     Test that a TEXT index is created in the remote database.
     """
     index = TextIndex(self.db, 'ddoc001', 'index001')
     index.create()
     self.assertEqual(index.design_document_id, '_design/ddoc001')
     self.assertEqual(index.name, 'index001')
     with DesignDocument(self.db, index.design_document_id) as ddoc:
         self.assertEqual(ddoc['language'], 'query')
         self.assertListEqual(list(ddoc['indexes'].keys()), ['index001'])
         self.assertTrue(ddoc['_rev'].startswith('1-'))
         self.assertEqual(ddoc,
             {'_id': '_design/ddoc001',
              '_rev': ddoc['_rev'],
              'language': 'query',
              'views': {},
              'indexes': {'index001': 
                  {'index': {'index_array_lengths': True,
                             'fields': 'all_fields',
                             'default_field': {},
                             'default_analyzer': 'keyword',
                             'selector': {}},
                   'analyzer': {'name': 'perfield',
                                'default': 'keyword',
                                'fields': {'$default': 'standard'}}}}}
         )
 def test_create_a_search_index_invalid_argument(self):
     """
     Test that a TEXT index is not created when an invalid argument is given.
     """
     index = TextIndex(self.db, 'ddoc001', 'index001', foo='bar')
     with self.assertRaises(CloudantArgumentError) as cm:
         index.create()
     err = cm.exception
     self.assertEqual(str(err), 'Invalid argument: foo')
 def test_create_a_search_index_invalid_selector_value(self):
     """
     Test that a TEXT index is not created when an invalid selector
     value is given.
     """
     index = TextIndex(self.db, 'ddoc001', 'index001', selector=5)
     with self.assertRaises(CloudantArgumentError) as cm:
         index.create()
     err = cm.exception
     self.assertEqual(
         str(err),
         'Argument selector is not an instance of expected type: '
         '<{} \'dict\'>'.format('type' if PY2 else 'class')
     )
 def test_search_index_via_query(self):
     """
     Test that a created TEXT index will produce expected query results.
     """
     index = TextIndex(self.db, 'ddoc001', 'index001')
     index.create()
     self.populate_db_with_documents(100)
     with Document(self.db, 'julia006') as doc:
         doc['name'] = 'julia isabel'
     query = Query(self.db)
     resp = query(
         fields=['name', 'age'],
         selector={'$text': 'isabel'}
     )
     self.assertEqual(resp['docs'], [{'name': 'julia isabel', 'age': 6}])