1414 SherlockImportPartsListError ,
1515 SherlockUpdatePartsFromAVLError ,
1616 SherlockUpdatePartsListError ,
17+ SherlockUpdatePartsListPropertiesError ,
1718 SherlockUpdatePartsLocationsByFileError ,
1819 SherlockUpdatePartsLocationsError ,
1920)
@@ -34,6 +35,8 @@ def test_all():
3435
3536 helper_test_update_parts_list (parts )
3637 time .sleep (1 )
38+ helper_test_update_parts_list_properties (parts )
39+ time .sleep (1 )
3740 helper_test_update_parts_from_AVL (parts )
3841 helper_test_update_parts_locations (parts )
3942 helper_test_update_parts_locations_by_file (parts )
@@ -672,5 +675,160 @@ def helper_test_get_part_location(parts):
672675 assert str (e ) == "Get part location error: Location unit is invalid."
673676
674677
678+ def helper_test_update_parts_list_properties (parts ):
679+ """Test update_parts_list_properties API"""
680+ try :
681+ parts .update_parts_list_properties (
682+ "" ,
683+ "CCA_Name" ,
684+ [
685+ {
686+ "reference_designators" : ["C1" ],
687+ "properties" : [{"name" : "partType" , "value" : "RESISTOR" }],
688+ }
689+ ],
690+ )
691+ pytest .fail ("No exception raised when using an invalid parameter" )
692+ except SherlockUpdatePartsListPropertiesError as e :
693+ assert str (e .str_itr ()) == (
694+ "['Update parts list properties error: Project name is invalid.']"
695+ )
696+
697+ try :
698+ parts .update_parts_list_properties (
699+ "Test" ,
700+ "" ,
701+ [
702+ {
703+ "reference_designators" : ["C1" ],
704+ "properties" : [{"name" : "partType" , "value" : "RESISTOR" }],
705+ }
706+ ],
707+ )
708+ pytest .fail ("No exception raised when using an invalid parameter" )
709+ except SherlockUpdatePartsListPropertiesError as e :
710+ assert str (e .str_itr ()) == "['Update parts list properties error: CCA name is invalid.']"
711+
712+ try :
713+ parts .update_parts_list_properties ("Test" , "CCA_Name" , [])
714+ pytest .fail ("No exception raised when using an invalid parameter" )
715+ except SherlockUpdatePartsListPropertiesError as e :
716+ assert str (e .str_itr ()) == (
717+ "['Update parts list properties error: Part properties are missing.']"
718+ )
719+
720+ try :
721+ parts .update_parts_list_properties (
722+ "Test" ,
723+ "CCA_name" ,
724+ [
725+ {
726+ "reference_designators" : ["C1" ],
727+ "properties" : [{"name" : "partType" , "value" : "RESISTOR" }],
728+ "test" : "test" ,
729+ }
730+ ],
731+ )
732+ pytest .fail ("No exception raised when using an invalid parameter" )
733+ except SherlockUpdatePartsListPropertiesError as e :
734+ assert str (e .str_itr ()) == (
735+ "['Update parts list properties error: Number of elements (3) "
736+ "is wrong for part list property 0.']"
737+ )
738+
739+ try :
740+ parts .update_parts_list_properties (
741+ "Test" ,
742+ "CCA_name" ,
743+ [
744+ {
745+ "reference_designators" : "C1" ,
746+ "properties" : [{"name" : "partType" , "value" : "RESISTOR" }],
747+ }
748+ ],
749+ )
750+ pytest .fail ("No exception raised when using an invalid parameter" )
751+ except SherlockUpdatePartsListPropertiesError as e :
752+ assert str (e .str_itr ()) == (
753+ "['Update parts list properties error: reference_designators is not a list "
754+ "for parts list property 0.']"
755+ )
756+
757+ try :
758+ parts .update_parts_list_properties (
759+ "Test" ,
760+ "CCA_name" ,
761+ [
762+ {
763+ "reference_designators" : ["C1" ],
764+ "properties" : [{"name" : "partType" , "value" : "RESISTOR" , "test" : "test" }],
765+ }
766+ ],
767+ )
768+ pytest .fail ("No exception raised when using an invalid parameter" )
769+ except SherlockUpdatePartsListPropertiesError as e :
770+ assert str (e .str_itr ()) == (
771+ "['Update parts list properties error: Number of elements (3) "
772+ "is wrong for property 0.']"
773+ )
774+
775+ try :
776+ parts .update_parts_list_properties (
777+ "Test" ,
778+ "CCA_name" ,
779+ [{"reference_designators" : ["C1" ], "properties" : [{"name" : "" , "value" : "RESISTOR" }]}],
780+ )
781+ pytest .fail ("No exception raised when using an invalid parameter" )
782+ except SherlockUpdatePartsListPropertiesError as e :
783+ assert str (e .str_itr ()) == (
784+ "['Update parts list properties error: Name is required for property 0.']"
785+ )
786+
787+ try :
788+ parts .update_parts_list_properties (
789+ "Test" ,
790+ "CCA_name" ,
791+ [{"reference_designators" : ["C1" ], "properties" : [{"name" : "partType" , "value" : 0 }]}],
792+ )
793+ pytest .fail ("No exception raised when using an invalid parameter" )
794+ except SherlockUpdatePartsListPropertiesError as e :
795+ assert str (e .str_itr ()) == ("['Update parts list properties error: Value is invalid.']" )
796+
797+ if not parts ._is_connection_up ():
798+ return
799+
800+ try :
801+ parts .update_parts_list_properties (
802+ "Invalid project" ,
803+ "CCA_name" ,
804+ [
805+ {
806+ "reference_designators" : ["C1" ],
807+ "properties" : [{"name" : "partType" , "value" : "RESISTOR" }],
808+ }
809+ ],
810+ )
811+ pytest .fail ("No exception raised when using an invalid parameter" )
812+ except Exception as e :
813+ assert type (e ) == SherlockUpdatePartsListPropertiesError
814+
815+ try :
816+ result = parts .update_parts_list_properties (
817+ "Tutorial Project" ,
818+ "Main Board" ,
819+ [
820+ {
821+ "reference_designators" : ["C1" ],
822+ "properties" : [{"name" : "partType" , "value" : "RESISTOR" }],
823+ }
824+ ],
825+ )
826+
827+ assert result == 0
828+
829+ except Exception as e :
830+ pytest .fail (e .message )
831+
832+
675833if __name__ == "__main__" :
676834 test_all ()
0 commit comments