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})
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})
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)
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)