OLD | NEW |
(Empty) | |
| 1 #!/usr/bin env python |
| 2 |
| 3 from tests.unit import AWSMockServiceTestCase |
| 4 |
| 5 from boto.cloudsearch.domain import Domain |
| 6 from boto.cloudsearch.layer1 import Layer1 |
| 7 |
| 8 import json |
| 9 |
| 10 class TestCloudSearchCreateDomain(AWSMockServiceTestCase): |
| 11 connection_class = Layer1 |
| 12 |
| 13 def default_body(self): |
| 14 return """ |
| 15 <CreateDomainResponse xmlns="http://cloudsearch.amazonaws.com/doc/2011-02-01"> |
| 16 <CreateDomainResult> |
| 17 <DomainStatus> |
| 18 <SearchPartitionCount>0</SearchPartitionCount> |
| 19 <SearchService> |
| 20 <Arn>arn:aws:cs:us-east-1:1234567890:search/demo</Arn> |
| 21 <Endpoint>search-demo-userdomain.us-east-1.cloudsearch.amazonaws.com</En
dpoint> |
| 22 </SearchService> |
| 23 <NumSearchableDocs>0</NumSearchableDocs> |
| 24 <Created>true</Created> |
| 25 <DomainId>1234567890/demo</DomainId> |
| 26 <Processing>false</Processing> |
| 27 <SearchInstanceCount>0</SearchInstanceCount> |
| 28 <DomainName>demo</DomainName> |
| 29 <RequiresIndexDocuments>false</RequiresIndexDocuments> |
| 30 <Deleted>false</Deleted> |
| 31 <DocService> |
| 32 <Arn>arn:aws:cs:us-east-1:1234567890:doc/demo</Arn> |
| 33 <Endpoint>doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com</Endpo
int> |
| 34 </DocService> |
| 35 </DomainStatus> |
| 36 </CreateDomainResult> |
| 37 <ResponseMetadata> |
| 38 <RequestId>00000000-0000-0000-0000-000000000000</RequestId> |
| 39 </ResponseMetadata> |
| 40 </CreateDomainResponse> |
| 41 """ |
| 42 |
| 43 def test_create_domain(self): |
| 44 self.set_http_response(status_code=200) |
| 45 api_response = self.service_connection.create_domain('demo') |
| 46 |
| 47 self.assert_request_parameters({ |
| 48 'Action': 'CreateDomain', |
| 49 'DomainName': 'demo', |
| 50 'AWSAccessKeyId': 'aws_access_key_id', |
| 51 'SignatureMethod': 'HmacSHA256', |
| 52 'SignatureVersion': 2, |
| 53 'Version': '2011-02-01', |
| 54 }, ignore_params_values=['Timestamp']) |
| 55 |
| 56 def test_cloudsearch_connect_result_endpoints(self): |
| 57 """Check that endpoints & ARNs are correctly returned from AWS""" |
| 58 |
| 59 self.set_http_response(status_code=200) |
| 60 api_response = self.service_connection.create_domain('demo') |
| 61 domain = Domain(self, api_response) |
| 62 |
| 63 self.assertEqual(domain.doc_service_arn, |
| 64 "arn:aws:cs:us-east-1:1234567890:doc/demo") |
| 65 self.assertEqual( |
| 66 domain.doc_service_endpoint, |
| 67 "doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com") |
| 68 self.assertEqual(domain.search_service_arn, |
| 69 "arn:aws:cs:us-east-1:1234567890:search/demo") |
| 70 self.assertEqual( |
| 71 domain.search_service_endpoint, |
| 72 "search-demo-userdomain.us-east-1.cloudsearch.amazonaws.com") |
| 73 |
| 74 def test_cloudsearch_connect_result_statuses(self): |
| 75 """Check that domain statuses are correctly returned from AWS""" |
| 76 self.set_http_response(status_code=200) |
| 77 api_response = self.service_connection.create_domain('demo') |
| 78 domain = Domain(self, api_response) |
| 79 |
| 80 self.assertEqual(domain.created, True) |
| 81 self.assertEqual(domain.processing, False) |
| 82 self.assertEqual(domain.requires_index_documents, False) |
| 83 self.assertEqual(domain.deleted, False) |
| 84 |
| 85 def test_cloudsearch_connect_result_details(self): |
| 86 """Check that the domain information is correctly returned from AWS""" |
| 87 self.set_http_response(status_code=200) |
| 88 api_response = self.service_connection.create_domain('demo') |
| 89 domain = Domain(self, api_response) |
| 90 |
| 91 self.assertEqual(domain.id, "1234567890/demo") |
| 92 self.assertEqual(domain.name, "demo") |
| 93 |
| 94 def test_cloudsearch_documentservice_creation(self): |
| 95 self.set_http_response(status_code=200) |
| 96 api_response = self.service_connection.create_domain('demo') |
| 97 domain = Domain(self, api_response) |
| 98 |
| 99 document = domain.get_document_service() |
| 100 |
| 101 self.assertEqual( |
| 102 document.endpoint, |
| 103 "doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com") |
| 104 |
| 105 def test_cloudsearch_searchservice_creation(self): |
| 106 self.set_http_response(status_code=200) |
| 107 api_response = self.service_connection.create_domain('demo') |
| 108 domain = Domain(self, api_response) |
| 109 |
| 110 search = domain.get_search_service() |
| 111 |
| 112 self.assertEqual( |
| 113 search.endpoint, |
| 114 "search-demo-userdomain.us-east-1.cloudsearch.amazonaws.com") |
| 115 |
| 116 |
| 117 class CloudSearchConnectionDeletionTest(AWSMockServiceTestCase): |
| 118 connection_class = Layer1 |
| 119 |
| 120 def default_body(self): |
| 121 return """ |
| 122 <DeleteDomainResponse xmlns="http://cloudsearch.amazonaws.com/doc/2011-02-01"> |
| 123 <DeleteDomainResult> |
| 124 <DomainStatus> |
| 125 <SearchPartitionCount>0</SearchPartitionCount> |
| 126 <SearchService> |
| 127 <Arn>arn:aws:cs:us-east-1:1234567890:search/demo</Arn> |
| 128 <Endpoint>search-demo-userdomain.us-east-1.cloudsearch.amazonaws.com</En
dpoint> |
| 129 </SearchService> |
| 130 <NumSearchableDocs>0</NumSearchableDocs> |
| 131 <Created>true</Created> |
| 132 <DomainId>1234567890/demo</DomainId> |
| 133 <Processing>false</Processing> |
| 134 <SearchInstanceCount>0</SearchInstanceCount> |
| 135 <DomainName>demo</DomainName> |
| 136 <RequiresIndexDocuments>false</RequiresIndexDocuments> |
| 137 <Deleted>false</Deleted> |
| 138 <DocService> |
| 139 <Arn>arn:aws:cs:us-east-1:1234567890:doc/demo</Arn> |
| 140 <Endpoint>doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com</Endpo
int> |
| 141 </DocService> |
| 142 </DomainStatus> |
| 143 </DeleteDomainResult> |
| 144 <ResponseMetadata> |
| 145 <RequestId>00000000-0000-0000-0000-000000000000</RequestId> |
| 146 </ResponseMetadata> |
| 147 </DeleteDomainResponse> |
| 148 """ |
| 149 |
| 150 def test_cloudsearch_deletion(self): |
| 151 """ |
| 152 Check that the correct arguments are sent to AWS when creating a |
| 153 cloudsearch connection. |
| 154 """ |
| 155 self.set_http_response(status_code=200) |
| 156 api_response = self.service_connection.delete_domain('demo') |
| 157 |
| 158 self.assert_request_parameters({ |
| 159 'Action': 'DeleteDomain', |
| 160 'DomainName': 'demo', |
| 161 'AWSAccessKeyId': 'aws_access_key_id', |
| 162 'SignatureMethod': 'HmacSHA256', |
| 163 'SignatureVersion': 2, |
| 164 'Version': '2011-02-01', |
| 165 }, ignore_params_values=['Timestamp']) |
| 166 |
| 167 |
| 168 class CloudSearchConnectionIndexDocumentTest(AWSMockServiceTestCase): |
| 169 connection_class = Layer1 |
| 170 |
| 171 def default_body(self): |
| 172 return """ |
| 173 <IndexDocumentsResponse xmlns="http://cloudsearch.amazonaws.com/doc/2011-02-01"> |
| 174 <IndexDocumentsResult> |
| 175 <FieldNames> |
| 176 <member>average_score</member> |
| 177 <member>brand_id</member> |
| 178 <member>colors</member> |
| 179 <member>context</member> |
| 180 <member>context_owner</member> |
| 181 <member>created_at</member> |
| 182 <member>creator_id</member> |
| 183 <member>description</member> |
| 184 <member>file_size</member> |
| 185 <member>format</member> |
| 186 <member>has_logo</member> |
| 187 <member>has_messaging</member> |
| 188 <member>height</member> |
| 189 <member>image_id</member> |
| 190 <member>ingested_from</member> |
| 191 <member>is_advertising</member> |
| 192 <member>is_photo</member> |
| 193 <member>is_reviewed</member> |
| 194 <member>modified_at</member> |
| 195 <member>subject_date</member> |
| 196 <member>tags</member> |
| 197 <member>title</member> |
| 198 <member>width</member> |
| 199 </FieldNames> |
| 200 </IndexDocumentsResult> |
| 201 <ResponseMetadata> |
| 202 <RequestId>eb2b2390-6bbd-11e2-ab66-93f3a90dcf2a</RequestId> |
| 203 </ResponseMetadata> |
| 204 </IndexDocumentsResponse> |
| 205 """ |
| 206 |
| 207 def test_cloudsearch_index_documents(self): |
| 208 """ |
| 209 Check that the correct arguments are sent to AWS when indexing a |
| 210 domain. |
| 211 """ |
| 212 self.set_http_response(status_code=200) |
| 213 api_response = self.service_connection.index_documents('demo') |
| 214 |
| 215 self.assert_request_parameters({ |
| 216 'Action': 'IndexDocuments', |
| 217 'DomainName': 'demo', |
| 218 'AWSAccessKeyId': 'aws_access_key_id', |
| 219 'SignatureMethod': 'HmacSHA256', |
| 220 'SignatureVersion': 2, |
| 221 'Version': '2011-02-01', |
| 222 }, ignore_params_values=['Timestamp']) |
| 223 |
| 224 def test_cloudsearch_index_documents_resp(self): |
| 225 """ |
| 226 Check that the AWS response is being parsed correctly when indexing a |
| 227 domain. |
| 228 """ |
| 229 self.set_http_response(status_code=200) |
| 230 api_response = self.service_connection.index_documents('demo') |
| 231 |
| 232 self.assertEqual(api_response, ['average_score', 'brand_id', 'colors', |
| 233 'context', 'context_owner', |
| 234 'created_at', 'creator_id', |
| 235 'description', 'file_size', 'format', |
| 236 'has_logo', 'has_messaging', 'height', |
| 237 'image_id', 'ingested_from', |
| 238 'is_advertising', 'is_photo', |
| 239 'is_reviewed', 'modified_at', |
| 240 'subject_date', 'tags', 'title', |
| 241 'width']) |
OLD | NEW |