Skip to content

Commit

Permalink
Accomodate case where 'list_documents' API returns only document IDs.
Browse files Browse the repository at this point in the history
This case is actually the default if no 'view' is passed.
  • Loading branch information
tseaver committed Oct 14, 2015
1 parent d8961e5 commit a9728ba
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions gcloud/search/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,20 @@ def _makeResource(self):
}
}

def _makeDocumentResource(self, doc_id, rank, title):
return {
'docId': doc_id,
'rank': rank,
'fields': {
def _makeDocumentResource(self, doc_id, rank=None, title=None):
resource = {'docId': doc_id}
if rank is not None:
resource['rank'] = rank
if title is not None:
resource['fields'] = {
'title': {
'values': [{
'stringValue': title,
'stringFormat': 'text',
'lang': 'en'}]
}
}
}
return resource

def _verifyResourceProperties(self, index, resource):

Expand All @@ -82,10 +83,11 @@ def _verifyDocumentResource(self, documents, resource):
for found, expected in zip(documents, resource['documents']):
self.assertTrue(isinstance(found, Document))
self.assertEqual(found.name, expected['docId'])
self.assertEqual(found.rank, expected['rank'])
self.assertEqual(sorted(found.fields), sorted(expected['fields']))
self.assertEqual(found.rank, expected.get('rank'))
e_fields = expected.get('fields', ())
self.assertEqual(sorted(found.fields), sorted(e_fields))
for field, f_field in found.fields.items():
e_field = expected['fields'][field]
e_field = e_fields[field]
for f_value, e_value in zip(f_field.values, e_field['values']):
self.assertTrue(isinstance(f_value, StringValue))
self.assertEqual(f_value.string_value,
Expand Down Expand Up @@ -141,16 +143,12 @@ def test_from_api_repr_w_properties(self):

def test_list_documents_defaults(self):
DOCID_1 = 'docid-one'
RANK_1 = 2345
TITLE_1 = 'Title One'
DOCID_2 = 'docid-two'
RANK_2 = 1234
TITLE_2 = 'Title Two'
PATH = 'projects/%s/indexes/%s/documents' % (
self.PROJECT, self.INDEX_ID)
TOKEN = 'TOKEN'
DOC_1 = self._makeDocumentResource(DOCID_1, RANK_1, TITLE_1)
DOC_2 = self._makeDocumentResource(DOCID_2, RANK_2, TITLE_2)
DOC_1 = self._makeDocumentResource(DOCID_1)
DOC_2 = self._makeDocumentResource(DOCID_2)
DATA = {
'nextPageToken': TOKEN,
'documents': [DOC_1, DOC_2],
Expand Down

0 comments on commit a9728ba

Please sign in to comment.