def test_handler_bad_render2(self): "article xml fails to convert truncated xml to article-json" self.valid_request['location'] = 'file://' + join(self.ingest_dir, 'bad', 'truncated.xml') adapt.handler(self.valid_request, self.out) self.assertEqual(len(self.out.errors), 1) self.assertTrue(self.out.errors[0]['message'].startswith("failed to render"))
def test_handler_bad_location_outside_project_root(self): "file at location may exist but is outside of project dir" self.valid_request['location'] = 'file:///dev/null' adapt.handler(self.valid_request, self.out) self.assertEqual(len(self.out.errors), 1) self.assertTrue(self.out.errors[0]['message'].startswith("refusing to download"))
def test_handler_bad_location(self): "location with missing file generates an error" self.valid_request['location'] = 'file://' + join(conf.PROJECT_DIR, 'does-not-exist.xml') adapt.handler(self.valid_request, self.out) self.assertEqual(len(self.out.errors), 1) self.assertTrue(self.out.errors[0]['message'].startswith("failed to download"))
def test_handler_bad_bad_data(self): "something about the data causes an unhandled exception that generate an error" adapt.handler(lambda x: x, self.out) self.assertEqual(len(self.out.errors), 1) self.assertTrue(self.out.errors[0]["message"].startswith("unhandled error"))
def test_handler_good_json_but_invalid(self): "good json but invalid request generates an error" adapt.handler('{"I-hope-you-have-a-very": "pants-party"}', self.out) self.assertEqual(len(self.out.errors), 1)
def test_handler_bad_json(self): "bad json request generates an error" adapt.handler("pants-party", self.out) self.assertEqual(len(self.out.errors), 1)