Example #1
0
    def test_fake_docs_too_big(self):
        document = DocumentServiceConnection(
            endpoint="doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com")
        document.add("1234", 10, {"id": "1234", "title": "Title 1",
                                  "category": ["cat_a", "cat_b", "cat_c"]})

        self.assertRaises(ContentTooLongError, document.commit)
Example #2
0
    def test_fake_docs_too_big(self):
        document = DocumentServiceConnection(
            endpoint="doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com")
        document.add("1234", 10, {"id": "1234", "title": "Title 1",
                                  "category": ["cat_a", "cat_b", "cat_c"]})

        self.assertRaises(ContentTooLongError, document.commit)
Example #3
0
 def test_fake_failure(self):
     document = DocumentServiceConnection(
         endpoint="doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com")
     document.add(
         "1234", 10, {
             "id": "1234",
             "title": "Title 1",
             "category": ["cat_a", "cat_b", "cat_c"]
         })
     self.assertRaises(SearchServiceException, document.commit)
Example #4
0
    def test_cloudsearch_delete_results(self):
        """
        Check that the result of a single document deletion is parsed properly.
        """
        document = DocumentServiceConnection(
            endpoint="doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com")
        document.delete("5", "10")
        doc = document.commit()

        self.assertEqual(doc.status, 'success')
        self.assertEqual(doc.adds, 0)
        self.assertEqual(doc.deletes, 1)
Example #5
0
    def test_cloudsearch_delete_results(self):
        """
        Check that the result of a single document deletion is parsed properly.
        """
        document = DocumentServiceConnection(
            endpoint="doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com")
        document.delete("5", "10")
        doc = document.commit()

        self.assertEqual(doc.status, 'success')
        self.assertEqual(doc.adds, 0)
        self.assertEqual(doc.deletes, 1)
Example #6
0
    def test_cloudsearch_erroneous_sdf(self):
        original = boto.log.error
        boto.log.error = MagicMock()
        document = DocumentServiceConnection(
            endpoint="doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com")

        document.add("1234", 10, {"id": "1234", "title": None,
                                  "category": ["cat_a", "cat_b", "cat_c"]})

        document.commit()
        self.assertNotEqual(len(boto.log.error.call_args_list), 1)

        boto.log.error = original
Example #7
0
    def test_cloudsearch_delete(self):
        """
        Test that the request for a single document deletion is done properly.
        """
        document = DocumentServiceConnection(
            endpoint="doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com")
        document.delete("5", "10")
        document.commit()
        args = json.loads(HTTPretty.last_request.body)[0]

        self.assertEqual(args['version'], '10')
        self.assertEqual(args['type'], 'delete')
        self.assertEqual(args['id'], '5')
Example #8
0
    def test_cloudsearch_add_results(self):
        """
        Check that the result from adding multiple documents is parsed
        correctly.
        """
        document = DocumentServiceConnection(
            endpoint="doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com")
        for (key, obj) in self.objs.items():
            document.add(key, obj['version'], obj['fields'])
        doc = document.commit()

        self.assertEqual(doc.status, 'success')
        self.assertEqual(doc.adds, len(self.objs))
        self.assertEqual(doc.deletes, 0)
Example #9
0
    def test_cloudsearch_add_results(self):
        """
        Check that the result from adding multiple documents is parsed
        correctly.
        """
        document = DocumentServiceConnection(
            endpoint="doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com")
        for (key, obj) in self.objs.items():
            document.add(key, obj['version'], obj['fields'])
        doc = document.commit()

        self.assertEqual(doc.status, 'success')
        self.assertEqual(doc.adds, len(self.objs))
        self.assertEqual(doc.deletes, 0)
Example #10
0
    def test_cloudsearch_add_basics(self):
        """
        Check that a simple add document actually sends an add document request
        to AWS.
        """
        document = DocumentServiceConnection(
            endpoint="doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com")
        document.add("1234", 10, {"id": "1234", "title": "Title 1",
                                  "category": ["cat_a", "cat_b", "cat_c"]})
        document.commit()

        args = json.loads(HTTPretty.last_request.body)[0]

        self.assertEqual(args['lang'], 'en')
        self.assertEqual(args['type'], 'add')
Example #11
0
    def test_cloudsearch_add_single_result(self):
        """
        Check that the reply from adding a single document is correctly parsed.
        """
        document = DocumentServiceConnection(
            endpoint="doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com")
        document.add("1234", 10, {"id": "1234", "title": "Title 1",
                                  "category": ["cat_a", "cat_b", "cat_c"]})
        doc = document.commit()

        self.assertEqual(doc.status, 'success')
        self.assertEqual(doc.adds, 1)
        self.assertEqual(doc.deletes, 0)

        self.assertEqual(doc.doc_service, document)
