@@ -490,3 +490,112 @@ def test_all_errors(self, mocker):
490490 self .assertEqual (len (commands ), 7 )
491491 for command in commands :
492492 self .assertEqual (command .status , BatchCommand .STATUS_ERROR )
493+
494+ @requests_mock .Mocker ()
495+ def test_get_label (self , mocker ):
496+ ApiMocker .wikidata_property_data_types (mocker )
497+ ApiMocker .is_autoconfirmed (mocker )
498+ ApiMocker .create_item (mocker , "Q1" )
499+ ApiMocker .item_empty (mocker , "Q1" )
500+ ApiMocker .item_empty (mocker , "Q2" )
501+ ApiMocker .property_data_type (mocker , "P1" , "quantity" )
502+ ApiMocker .patch_item_successful (mocker , "Q1" , {})
503+ ApiMocker .patch_item_successful (mocker , "Q2" , {})
504+ batch = self .parse ("""
505+ CREATE
506+ LAST|P1|12
507+ Q2|P1|15
508+ """ )
509+ batch .combine_commands = True
510+ commands = batch .commands ()
511+ client = ApiClient .from_username (batch .user )
512+ ApiMocker .labels (mocker , client , "Q1" , {"pt" : "pt1" , "en" : "en1" })
513+ ApiMocker .labels (mocker , client , "Q2" , {"pt" : "pt2" , "en" : "en2" })
514+ self .assertEqual (commands [0 ].get_label (client , "pt" ), None )
515+ self .assertEqual (commands [1 ].get_label (client , "pt" ), None )
516+ self .assertEqual (commands [2 ].get_label (client , "pt" ), "pt2" )
517+ self .assertEqual (commands [0 ].get_label (client , "de" ), None )
518+ self .assertEqual (commands [1 ].get_label (client , "de" ), None )
519+ self .assertEqual (commands [2 ].get_label (client , "de" ), "en2" )
520+ self .assertEqual (commands [0 ].get_label (client , "en" ), None )
521+ self .assertEqual (commands [1 ].get_label (client , "en" ), None )
522+ self .assertEqual (commands [2 ].get_label (client , "en" ), "en2" )
523+ batch .run () # -> load Q1 into commands[0] and commands[1]
524+ self .assertEqual (commands [0 ].get_label (client , "pt" ), "pt1" )
525+ self .assertEqual (commands [1 ].get_label (client , "pt" ), "pt1" )
526+ self .assertEqual (commands [2 ].get_label (client , "pt" ), "pt2" )
527+ self .assertEqual (commands [0 ].get_label (client , "de" ), "en1" )
528+ self .assertEqual (commands [1 ].get_label (client , "de" ), "en1" )
529+ self .assertEqual (commands [2 ].get_label (client , "de" ), "en2" )
530+ self .assertEqual (commands [0 ].get_label (client , "en" ), "en1" )
531+ self .assertEqual (commands [1 ].get_label (client , "en" ), "en1" )
532+ self .assertEqual (commands [2 ].get_label (client , "en" ), "en2" )
533+
534+ @requests_mock .Mocker ()
535+ def test_remove_qual_or_ref_errors (self , mocker ):
536+ ApiMocker .item (
537+ mocker ,
538+ "Q1" ,
539+ {
540+ "statements" : {
541+ "P5" : [
542+ {
543+ "id" : "Q1234$abcdefgh-uijkl" ,
544+ "value" : {
545+ "type" : "value" ,
546+ "content" : "Q12" ,
547+ },
548+ "qualifiers" : [
549+ {
550+ "property" : {"id" : "P65" , "data_type" : "quantity" },
551+ "value" : {
552+ "type" : "value" ,
553+ "content" : {"amount" : "+84" , "unit" : "1" },
554+ },
555+ },
556+ ],
557+ "references" : [
558+ {
559+ "hash" : "i_am_ahash" ,
560+ "parts" : [
561+ {
562+ "property" : {"id" : "P93" , "data_type" : "url" },
563+ "value" : {
564+ "type" : "value" ,
565+ "content" : "https://kernel.org/" ,
566+ },
567+ },
568+ ],
569+ },
570+ ],
571+ },
572+ ],
573+ },
574+ },
575+ )
576+ ApiMocker .wikidata_property_data_types (mocker )
577+ ApiMocker .is_autoconfirmed (mocker )
578+ ApiMocker .property_data_type (mocker , "P5" , "wikibase-item" )
579+ ApiMocker .patch_item_successful (mocker , "Q1" , {})
580+ batch = self .parse ("""
581+ REMOVE_QUAL|Q1|P5|Q12|P123|123
582+ REMOVE_QUAL|Q1|P5|Q999|P65|84
583+ REMOVE_QUAL|Q1|P5|Q12|P65|84
584+ REMOVE_REF|Q1|P5|Q12|S93|"https://kernel.xyz"
585+ REMOVE_REF|Q1|P5|Q999|S93|"https://kernel.org/"
586+ REMOVE_REF|Q1|P5|Q12|S93|"https://kernel.org/"
587+ """ )
588+ commands = batch .commands ()
589+ batch .run ()
590+ # qualifiers
591+ self .assertEqual (commands [0 ].status , BatchCommand .STATUS_ERROR )
592+ self .assertEqual (commands [0 ].error , BatchCommand .Error .NO_QUALIIFERS )
593+ self .assertEqual (commands [1 ].status , BatchCommand .STATUS_ERROR )
594+ self .assertEqual (commands [1 ].error , BatchCommand .Error .NO_QUALIIFERS )
595+ self .assertEqual (commands [2 ].status , BatchCommand .STATUS_DONE )
596+ # references
597+ self .assertEqual (commands [3 ].status , BatchCommand .STATUS_ERROR )
598+ self .assertEqual (commands [3 ].error , BatchCommand .Error .NO_REFERENCE_PARTS )
599+ self .assertEqual (commands [4 ].status , BatchCommand .STATUS_ERROR )
600+ self .assertEqual (commands [4 ].error , BatchCommand .Error .NO_REFERENCE_PARTS )
601+ self .assertEqual (commands [5 ].status , BatchCommand .STATUS_DONE )
0 commit comments