vnf_pkg1 = VnfPackageModel.objects.filter(vnfPackageId="222")
self.assertEqual("zte-hss-1.0", vnf_pkg1[0].vnfdId)
- def test_upload_from_uri_failed(self):
+ def test_upload_from_uri_bad_req(self):
req_data = {"username": "123"}
response = self.client.post("%s/111/package_content/upload_from_uri" % VNF_BASE_URL, data=req_data)
- self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
+ self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
+
+ @mock.patch.object(urllib.request, 'urlopen')
+ def test_upload_from_uri_failed(self, mock_urlopen):
+ vnf_pkg = VnfPackageModel.objects.create(
+ vnfPackageId="333",
+ onboardingState="CREATED"
+ )
+ req_data = {"addressInformation": "error"}
+ mock_urlopen.return_value = Exception('Boom!')
+ vnf_pkg_id = vnf_pkg.vnfPackageId
+ VnfPkgUploadThread(req_data, vnf_pkg_id).run()
+ vnf_pkg1 = VnfPackageModel.objects.filter(vnfPackageId="333")
+ self.assertEqual("CREATED", vnf_pkg1[0].onboardingState)
def test_create_vnf_pkg(self):
req_data = {
from django.http import FileResponse
from drf_yasg.utils import swagger_auto_schema
+from drf_yasg import openapi
from rest_framework import status
from rest_framework.views import APIView
@swagger_auto_schema(
tags=[TAG_VNF_PACKAGE_API],
responses={
- status.HTTP_200_OK: "Return the artifact file",
- status.HTTP_404_NOT_FOUND: "Artifact not found",
- status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
+ status.HTTP_200_OK: openapi.Response("Return the artifact file",
+ schema=openapi.Schema(format=openapi.FORMAT_BINARY,
+ type=openapi.TYPE_STRING)),
+ status.HTTP_404_NOT_FOUND: openapi.Response("Artifact not found",
+ schema=openapi.Schema(type=openapi.TYPE_STRING)),
+ status.HTTP_500_INTERNAL_SERVER_ERROR: openapi.Response("Internal error",
+ schema=openapi.Schema(type=openapi.TYPE_STRING))
}
)
@view_safe_call_with_log(logger=logger)
from catalog.packages.serializers.upload_vnf_pkg_from_uri_req import UploadVnfPackageFromUriRequestSerializer
from catalog.packages.serializers.vnf_pkg_info import VnfPkgInfoSerializer
from catalog.packages.serializers.vnf_pkg_infos import VnfPkgInfosSerializer
-from .common import validate_data
+from .common import validate_data, validate_req_data
from .common import view_safe_call_with_log
logger = logging.getLogger(__name__)
request_body=no_body,
responses={
status.HTTP_200_OK: VnfPkgInfosSerializer(),
- status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
+ status.HTTP_500_INTERNAL_SERVER_ERROR: openapi.Response("Internal error",
+ openapi.Schema(type=openapi.TYPE_STRING))
}
)
@swagger_auto_schema(
request_body=CreateVnfPkgInfoRequestSerializer,
responses={
status.HTTP_201_CREATED: VnfPkgInfoSerializer(),
- status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
+ status.HTTP_400_BAD_REQUEST: openapi.Response("Bad Request", schema=openapi.Schema(type=openapi.TYPE_STRING)),
+ status.HTTP_500_INTERNAL_SERVER_ERROR: openapi.Response("Internal error",
+ schema=openapi.Schema(type=openapi.TYPE_STRING))
}
)
@api_view(http_method_names=["GET", "POST"])
if request.method == 'POST':
logger.debug("Create VNF package> %s" % request.data)
- create_vnf_pkg_info_request = validate_data(request.data,
- CreateVnfPkgInfoRequestSerializer)
+ create_vnf_pkg_info_request = validate_req_data(request.data, CreateVnfPkgInfoRequestSerializer)
data = VnfPackage().create_vnf_pkg(create_vnf_pkg_info_request.data)
validate_data(data, VnfPkgInfoSerializer)
return Response(data=data, status=status.HTTP_201_CREATED)
status.HTTP_200_OK: openapi.Response('VNFD of an on-boarded VNF package',
schema=openapi.Schema(format=openapi.FORMAT_BINARY,
type=openapi.TYPE_STRING)),
- status.HTTP_404_NOT_FOUND: "VNF package does not exist",
- status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
+ status.HTTP_404_NOT_FOUND: openapi.Response("VNF package does not exist",
+ schema=openapi.Schema(type=openapi.TYPE_STRING)),
+ status.HTTP_500_INTERNAL_SERVER_ERROR: openapi.Response("Internal error",
+ schema=openapi.Schema(type=openapi.TYPE_STRING))
},
produces='application/octet-stream',
operation_id='VNFD of an on-boarded VNF package'
request_body=no_body,
responses={
status.HTTP_202_ACCEPTED: "Successfully",
- status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
+ status.HTTP_500_INTERNAL_SERVER_ERROR: openapi.Response("Internal error",
+ schema=openapi.Schema(type=openapi.TYPE_STRING))
}
)
@swagger_auto_schema(
status.HTTP_200_OK: openapi.Response('VNF package file',
schema=openapi.Schema(format=openapi.FORMAT_BINARY,
type=openapi.TYPE_STRING)),
- status.HTTP_404_NOT_FOUND: "VNF package does not exist",
- status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
+ status.HTTP_404_NOT_FOUND: openapi.Response("VNF package does not exist",
+ schema=openapi.Schema(type=openapi.TYPE_STRING)),
+ status.HTTP_500_INTERNAL_SERVER_ERROR: openapi.Response("Internal error",
+ schema=openapi.Schema(type=openapi.TYPE_STRING))
}
)
@api_view(http_method_names=["PUT", "GET"])
request_body=UploadVnfPackageFromUriRequestSerializer,
responses={
status.HTTP_202_ACCEPTED: "Successfully",
- status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
+ status.HTTP_400_BAD_REQUEST: openapi.Response("Bad Request", schema=openapi.Schema(type=openapi.TYPE_STRING)),
+ status.HTTP_500_INTERNAL_SERVER_ERROR: openapi.Response("Internal error",
+ schema=openapi.Schema(type=openapi.TYPE_STRING))
}
)
@api_view(http_method_names=['POST'])
def upload_from_uri_c(request, **kwargs):
vnf_pkg_id = kwargs.get("vnfPkgId")
try:
- upload_vnf_from_uri_request = validate_data(request.data,
- UploadVnfPackageFromUriRequestSerializer)
+ upload_vnf_from_uri_request = validate_req_data(request.data,
+ UploadVnfPackageFromUriRequestSerializer)
VnfPkgUploadThread(upload_vnf_from_uri_request.data, vnf_pkg_id).start()
return Response(None, status=status.HTTP_202_ACCEPTED)
except Exception as e:
request_body=no_body,
responses={
status.HTTP_200_OK: VnfPkgInfoSerializer(),
- status.HTTP_404_NOT_FOUND: "VNF package does not exist",
- status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
+ status.HTTP_404_NOT_FOUND: openapi.Response("VNF package does not exist",
+ schema=openapi.Schema(type=openapi.TYPE_STRING)),
+ status.HTTP_500_INTERNAL_SERVER_ERROR: openapi.Response("Internal error",
+ schema=openapi.Schema(type=openapi.TYPE_STRING))
}
)
@swagger_auto_schema(
request_body=no_body,
responses={
status.HTTP_204_NO_CONTENT: "No content",
- status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
+ status.HTTP_500_INTERNAL_SERVER_ERROR: openapi.Response("Internal error",
+ schema=openapi.Schema(type=openapi.TYPE_STRING))
}
)
@api_view(http_method_names=['GET', 'DELETE'])