Ejemplo n.º 1
0
 def test_client_delete_notfound(self):
     """Test the client response to an unknown error."""
     endpoint_url = 'http://127.0.0.1:8080'
     class_type = 'users'
     params = {
         '_id': 127
     }
     httpretty.register_uri(httpretty.DELETE, '{0}/{1}'.format(endpoint_url, class_type), status=404)
     client = PMClient(endpoint_url)
     response = client.delete(class_type, params)
     self.assertTrue(response)
Ejemplo n.º 2
0
 def test_client_delete(self):
     """
     Test the client response to an unknown error
     """
     endpoint_url = "http://127.0.0.1:8080"
     class_type = "users"
     params = {
         "_id": 127
     }
     httpretty.register_uri(httpretty.DELETE, "%s/%s"%(endpoint_url, class_type))
     client = PMClient(endpoint_url)
     response = client.delete(class_type, params)
     self.assertTrue(response)
Ejemplo n.º 3
0
 def test_client_get_unknown_error(self):
     """Test the client response to an unknown error."""
     endpoint_url = 'http://127.0.0.1:8080'
     class_type = 'users'
     params = {
         '_id': 127
     }
     httpretty.register_uri(httpretty.GET, '{0}/{1}'.format(endpoint_url, class_type),
                            body='This is the error.',
                            status=301)
     client = PMClient(endpoint_url)
     try:
         client.get(class_type, params)
     except PMClientError as ex:
         self.assertEqual(str(ex), 'Unknown Error (301) This is the error.')
Ejemplo n.º 4
0
 def test_client_get_not_found(self):
     """Test response from the client when the object is not found."""
     endpoint_url = 'http://127.0.0.1:8080'
     class_type = 'users'
     params = {
         '_id': 127
     }
     response_body = {}
     httpretty.register_uri(httpretty.GET, '{0}/{1}'.format(endpoint_url, class_type),
                            body=dumps(response_body),
                            content_type='application/json',
                            status=404)
     client = PMClient(endpoint_url)
     response = client.get(class_type, params)
     self.assertEqual(response, {})
Ejemplo n.º 5
0
 def test_client_delete_server_error(self):
     """Test the client response to an unknown error."""
     endpoint_url = 'http://127.0.0.1:8080'
     class_type = 'users'
     params = {
         '_id': 127
     }
     httpretty.register_uri(httpretty.DELETE, '{0}/{1}'.format(endpoint_url, class_type),
                            body='This is the error.',
                            status=501)
     client = PMClient(endpoint_url)
     try:
         client.delete(class_type, params)
     except PMClientError as ex:
         self.assertEqual(str(ex), 'Internal Server Error (501) This is the error.')
Ejemplo n.º 6
0
 def test_client_update(self):
     """Test the client response to an unknown error."""
     endpoint_url = 'http://127.0.0.1:8080'
     class_type = 'users'
     params = {
         '_id': 127
     }
     response_body = {
         '_id': 127,
         'last_name': 'Doe',
         'first_name': 'John',
         'network_id': 'johndoe'
     }
     httpretty.register_uri(httpretty.POST, '{0}/{1}'.format(endpoint_url, class_type))
     client = PMClient(endpoint_url)
     response = client.update(class_type, params, response_body)
     self.assertTrue(response)
Ejemplo n.º 7
0
 def test_client_create(self):
     """Test the client response to an unknown error."""
     endpoint_url = 'http://127.0.0.1:8080'
     class_type = 'users'
     response_body = {
         '_id': 127,
         'last_name': 'Doe',
         'first_name': 'John',
         'network_id': 'johndoe'
     }
     httpretty.register_uri(httpretty.PUT, '{0}/{1}'.format(endpoint_url, class_type))
     client = PMClient(endpoint_url)
     response = client.create(class_type, response_body)
     self.assertTrue(response)
     chk_body = loads(httpretty.last_request().body)
     for key, value in response_body.items():
         self.assertEqual(chk_body[key], value)
Ejemplo n.º 8
0
def main():
    """Main method for loading the test data."""
    mdclient = PMClient(getenv('METADATA_URL', 'http://127.0.0.1:8121'))
    test_data_dir = dirname(realpath(__file__))
    object_order = [
        'analytical_tools', 'journals', 'citations', 'institutions', 'users',
        'contributors', 'proposals', 'instruments', 'transactions', 'files',
        'groups', 'keys', 'keywords', 'values', 'atool_transaction',
        'atool_proposal', 'citation_contributor', 'citation_keyword',
        'citation_proposal', 'file_key_value', 'institution_person',
        'instrument_custodian', 'instrument_group', 'proposal_instrument',
        'proposal_participant', 'trans_key_value', 'user_group'
    ]
    for obj in object_order:
        mdclient.create(
            obj,
            loads(open('{0}.json'.format(join(test_data_dir, obj))).read()))
