예제 #1
0
 def test_update(self):
     datastore_service = DatastoreService(self.http_client)
     ds_id = "datastore1"
     uri = "%s/%s" % (DatastoreService.PATH, ds_id)
     fields = {"id": ds_id, "name": "datastore", "type": "NFS",
               "documentSelfLink": uri}
     # Test create when the document doesn't exists
     datastore_service.update(ds_id, fields)
     selfLink = fields["documentSelfLink"]
     self.http_client.put.assert_called_once_with(selfLink,
                                                  {'data': fields})
예제 #2
0
 def test_update(self):
     datastore_service = DatastoreService(self.http_client)
     ds_id = "datastore1"
     uri = "%s/%s" % (DatastoreService.PATH, ds_id)
     fields = {
         "id": ds_id,
         "name": "datastore",
         "type": "NFS",
         "documentSelfLink": uri
     }
     # Test create when the document doesn't exists
     datastore_service.update(ds_id, fields)
     selfLink = fields["documentSelfLink"]
     self.http_client.put.assert_called_once_with(selfLink,
                                                  {'data': fields})
예제 #3
0
    def test_create(self):
        datastore_service = DatastoreService(self.http_client)
        ds_id = "datastore1"
        uri = "%s/%s" % (DatastoreService.PATH, ds_id)
        fields = {"id": ds_id, "name": "datastore", "type": "NFS",
                  "documentSelfLink": uri}
        # Test create when the document doesn't exists
        datastore_service.create(ds_id, fields)
        self.http_client.post.assert_called_once_with(DatastoreService.PATH,
                                                      {'data': fields})
        self.http_client.reset_mock()

        # Test create when the document exists
        resp = mock.MagicMock()
        resp.status = httplib.CONFLICT
        resp.reason = "document already exists"
        self.http_client.post.return_value = resp, ""
        self.assertRaises(ClientError, datastore_service.create, ds_id, fields)
예제 #4
0
    def test_create(self):
        datastore_service = DatastoreService(self.http_client)
        ds_id = "datastore1"
        uri = "%s/%s" % (DatastoreService.PATH, ds_id)
        fields = {
            "id": ds_id,
            "name": "datastore",
            "type": "NFS",
            "documentSelfLink": uri
        }
        # Test create when the document doesn't exists
        datastore_service.create(ds_id, fields)
        self.http_client.post.assert_called_once_with(DatastoreService.PATH,
                                                      {'data': fields})
        self.http_client.reset_mock()

        # Test create when the document exists
        resp = mock.MagicMock()
        resp.status = httplib.CONFLICT
        resp.reason = "document already exists"
        self.http_client.post.return_value = resp
        self.assertRaises(ClientError, datastore_service.create, ds_id, fields)