@@ -635,6 +635,36 @@ def post(url, data, headers, files, allow_redirects, auth=None):
635635
636636 Configuration .read ().remoteckan ().session = MockSession ()
637637
638+ @pytest .fixture (scope = "function" )
639+ def post_broken (self ):
640+ class MockSession :
641+ @staticmethod
642+ def post (url , data , headers , files , allow_redirects , auth = None ):
643+ if isinstance (data , dict ):
644+ datadict = {
645+ k .decode ("utf8" ): v .decode ("utf8" )
646+ for k , v in data .items ()
647+ }
648+ else :
649+ datadict = json .loads (data .decode ("utf-8" ))
650+ if "show" in url :
651+ return mockshow (url , datadict )
652+ if "broken" not in url :
653+ return MockResponse (
654+ 404 ,
655+ '{"success": false, "error": {"message": "TEST ERROR: Not mark broken", "__type": "TEST ERROR: Not Create Error"}, "help": "http://test-data.humdata.org/api/3/action/help_show?name=hdx_mark_broken_link_in_resource"}' ,
656+ )
657+ resultdictcopy = copy .deepcopy (resultdict )
658+ resultdictcopy ["broken_link" ] = True
659+ result = json .dumps (resultdictcopy )
660+ return MockResponse (
661+ 200 ,
662+ '{"success": true, "result": %s, "help": "http://test-data.humdata.org/api/3/action/help_show?name=hdx_mark_broken_link_in_resource"}'
663+ % result ,
664+ )
665+
666+ Configuration .read ().remoteckan ().session = MockSession ()
667+
638668 def test_read_from_hdx (self , configuration , read ):
639669 resource = Resource .read_from_hdx (
640670 "74b74ae1-df0c-4716-829f-4f939a046811"
@@ -965,3 +995,13 @@ def test_resource_views(self, configuration, post_resourceview):
965995 resource .reorder_resource_views (
966996 [resource_view_list [1 ], resource_view ]
967997 )
998+
999+ def test_mark_broken (self , configuration , post_broken ):
1000+ resource = Resource .read_from_hdx (
1001+ "74b74ae1-df0c-4716-829f-4f939a046811"
1002+ )
1003+ assert resource ["id" ] == "de6549d8-268b-4dfe-adaf-a4ae5c8510d5"
1004+ assert resource ["name" ] == "MyResource1"
1005+ assert resource ["package_id" ] == "6f36a41c-f126-4b18-aaaf-6c2ddfbc5d4d"
1006+ resource .mark_broken ()
1007+ assert resource ["broken_link" ] is True
0 commit comments