Example #12
0
    def test_cloudsearch_add_single_result(self):
        """
        Check that the reply from adding a single document is correctly parsed.
        """
        document = DocumentServiceConnection(
            endpoint="doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com")
        document.add("1234", 10, {"id": "1234", "title": "Title 1",
                                  "category": ["cat_a", "cat_b", "cat_c"]})
        doc = document.commit()

        self.assertEqual(doc.status, 'success')
        self.assertEqual(doc.adds, 1)
        self.assertEqual(doc.deletes, 0)

        self.assertEqual(doc.doc_service, document)
Example #13
0
    def test_cloudsearch_add_single_fields(self):
        """
        Check that a simple add document sends the actual document to AWS.
        """
        document = DocumentServiceConnection(
            endpoint="doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com")
        document.add("1234", 10, {"id": "1234", "title": "Title 1",
                                  "category": ["cat_a", "cat_b", "cat_c"]})
        document.commit()

        args = json.loads(HTTPretty.last_request.body)[0]

        self.assertEqual(args['fields']['category'], ['cat_a', 'cat_b',
                                                      'cat_c'])
        self.assertEqual(args['fields']['id'], '1234')
        self.assertEqual(args['fields']['title'], 'Title 1')
Example #14
0
    def test_cloudsearch_add_single_basic(self):
        """
        Check that a simple add document sends correct document metadata to
        AWS.
        """
        document = DocumentServiceConnection(
            endpoint="doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com")
        document.add("1234", 10, {"id": "1234", "title": "Title 1",
                                  "category": ["cat_a", "cat_b", "cat_c"]})
        document.commit()

        args = json.loads(HTTPretty.last_request.body)[0]

        self.assertEqual(args['id'], '1234')
        self.assertEqual(args['version'], 10)
        self.assertEqual(args['type'], 'add')
Example #15
0
    def test_cloudsearch_delete_multiples(self):
        document = DocumentServiceConnection(
            endpoint="doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com")
        document.delete("5", "10")
        document.delete("6", "11")
        document.commit()
        args = json.loads(HTTPretty.last_request.body)

        self.assertEqual(len(args), 2)
        for arg in args:
            self.assertEqual(arg['type'], 'delete')

            if arg['id'] == '5':
                self.assertEqual(arg['version'], '10')
            elif arg['id'] == '6':
                self.assertEqual(arg['version'], '11')
            else: # Unknown result out of AWS that shouldn't be there
                self.assertTrue(False)
Example #16
0
    def test_cloudsearch_single_document_sdf(self):
        document = DocumentServiceConnection(
            endpoint="doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com")

        document.add("1234", 10, {"id": "1234", "title": "Title 1",
                                  "category": ["cat_a", "cat_b", "cat_c"]})

        self.assertNotEqual(document.get_sdf(), '[]')

        document.clear_sdf()

        self.assertEqual(document.get_sdf(), '[]')
Example #17
0
    def test_cloudsearch_add_basics(self):
        """Check that multiple documents are added correctly to AWS"""
        document = DocumentServiceConnection(
            endpoint="doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com")
        for (key, obj) in self.objs.items():
            document.add(key, obj['version'], obj['fields'])
        document.commit()

        args = json.loads(HTTPretty.last_request.body)

        for arg in args:
            self.assertTrue(arg['id'] in self.objs)
            self.assertEqual(arg['version'], self.objs[arg['id']]['version'])
            self.assertEqual(arg['fields']['id'],
                             self.objs[arg['id']]['fields']['id'])
            self.assertEqual(arg['fields']['title'],
                             self.objs[arg['id']]['fields']['title'])
            self.assertEqual(arg['fields']['category'],
                             self.objs[arg['id']]['fields']['category'])
Example #18
0
    def test_cloudsearch_single_document_sdf(self):
        document = DocumentServiceConnection(
            endpoint="doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com")

        document.add("1234", 10, {"id": "1234", "title": "Title 1",
                                  "category": ["cat_a", "cat_b", "cat_c"]})

        self.assertNotEqual(document.get_sdf(), '[]')

        document.clear_sdf()

        self.assertEqual(document.get_sdf(), '[]')
Example #19
0
	def save_to_cloudsearch(self, conn=None):
		'''Save/Update this item in CloudSearch'''
		from boto.cloudsearch.document import DocumentServiceConnection
		if conn is None:
			conn = DocumentServiceConnection(endpoint=self._cs_document_endpoint)
		# Build the document ID
		doc_id = self.id
		doc_id = b32encode(doc_id).lower().replace('=', '_')
		conn.add(doc_id, int(time.time()), fields=self.get_sdf())
		conn.commit()
Example #20
0
	def delete(self, *args, **kwargs):
		'''Intercept the delete function to also remove this record from CloudSearch
		if it is indexed'''
		if self._cs_document_endpoint:
			from boto.cloudsearch.document import DocumentServiceConnection
			conn = DocumentServiceConnection(endpoint=self._cs_document_endpoint)
			doc_id = self.id
			doc_id = b32encode(doc_id).lower().replace('=', '_')
			conn.delete(doc_id, int(time.time()))
			conn.commit()
		return Item.delete(self, *args, **kwargs)
