@@ -768,6 +768,60 @@ def test_get_users_of_project(self):
768768
769769 lib .get_users_of_project ("123" )
770770
771+ @responses .activate
772+ def test_duplicate_project (self ):
773+ lib = self .get_logged_in_lib ()
774+ responses .add (
775+ responses .POST ,
776+ url = self .MYURL + "resource/api/projects/duplicate/007" ,
777+ json = {
778+ # server returns complete project, here we only mock a part of it
779+ 'name' : 'ExistingProduct' ,
780+ 'version' : '42' ,
781+ 'clearingState' : 'OPEN' ,
782+ '_links' : {
783+ 'self' : {
784+ 'href' : self .MYURL + 'resource/api/projects/0206'
785+ }
786+ },
787+ },
788+ match = [
789+ responses .json_params_matcher ({
790+ "version" : "42" ,
791+ 'clearingState' : 'OPEN' ,
792+ })
793+ ]
794+ )
795+ result = lib .duplicate_project ("007" , "42" )
796+ self .assertIsNotNone (result )
797+ self .assertTrue ("clearingState" in result )
798+ self .assertEqual ("OPEN" , result ["clearingState" ])
799+ self .assertTrue ("version" in result )
800+ self .assertEqual ("42" , result ["version" ])
801+
802+ @responses .activate
803+ def test_duplicate_project_no_id (self ):
804+ lib = self .get_logged_in_lib ()
805+
806+ with self .assertRaises (SW360Error ) as context :
807+ lib .duplicate_project (None , "42" )
808+
809+ self .assertEqual ("No project id provided!" , context .exception .message )
810+
811+ @responses .activate
812+ def test_duplicate_project_failed (self ):
813+ lib = self .get_logged_in_lib ()
814+
815+ responses .add (
816+ responses .POST ,
817+ url = self .MYURL + "resource/api/projects/duplicate/123" ,
818+ body = "4" ,
819+ status = 404 ,
820+ )
821+
822+ with self .assertRaises (SW360Error ) as context :
823+ lib .duplicate_project ("123" , "42" )
824+
771825
772826if __name__ == "__main__" :
773827 unittest .main ()
0 commit comments