@@ -758,24 +758,57 @@ def test_time_limit_validation_on_invocation_post_serializer(settings):
758758
759759
760760@pytest .mark .django_db
761- def test_invocation_post_serializer_create (request ):
762- endpoint = EndpointFactory (status = Endpoint .StatusChoices .RUNNING )
763- request .user = endpoint .creator
764- socket = ComponentInterfaceFactory (kind = ComponentInterface .Kind .STRING )
765- interface = AlgorithmInterfaceFactory (inputs = [socket ])
761+ def test_invocation_post_serializer_create (
762+ request , settings , django_capture_on_commit_callbacks
763+ ):
764+ settings .CELERY_TASK_ALWAYS_EAGER = True
765+ settings .CELERY_TASK_EAGER_PROPAGATES = True
766+
767+ user = UserFactory ()
768+ request .user = user
769+ endpoint = EndpointFactory .create (
770+ creator = user ,
771+ status = Endpoint .StatusChoices .RUNNING ,
772+ )
773+ ci_string = ComponentInterfaceFactory .create (
774+ kind = ComponentInterface .Kind .STRING
775+ )
776+ ci_img1 , ci_img2 = ComponentInterfaceFactory .create_batch (
777+ 2 , kind = ComponentInterface .Kind .PANIMG_IMAGE
778+ )
779+ interface = AlgorithmInterfaceFactory (inputs = [ci_string , ci_img2 , ci_img1 ])
766780 endpoint .algorithm_image .algorithm .interfaces .add (interface )
781+ upload = RawImageUploadSessionFactory (creator = user )
782+ image1 , image2 = ImageFactory .create_batch (2 )
783+ for im in [image1 , image2 ]:
784+ assign_perm ("view_image" , user , im )
785+ upload .image_set .set ([image1 ])
767786
768787 serializer = InvocationPostSerializer (
769788 data = {
770789 "endpoint" : endpoint .api_url ,
771- "inputs" : [{"interface" : socket .slug , "value" : "dummy" }],
790+ "inputs" : [
791+ {"interface" : ci_string .slug , "value" : "foo" },
792+ {"interface" : ci_img1 .slug , "upload_session" : upload .api_url },
793+ {"interface" : ci_img2 .slug , "image" : image2 .api_url },
794+ ],
772795 },
773796 context = {"request" : request },
774797 )
775798
776- assert serializer .is_valid ()
777- serializer .create (serializer .validated_data )
799+ assert serializer .is_valid (), serializer .errors
800+
801+ # fake successful upload
802+ upload .status = RawImageUploadSession .SUCCESS
803+ upload .save ()
804+
805+ with django_capture_on_commit_callbacks (execute = True ):
806+ serializer .create (serializer .validated_data )
807+
808+ assert Invocation .objects .count () == 1
778809
779810 invocation = Invocation .objects .get ()
780811
781812 assert invocation .endpoint == endpoint
813+ assert invocation .algorithm_interface == interface
814+ assert invocation .inputs .count () == 3
0 commit comments