Example #21
0
    def test_cloudsearch_erroneous_sdf(self):
        original = boto.log.error
        boto.log.error = MagicMock()
        document = DocumentServiceConnection(
            endpoint="doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com")

        document.add("1234", 10, {"id": "1234", "title": None,
                                  "category": ["cat_a", "cat_b", "cat_c"]})

        document.commit()
        self.assertNotEqual(len(boto.log.error.call_args_list), 1)

        boto.log.error = original
Example #22
0
    def test_cloudsearch_delete(self):
        """
        Test that the request for a single document deletion is done properly.
        """
        document = DocumentServiceConnection(
            endpoint="doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com")
        document.delete("5", "10")
        document.commit()
        args = json.loads(HTTPretty.last_request.body.decode('utf-8'))[0]

        self.assertEqual(args['version'], '10')
        self.assertEqual(args['type'], 'delete')
        self.assertEqual(args['id'], '5')
Example #23
0
    def test_cloudsearch_add_basics(self):
        """
        Check that a simple add document actually sends an add document request
        to AWS.
        """
        document = DocumentServiceConnection(
            endpoint="doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com")
        document.add("1234", 10, {"id": "1234", "title": "Title 1",
                                  "category": ["cat_a", "cat_b", "cat_c"]})
        document.commit()

        args = json.loads(HTTPretty.last_request.body.decode('utf-8'))[0]

        self.assertEqual(args['lang'], 'en')
        self.assertEqual(args['type'], 'add')
Example #24
0
    def test_cloudsearch_add_single_basic(self):
        """
        Check that a simple add document sends correct document metadata to
        AWS.
        """
        document = DocumentServiceConnection(
            endpoint="doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com")
        document.add("1234", 10, {"id": "1234", "title": "Title 1",
                                  "category": ["cat_a", "cat_b", "cat_c"]})
        document.commit()

        args = json.loads(HTTPretty.last_request.body.decode('utf-8'))[0]

        self.assertEqual(args['id'], '1234')
        self.assertEqual(args['version'], 10)
        self.assertEqual(args['type'], 'add')
Example #25
0
    def test_cloudsearch_add_single_fields(self):
        """
        Check that a simple add document sends the actual document to AWS.
        """
        document = DocumentServiceConnection(
            endpoint="doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com")
        document.add("1234", 10, {"id": "1234", "title": "Title 1",
                                  "category": ["cat_a", "cat_b", "cat_c"]})
        document.commit()

        args = json.loads(HTTPretty.last_request.body.decode('utf-8'))[0]

        self.assertEqual(args['fields']['category'], ['cat_a', 'cat_b',
                                                      'cat_c'])
        self.assertEqual(args['fields']['id'], '1234')
        self.assertEqual(args['fields']['title'], 'Title 1')
Example #26
0
    def test_cloudsearch_delete_multiples(self):
        document = DocumentServiceConnection(
            endpoint="doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com")
        document.delete("5", "10")
        document.delete("6", "11")
        document.commit()
        args = json.loads(HTTPretty.last_request.body.decode('utf-8'))

        self.assertEqual(len(args), 2)
        for arg in args:
            self.assertEqual(arg['type'], 'delete')

            if arg['id'] == '5':
                self.assertEqual(arg['version'], '10')
            elif arg['id'] == '6':
                self.assertEqual(arg['version'], '11')
            else:  # Unknown result out of AWS that shouldn't be there
                self.assertTrue(False)
Example #27
0
    def test_cloudsearch_add_basics(self):
        """Check that multiple documents are added correctly to AWS"""
        document = DocumentServiceConnection(
            endpoint="doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com")
        for (key, obj) in self.objs.items():
            document.add(key, obj['version'], obj['fields'])
        document.commit()

        args = json.loads(HTTPretty.last_request.body.decode('utf-8'))

        for arg in args:
            self.assertTrue(arg['id'] in self.objs)
            self.assertEqual(arg['version'], self.objs[arg['id']]['version'])
            self.assertEqual(arg['fields']['id'],
                             self.objs[arg['id']]['fields']['id'])
            self.assertEqual(arg['fields']['title'],
                             self.objs[arg['id']]['fields']['title'])
            self.assertEqual(arg['fields']['category'],
                             self.objs[arg['id']]['fields']['category'])
Example #28
0
 def test_fake_failure(self):
     document = DocumentServiceConnection(
         endpoint="doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com")
     document.add("1234", 10, {"id": "1234", "title": "Title 1",
                               "category": ["cat_a", "cat_b", "cat_c"]})
     self.assertRaises(SearchServiceException, document.commit)
Example #29
0
 def get_document_service(self):
     return DocumentServiceConnection(domain=self)
Example #30
0
    def test_cloudsearch_initial_sdf_is_blank(self):
        document = DocumentServiceConnection(
            endpoint="doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com")

        self.assertEqual(document.get_sdf(), '[]')
Example #31
0
    def test_cloudsearch_initial_sdf_is_blank(self):
        document = DocumentServiceConnection(
            endpoint="doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com")

        self.assertEqual(document.get_sdf(), '[]')