Ejemplo n.º 9
0
 def test_client_get_not_found(self):
     """
     Test response from the client when the object is not found
     """
     endpoint_url = "http://127.0.0.1:8080"
     class_type = "users"
     params = {
         "_id": 127
     }
     response_body = {}
     httpretty.register_uri(httpretty.GET, "%s/%s"%(endpoint_url, class_type),
                            body=dumps(response_body),
                            content_type="application/json",
                            status=404)
     client = PMClient(endpoint_url)
     response = client.get(class_type, params)
     self.assertEqual(response, {})
Ejemplo n.º 10
0
 def test_client_delete_server_error(self):
     """
     Test the client response to an unknown error
     """
     endpoint_url = "http://127.0.0.1:8080"
     class_type = "users"
     params = {
         "_id": 127
     }
     httpretty.register_uri(httpretty.DELETE, "%s/%s"%(endpoint_url, class_type),
                            body="This is the error.",
                            status=501)
     client = PMClient(endpoint_url)
     try:
         client.delete(class_type, params)
     except PMClientError, ex:
         self.assertEqual(str(ex), "Internal Server Error (501) This is the error.")
Ejemplo n.º 11
0
 def test_client_get_unknown_error(self):
     """
     Test the client response to an unknown error
     """
     endpoint_url = "http://127.0.0.1:8080"
     class_type = "users"
     params = {
         "_id": 127
     }
     httpretty.register_uri(httpretty.GET, "%s/%s"%(endpoint_url, class_type),
                            body="This is the error.",
                            status=301)
     client = PMClient(endpoint_url)
     try:
         client.get(class_type, params)
     except PMClientError, ex:
         self.assertEqual(str(ex), "Unknown Error (301) This is the error.")
Ejemplo n.º 12
0
 def test_client_create_unk_error(self):
     """Test the client response to an unknown error."""
     endpoint_url = 'http://127.0.0.1:8080'
     class_type = 'users'
     response_body = {
         '_id': 127,
         'last_name': 'Doe',
         'first_name': 'John',
         'network_id': 'johndoe'
     }
     httpretty.register_uri(httpretty.PUT, '{0}/{1}'.format(endpoint_url, class_type),
                            body='This is the error.',
                            status=301)
     client = PMClient(endpoint_url)
     try:
         client.create(class_type, response_body)
     except PMClientError as ex:
         self.assertEqual(str(ex), 'Unknown Error (301) This is the error.')
Ejemplo n.º 13
0
 def test_client_create(self):
     """
     Test the client response to an unknown error
     """
     endpoint_url = "http://127.0.0.1:8080"
     class_type = "users"
     response_body = {
         "_id": 127,
         "last_name": "Doe",
         "first_name": "John",
         "network_id": "johndoe"
     }
     httpretty.register_uri(httpretty.PUT, "%s/%s"%(endpoint_url, class_type))
     client = PMClient(endpoint_url)
     response = client.create(class_type, response_body)
     self.assertTrue(response)
     chk_body = loads(httpretty.last_request().body)
     for key, value in response_body.iteritems():
         self.assertEqual(chk_body[key], value)
Ejemplo n.º 14
0
 def test_client_update(self):
     """
     Test the client response to an unknown error
     """
     endpoint_url = "http://127.0.0.1:8080"
     class_type = "users"
     params = {
         "_id": 127
     }
     response_body = {
         "_id": 127,
         "last_name": "Doe",
         "first_name": "John",
         "network_id": "johndoe"
     }
     httpretty.register_uri(httpretty.POST, "%s/%s"%(endpoint_url, class_type))
     client = PMClient(endpoint_url)
     response = client.update(class_type, params, response_body)
     self.assertTrue(response)
Ejemplo n.º 15
0
 def test_client_create_unk_error(self):
     """
     Test the client response to an unknown error
     """
     endpoint_url = "http://127.0.0.1:8080"
     class_type = "users"
     response_body = {
         "_id": 127,
         "last_name": "Doe",
         "first_name": "John",
         "network_id": "johndoe"
     }
     httpretty.register_uri(httpretty.PUT, "%s/%s"%(endpoint_url, class_type),
                            body="This is the error.",
                            status=301)
     client = PMClient(endpoint_url)
     try:
         client.create(class_type, response_body)
     except PMClientError, ex:
         self.assertEqual(str(ex), "Unknown Error (301) This is the error.")
