def test_save_file(self): """Save redirects to a JSON string in a file or file-like object.""" rd1 = Redirect('/one', '/two', 302) rd2 = Redirect('/three', '/four', 302) rd3 = Redirect('/five', '/six', 302) rdf = RedirectsFile('/tmp/foo.json') rdf.add_redirect(rd1) rdf.add_redirect(rd2) rdf.add_redirect(rd3) json_file = StringIO() json_file.write(json.dumps([rd.to_JSON() for rd in rdf.redirects])) json_file.seek(0) json_ofile = StringIO() rdf.save_file(json_ofile) json_ofile.seek(0) assert json_file.read() == json_ofile.read()