@@ -679,7 +679,37 @@ def test_invalid_type(
679679 )
680680
681681
682- @pytest .mark .usefixtures ('verify_mock_vuforia' )
682+ @pytest .fixture ()
683+ def add_targets (
684+ high_quality_image : io .BytesIO ,
685+ vuforia_database_keys : VuforiaDatabaseKeys ,
686+ ) -> None :
687+ """
688+ Add two targets with the "high_quality_image" fixture contents.
689+ """
690+ image_content = high_quality_image .getvalue ()
691+ image_data_encoded = base64 .b64encode (image_content ).decode ('ascii' )
692+ for name in ('example_1' , 'example_2' ):
693+ add_target_data = {
694+ 'name' : name ,
695+ 'width' : 1 ,
696+ 'image' : image_data_encoded ,
697+ }
698+
699+ response = add_target_to_vws (
700+ vuforia_database_keys = vuforia_database_keys ,
701+ data = add_target_data ,
702+ )
703+
704+ target_id = response .json ()['target_id' ]
705+
706+ wait_for_target_processed (
707+ target_id = target_id ,
708+ vuforia_database_keys = vuforia_database_keys ,
709+ )
710+
711+
712+ @pytest .mark .usefixtures ('verify_mock_vuforia' , 'add_targets' )
683713class TestIncludeTargetData :
684714 """
685715 Tests for the ``include_target_data`` parameter.
@@ -694,26 +724,6 @@ def test_default(
694724 The default ``include_target_data`` is 'top'.
695725 """
696726 image_content = high_quality_image .getvalue ()
697- image_data_encoded = base64 .b64encode (image_content ).decode ('ascii' )
698- for name in ('example_1' , 'example_2' ):
699- add_target_data = {
700- 'name' : name ,
701- 'width' : 1 ,
702- 'image' : image_data_encoded ,
703- }
704-
705- response = add_target_to_vws (
706- vuforia_database_keys = vuforia_database_keys ,
707- data = add_target_data ,
708- )
709-
710- target_id = response .json ()['target_id' ]
711-
712- wait_for_target_processed (
713- target_id = target_id ,
714- vuforia_database_keys = vuforia_database_keys ,
715- )
716-
717727 body = {
718728 'image' : ('image.jpeg' , image_content , 'image/jpeg' ),
719729 'max_num_results' : (None , 2 , 'text/plain' ),
@@ -741,26 +751,6 @@ def test_top(
741751 the first result includes target data.
742752 """
743753 image_content = high_quality_image .getvalue ()
744- image_data_encoded = base64 .b64encode (image_content ).decode ('ascii' )
745- for name in ('example_1' , 'example_2' ):
746- add_target_data = {
747- 'name' : name ,
748- 'width' : 1 ,
749- 'image' : image_data_encoded ,
750- }
751-
752- response = add_target_to_vws (
753- vuforia_database_keys = vuforia_database_keys ,
754- data = add_target_data ,
755- )
756-
757- target_id = response .json ()['target_id' ]
758-
759- wait_for_target_processed (
760- target_id = target_id ,
761- vuforia_database_keys = vuforia_database_keys ,
762- )
763-
764754 body = {
765755 'image' : ('image.jpeg' , image_content , 'image/jpeg' ),
766756 'include_target_data' : (None , include_target_data , 'text/plain' ),
@@ -789,35 +779,21 @@ def test_none(
789779 results include target data.
790780 """
791781 image_content = high_quality_image .getvalue ()
792- image_data_encoded = base64 .b64encode (image_content ).decode ('ascii' )
793- add_target_data = {
794- 'name' : 'example' ,
795- 'width' : 1 ,
796- 'image' : image_data_encoded ,
797- }
798- response = add_target_to_vws (
799- vuforia_database_keys = vuforia_database_keys ,
800- data = add_target_data ,
801- )
802-
803- target_id = response .json ()['target_id' ]
804-
805- wait_for_target_processed (
806- target_id = target_id ,
807- vuforia_database_keys = vuforia_database_keys ,
808- )
809782 body = {
810783 'image' : ('image.jpeg' , image_content , 'image/jpeg' ),
811784 'include_target_data' : (None , include_target_data , 'text/plain' ),
785+ 'max_num_results' : (None , 2 , 'text/plain' ),
812786 }
787+
813788 response = query (
814789 vuforia_database_keys = vuforia_database_keys ,
815790 body = body ,
816791 )
817792
818793 assert_query_success (response = response )
819- [result ] = response .json ()['results' ]
820- assert 'target_data' not in result
794+ result_1 , result_2 = response .json ()['results' ]
795+ assert 'target_data' not in result_1
796+ assert 'target_data' not in result_2
821797
822798 @pytest .mark .parametrize ('include_target_data' , ['all' , 'ALL' ])
823799 def test_all (
@@ -831,26 +807,6 @@ def test_all(
831807 results include target data.
832808 """
833809 image_content = high_quality_image .getvalue ()
834- image_data_encoded = base64 .b64encode (image_content ).decode ('ascii' )
835- for name in ('example_1' , 'example_2' ):
836- add_target_data = {
837- 'name' : name ,
838- 'width' : 1 ,
839- 'image' : image_data_encoded ,
840- }
841-
842- response = add_target_to_vws (
843- vuforia_database_keys = vuforia_database_keys ,
844- data = add_target_data ,
845- )
846-
847- target_id = response .json ()['target_id' ]
848-
849- wait_for_target_processed (
850- target_id = target_id ,
851- vuforia_database_keys = vuforia_database_keys ,
852- )
853-
854810 body = {
855811 'image' : ('image.jpeg' , image_content , 'image/jpeg' ),
856812 'include_target_data' : (None , include_target_data , 'text/plain' ),
0 commit comments