コード例 #1
0
ファイル: api.py プロジェクト: EMSL-MSC/pacifica-metadata
 def test_failed_upload(self):
     """
     Test the upload class method failed upload
     """
     obj_hash = {
         '_id': 127,
         u'foo': u'bar'
     }
     url = "http://127.0.0.1:9200/pacifica/ElasticAPI/127"
     obj = ElasticAPI()
     obj.id = 127
     setattr(obj, 'to_hash', lambda: obj_hash)
     response_body = {
         "status": "failed!"
     }
     httpretty.register_uri(httpretty.PUT, url,
                            body=dumps(response_body),
                            content_type="application/json",
                            status=500)
     #pylint: disable=broad-except
     try:
         ElasticAPI.elastic_upload(obj)
     except Exception, ex:
         self.assertEqual(httpretty.last_request().method, "PUT")
         self.assertEqual(str(ex), "upload_obj: 500\n")
コード例 #2
0
ファイル: api.py プロジェクト: EMSL-MSC/pacifica-metadata
 def test_upload(self):
     """
     Test the upload class method
     """
     obj_hash = {
         '_id': 127,
         u'foo': u'bar'
     }
     url = "http://127.0.0.1:9200/pacifica/ElasticAPI/127"
     obj = ElasticAPI()
     obj.id = 127
     setattr(obj, 'to_hash', lambda: obj_hash)
     response_body = {
         "status": "uploaded!"
     }
     httpretty.register_uri(httpretty.PUT, url,
                            body=dumps(response_body),
                            content_type="application/json")
     ElasticAPI.elastic_upload(obj)
     self.assertEqual(httpretty.last_request().method, "PUT")
     sent_body = httpretty.last_request().parsed_body
     self.assertTrue(isinstance(sent_body, unicode))
     sent_body = loads(sent_body)
     self.assertTrue('_id' not in sent_body)
     for key, value in sent_body.iteritems():
         self.assertEqual(value, obj_hash[key])
コード例 #3
0
ファイル: api.py プロジェクト: EMSL-MSC/pacifica-metadata
 def test_delete(self):
     """
     Test the delete class method
     """
     url = "http://127.0.0.1:9200/pacifica/ElasticAPI/127"
     obj = ElasticAPI()
     obj.id = 127
     response_body = {
         "status": "deleted!"
     }
     httpretty.register_uri(httpretty.DELETE, url,
                            body=dumps(response_body),
                            content_type="application/json")
     ElasticAPI.elastic_delete(obj)
     self.assertEqual(httpretty.last_request().method, "DELETE")
コード例 #4
0
ファイル: api.py プロジェクト: EMSL-MSC/pacifica-metadata
 def test_elastic_mapping(self):
     """
     Test the elastic_mapping class method
     """
     url = "http://127.0.0.1:9200/pacifica/_mapping/ElasticAPI"
     obj = ElasticAPI()
     obj.id = 127
     response_body = {
         "status": "mapped!"
     }
     httpretty.register_uri(httpretty.PUT, url,
                            body=dumps(response_body),
                            content_type="application/json")
     ElasticAPI.create_elastic_mapping()
     self.assertEqual(httpretty.last_request().method, "PUT")
コード例 #5
0
ファイル: api.py プロジェクト: EMSL-MSC/pacifica-metadata
 def test_failed_delete(self):
     """
     Test the delete class method failed upload
     """
     url = "http://127.0.0.1:9200/pacifica/ElasticAPI/127"
     obj = ElasticAPI()
     obj.id = 127
     response_body = {
         "status": "error!"
     }
     httpretty.register_uri(httpretty.DELETE, url,
                            body=dumps(response_body),
                            content_type="application/json",
                            status=500)
     #pylint: disable=broad-except
     try:
         ElasticAPI.elastic_delete(obj)
     except Exception, ex:
         self.assertEqual(httpretty.last_request().method, "DELETE")
         self.assertEqual(str(ex), "elastic_delete_obj: 500\n")
コード例 #6
0
ファイル: api.py プロジェクト: EMSL-MSC/pacifica-metadata
 def test_failed_elastic_mapping(self):
     """
     Test the elastic mapping class method failed upload
     """
     url = "http://127.0.0.1:9200/pacifica/_mapping/ElasticAPI"
     obj = ElasticAPI()
     obj.id = 127
     response_body = {
         "status": "error!"
     }
     httpretty.register_uri(httpretty.PUT, url,
                            body=dumps(response_body),
                            content_type="application/json",
                            status=500)
     #pylint: disable=broad-except
     try:
         ElasticAPI.create_elastic_mapping()
     except Exception, ex:
         self.assertEqual(httpretty.last_request().method, "PUT")
         self.assertEqual(str(ex), "create_elastic_mapping: 500\n")