def law_to_markdown(filein, fileout=None, name=None, yaml_header=True): ret = False if fileout is None: fileout = StringIO() ret = True parser = sax.make_parser() if name is None: orig_slug = filein.name.split('/')[-1].split('.')[0] else: orig_slug = name handler = LawToMarkdown( fileout, orig_slug=orig_slug, yaml_header=DEFAULT_YAML_HEADER if yaml_header else None) parser.setFeature(sax.handler.feature_external_ges, False) parser.setContentHandler(handler) parser.parse(filein) if ret: fileout.filename = handler.filename return fileout
def file_from_dict(self, educt): file_ = StringIO(json.dumps(educt).decode()) file_.filename = 'customstyles.json' file_.content_type = 'application/json' return file_
def test_filename(app: Flask, db: SQLAlchemy) -> None: content = StringIO("test") content.filename = "test.txt" blob = Blob(content) assert "filename" in blob.meta assert blob.meta["filename"] == "test.txt"
from app.enums import FileCategory from app.exceptions.base import ResourceNotFoundException, \ AuthorizationException, \ ValidationException from app.models.file import File from app.models.user import User from app.repository import user_repository from app.service import user_service, file_service, oauth_service user_repository_mock = MagicMock(spec=dir(user_repository)) file_service_mock = MagicMock(spec=dir(file_service)) oauth_service_mock = MagicMock(spec=dir(oauth_service)) avatar_file_data = StringIO('fake avatar file data') avatar_file_data.filename = 'avatar.png' @patch.object(user_service, 'user_repository', user_repository_mock) @patch.object(user_service, 'file_service', file_service_mock) @patch.object(user_service, 'oauth_service', oauth_service_mock) class TestUserService(unittest.TestCase): def setUp(self): user_repository_mock.reset_mock() file_service_mock.reset_mock() def test_set_password(self): user = MagicMock(spec=User) password = "******" user_repository_mock.find_by_id.return_value = user
def test_filename(app, db): content = StringIO("test") content.filename = "test.txt" blob = Blob(content) assert "filename" in blob.meta assert blob.meta["filename"] == "test.txt"