Ejemplo n.º 16
0
 def test_client_get(self):
     """Test the client get methods."""
     endpoint_url = 'http://127.0.0.1:8080'
     class_type = 'users'
     params = {
         '_id': 127
     }
     response_body = {
         '_id': 127,
         'last_name': 'Doe',
         'first_name': 'John',
         'network_id': 'johndoe'
     }
     httpretty.register_uri(httpretty.GET, '{0}/{1}'.format(endpoint_url, class_type),
                            body=dumps(response_body),
                            content_type='application/json')
     client = PMClient(endpoint_url)
     response = client.get(class_type, params)
     self.assertNotEqual(response, {})
     for key in response.keys():
         self.assertEqual(response[key], response_body[key])
Ejemplo n.º 17
0
 def test_client_update_not_found(self):
     """Test the client response to not finding things."""
     endpoint_url = 'http://127.0.0.1:8080'
     class_type = 'users'
     params = {
         '_id': 127
     }
     response_body = {}
     post_body = {
         '_id': 127,
         'last_name': 'Doe',
         'first_name': 'John',
         'network_id': 'johndoe'
     }
     httpretty.register_uri(httpretty.POST, '{0}/{1}'.format(endpoint_url, class_type),
                            body=dumps(response_body),
                            content_type='application/json',
                            status=404)
     client = PMClient(endpoint_url)
     response = client.update(class_type, params, post_body)
     self.assertFalse(response)
Ejemplo n.º 18
0
 def test_client_update_server_error(self):
     """Test the client response to not finding things."""
     endpoint_url = 'http://127.0.0.1:8080'
     class_type = 'users'
     params = {
         '_id': 127
     }
     post_body = {
         '_id': 127,
         'last_name': 'Doe',
         'first_name': 'John',
         'network_id': 'johndoe'
     }
     httpretty.register_uri(httpretty.POST, '{0}/{1}'.format(endpoint_url, class_type),
                            body='This is the error.',
                            status=501)
     client = PMClient(endpoint_url)
     try:
         client.update(class_type, params, post_body)
     except PMClientError as ex:
         self.assertEqual(str(ex), 'Internal Server Error (501) This is the error.')
Ejemplo n.º 19
0
 def test_client_update_server_error(self):
     """
     Test the client response to not finding things
     """
     endpoint_url = "http://127.0.0.1:8080"
     class_type = "users"
     params = {
         "_id": 127
     }
     post_body = {
         "_id": 127,
         "last_name": "Doe",
         "first_name": "John",
         "network_id": "johndoe"
     }
     httpretty.register_uri(httpretty.POST, "%s/%s"%(endpoint_url, class_type),
                            body="This is the error.",
                            status=501)
     client = PMClient(endpoint_url)
     try:
         client.update(class_type, params, post_body)
     except PMClientError, ex:
         self.assertEqual(str(ex), "Internal Server Error (501) This is the error.")
Ejemplo n.º 20
0
 def test_client_update_not_found(self):
     """
     Test the client response to not finding things
     """
     endpoint_url = "http://127.0.0.1:8080"
     class_type = "users"
     params = {
         "_id": 127
     }
     response_body = {}
     post_body = {
         "_id": 127,
         "last_name": "Doe",
         "first_name": "John",
         "network_id": "johndoe"
     }
     httpretty.register_uri(httpretty.POST, "%s/%s"%(endpoint_url, class_type),
                            body=dumps(response_body),
                            content_type="application/json",
                            status=404)
     client = PMClient(endpoint_url)
     response = client.update(class_type, params, post_body)
     self.assertFalse(response)
Ejemplo n.º 21
0
 def test_client_get(self):
     """
     Test the client get methods
     """
     endpoint_url = "http://127.0.0.1:8080"
     class_type = "users"
     params = {
         "_id": 127
     }
     response_body = {
         "_id": 127,
         "last_name": "Doe",
         "first_name": "John",
         "network_id": "johndoe"
     }
     httpretty.register_uri(httpretty.GET, "%s/%s"%(endpoint_url, class_type),
                            body=dumps(response_body),
                            content_type="application/json")
     client = PMClient(endpoint_url)
     response = client.get(class_type, params)
     self.assertNotEqual(response, {})
     for key in response.keys():
         self.assertEqual(response[key], response_body[key])