Best Python code snippet using localstack_python
DiskFile.py
Source:DiskFile.py
...70 ) + SimpleItem.manage_options)71 security = ClassSecurityInfo()72 @property73 def title(self):74 return self._get_mime_type()75 def __init__(self, id, pathspec):76 self._setId(id)77 self.pathspec = pathspec78 def _get_mime_type(self):79 content_type, content_encoding = mimetypes.guess_type(self.pathspec)80 if content_type is None:81 return 'application/octet-stream'82 else:83 return content_type84 def _get_data(self):85 f = open(resolve(self.pathspec), 'rb')86 data = f.read()87 f.close()88 return data89 security.declarePublic('index_html')90 def index_html(self, REQUEST, RESPONSE):91 """ return the data """92 RESPONSE.setHeader('content-type', self._get_mime_type())93 RESPONSE.write(self._get_data())94 _manage_main = PageTemplateFile('zpt/disk_file_manage', globals())95 security.declareProtected(view_management_screens, 'manage_main')96 def manage_main(self, REQUEST):97 """ """98 options = {99 'fs_path': resolve(self.pathspec),100 'file_data': self._get_data(),101 'mime_type': self._get_mime_type(),102 }103 return self._manage_main(REQUEST, **options)104 def manage_copy_to_database(self, REQUEST):105 """ Copy the file to ZODB for further customization """106 file_id = self.getId()107 parent = self.aq_inner.aq_parent108 parent.manage_delObjects([file_id])109 data_file = open(resolve(self.pathspec), 'rb')110 parent.manage_addFile(id=file_id,111 file=data_file,112 content_type=self._get_mime_type())113 data_file.close()114 file_ob = parent[file_id]115 log.info("DiskFile %r uploaded to database by %r",116 '/'.join(file_ob.getPhysicalPath()),117 REQUEST.AUTHENTICATED_USER)...
test_get_mime_type.py
Source:test_get_mime_type.py
2from crawler.app import App3def test_basic():4 filename = 'image.png'5 expected_mime_type = 'image/png'6 assert App._get_mime_type(filename) == expected_mime_type7def test_unknown_extension():8 filename = 'model_empirical_uncal_high_stddev.binaryproto'9 expected_mime_type = 'application/binaryproto'10 assert App._get_mime_type(filename) == expected_mime_type11def test_no_extension():12 filename = 'file'13 expected_mime_type = config.unknown_mime_failback14 assert App._get_mime_type(filename) == expected_mime_type15def test_no_empty_extension():16 filename = 'file.'17 expected_mime_type = config.unknown_mime_failback...
test_local_wrapper.py
Source:test_local_wrapper.py
...4# ããã¸ã§ã¯ããããã«ç§»åãã5os.chdir(os.path.dirname(os.path.abspath(__file__)) + "/../")6data_dir = Path("./tests/data")7class TestWrapperUtils:8 def test__get_mime_type(self):9 assert Wrapper._get_mime_type(str(data_dir / "lenna.png")) == "image/png"10 assert Wrapper._get_mime_type("sample.jpg") == "image/jpeg"11 assert Wrapper._get_mime_type("sample.txt") == "text/plain"...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!