@@ -508,7 +508,7 @@ class M(SetMixin, FakeManager):
508508
509509
510510@responses .activate
511- def test_upload_mixin (gl ):
511+ def test_upload_mixin_with_filepath_and_filedata (gl ):
512512 class TestClass (UploadMixin , FakeObject ):
513513 _upload_path = "/tests/{id}/uploads"
514514
@@ -523,26 +523,76 @@ class TestClass(UploadMixin, FakeObject):
523523
524524 mgr = FakeManager (gl )
525525 obj = TestClass (mgr , {"id" : 42 })
526-
527526 with pytest .raises (
528527 GitlabUploadError , match = "File contents and file path specified"
529528 ):
530529 obj .upload ("test.txt" , "testing contents" , "/home/test.txt" )
531530
531+
532+ @responses .activate
533+ def test_upload_mixin_without_filepath_nor_filedata (gl ):
534+ class TestClass (UploadMixin , FakeObject ):
535+ _upload_path = "/tests/{id}/uploads"
536+
537+ url = "http://localhost/api/v4/tests/42/uploads"
538+ responses .add (
539+ method = responses .POST ,
540+ url = url ,
541+ json = {"id" : 42 , "file_name" : "test.txt" , "file_content" : "testing contents" },
542+ status = 200 ,
543+ match = [responses .matchers .query_param_matcher ({})],
544+ )
545+
546+ mgr = FakeManager (gl )
547+ obj = TestClass (mgr , {"id" : 42 })
532548 with pytest .raises (GitlabUploadError , match = "No file contents or path specified" ):
533549 obj .upload ("test.txt" )
534550
551+
552+ @responses .activate
553+ def test_upload_mixin_with_filedata (gl ):
554+ class TestClass (UploadMixin , FakeObject ):
555+ _upload_path = "/tests/{id}/uploads"
556+
557+ url = "http://localhost/api/v4/tests/42/uploads"
558+ responses .add (
559+ method = responses .POST ,
560+ url = url ,
561+ json = {"id" : 42 , "file_name" : "test.txt" , "file_content" : "testing contents" },
562+ status = 200 ,
563+ match = [responses .matchers .query_param_matcher ({})],
564+ )
565+
566+ mgr = FakeManager (gl )
567+ obj = TestClass (mgr , {"id" : 42 })
535568 res_only_data = obj .upload ("test.txt" , "testing contents" )
536569 assert obj ._get_upload_path () == "/tests/42/uploads"
537570 assert isinstance (res_only_data , dict )
538571 assert res_only_data ["file_name" ] == "test.txt"
539572 assert res_only_data ["file_content" ] == "testing contents"
540573 assert responses .assert_call_count (url , 1 ) is True
541574
575+
576+ @responses .activate
577+ def test_upload_mixin_with_filepath (gl ):
578+ class TestClass (UploadMixin , FakeObject ):
579+ _upload_path = "/tests/{id}/uploads"
580+
581+ url = "http://localhost/api/v4/tests/42/uploads"
582+ responses .add (
583+ method = responses .POST ,
584+ url = url ,
585+ json = {"id" : 42 , "file_name" : "test.txt" , "file_content" : "testing contents" },
586+ status = 200 ,
587+ match = [responses .matchers .query_param_matcher ({})],
588+ )
589+
590+ mgr = FakeManager (gl )
591+ obj = TestClass (mgr , {"id" : 42 })
542592 with patch ("builtins.open" , mock_open (read_data = "raw\n file\n data" )):
543593 res_only_path = obj .upload ("test.txt" , None , "/filepath" )
544594 assert obj ._get_upload_path () == "/tests/42/uploads"
545595 assert isinstance (res_only_path , dict )
546596 assert res_only_path ["file_name" ] == "test.txt"
547597 assert res_only_path ["file_content" ] == "testing contents"
548- assert responses .assert_call_count (url , 2 ) is True
598+ assert responses .assert_call_count (url , 1 ) is True
0 commit comments