#!/usr/bin env python
from tests.unit import AWSMockServiceTestCase
from boto.cloudsearch.domain import Domain
from boto.cloudsearch.layer1 import Layer1
import json
class TestCloudSearchCreateDomain(AWSMockServiceTestCase):
connection_class = Layer1
def default_body(self):
return """
0
arn:aws:cs:us-east-1:1234567890:search/demo
search-demo-userdomain.us-east-1.cloudsearch.amazonaws.com
0
true
1234567890/demo
false
0
demo
false
false
arn:aws:cs:us-east-1:1234567890:doc/demo
doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com
00000000-0000-0000-0000-000000000000
"""
def test_create_domain(self):
self.set_http_response(status_code=200)
api_response = self.service_connection.create_domain('demo')
self.assert_request_parameters({
'Action': 'CreateDomain',
'DomainName': 'demo',
'AWSAccessKeyId': 'aws_access_key_id',
'SignatureMethod': 'HmacSHA256',
'SignatureVersion': 2,
'Version': '2011-02-01',
}, ignore_params_values=['Timestamp'])
def test_cloudsearch_connect_result_endpoints(self):
"""Check that endpoints & ARNs are correctly returned from AWS"""
self.set_http_response(status_code=200)
api_response = self.service_connection.create_domain('demo')
domain = Domain(self, api_response)
self.assertEqual(domain.doc_service_arn,
"arn:aws:cs:us-east-1:1234567890:doc/demo")
self.assertEqual(
domain.doc_service_endpoint,
"doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com")
self.assertEqual(domain.search_service_arn,
"arn:aws:cs:us-east-1:1234567890:search/demo")
self.assertEqual(
domain.search_service_endpoint,
"search-demo-userdomain.us-east-1.cloudsearch.amazonaws.com")
def test_cloudsearch_connect_result_statuses(self):
"""Check that domain statuses are correctly returned from AWS"""
self.set_http_response(status_code=200)
api_response = self.service_connection.create_domain('demo')
domain = Domain(self, api_response)
self.assertEqual(domain.created, True)
self.assertEqual(domain.processing, False)
self.assertEqual(domain.requires_index_documents, False)
self.assertEqual(domain.deleted, False)
def test_cloudsearch_connect_result_details(self):
"""Check that the domain information is correctly returned from AWS"""
self.set_http_response(status_code=200)
api_response = self.service_connection.create_domain('demo')
domain = Domain(self, api_response)
self.assertEqual(domain.id, "1234567890/demo")
self.assertEqual(domain.name, "demo")
def test_cloudsearch_documentservice_creation(self):
self.set_http_response(status_code=200)
api_response = self.service_connection.create_domain('demo')
domain = Domain(self, api_response)
document = domain.get_document_service()
self.assertEqual(
document.endpoint,
"doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com")
def test_cloudsearch_searchservice_creation(self):
self.set_http_response(status_code=200)
api_response = self.service_connection.create_domain('demo')
domain = Domain(self, api_response)
search = domain.get_search_service()
self.assertEqual(
search.endpoint,
"search-demo-userdomain.us-east-1.cloudsearch.amazonaws.com")
class CloudSearchConnectionDeletionTest(AWSMockServiceTestCase):
connection_class = Layer1
def default_body(self):
return """
0
arn:aws:cs:us-east-1:1234567890:search/demo
search-demo-userdomain.us-east-1.cloudsearch.amazonaws.com
0
true
1234567890/demo
false
0
demo
false
false
arn:aws:cs:us-east-1:1234567890:doc/demo
doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com
00000000-0000-0000-0000-000000000000
"""
def test_cloudsearch_deletion(self):
"""
Check that the correct arguments are sent to AWS when creating a
cloudsearch connection.
"""
self.set_http_response(status_code=200)
api_response = self.service_connection.delete_domain('demo')
self.assert_request_parameters({
'Action': 'DeleteDomain',
'DomainName': 'demo',
'AWSAccessKeyId': 'aws_access_key_id',
'SignatureMethod': 'HmacSHA256',
'SignatureVersion': 2,
'Version': '2011-02-01',
}, ignore_params_values=['Timestamp'])
class CloudSearchConnectionIndexDocumentTest(AWSMockServiceTestCase):
connection_class = Layer1
def default_body(self):
return """
average_score
brand_id
colors
context
context_owner
created_at
creator_id
description
file_size
format
has_logo
has_messaging
height
image_id
ingested_from
is_advertising
is_photo
is_reviewed
modified_at
subject_date
tags
title
width
eb2b2390-6bbd-11e2-ab66-93f3a90dcf2a
"""
def test_cloudsearch_index_documents(self):
"""
Check that the correct arguments are sent to AWS when indexing a
domain.
"""
self.set_http_response(status_code=200)
api_response = self.service_connection.index_documents('demo')
self.assert_request_parameters({
'Action': 'IndexDocuments',
'DomainName': 'demo',
'AWSAccessKeyId': 'aws_access_key_id',
'SignatureMethod': 'HmacSHA256',
'SignatureVersion': 2,
'Version': '2011-02-01',
}, ignore_params_values=['Timestamp'])
def test_cloudsearch_index_documents_resp(self):
"""
Check that the AWS response is being parsed correctly when indexing a
domain.
"""
self.set_http_response(status_code=200)
api_response = self.service_connection.index_documents('demo')
self.assertEqual(api_response, ['average_score', 'brand_id', 'colors',
'context', 'context_owner',
'created_at', 'creator_id',
'description', 'file_size', 'format',
'has_logo', 'has_messaging', 'height',
'image_id', 'ingested_from',
'is_advertising', 'is_photo',
'is_reviewed', 'modified_at',
'subject_date', 'tags', 'title',
'width'])