def test_write_binary_file(self, key_mock): """ Tests _write_files """ self.app.config['FLASKS3_ONLY_MODIFIED'] = True static_folder = tempfile.mkdtemp() static_url_loc = static_folder filenames = [os.path.join(static_folder, 'favicon.ico')] for filename in filenames: # Write random data into files with open(filename, 'wb') as f: f.write(bytearray([120, 3, 255, 0, 100])) flask_s3._write_files(key_mock, self.app, static_url_loc, static_folder, filenames, None) expected = { 'ACL': 'public-read', 'Bucket': None, 'Metadata': {}, 'ContentEncoding': 'gzip', 'Body': b'x\x03\xff\x00d', 'Key': filenames[0][1:], 'Expires': 'Thu, 31 Dec 2037 23:59:59 GMT' } name, args, kwargs = key_mock.mock_calls[0] self.assertEquals(expected, kwargs)
def test_write_binary_file(self, key_mock): """ Tests _write_files """ self.app.config['FLASKS3_ONLY_MODIFIED'] = True static_folder = tempfile.mkdtemp() static_url_loc = static_folder filenames = [os.path.join(static_folder, 'favicon.ico')] for filename in filenames: # Write random data into files with open(filename, 'wb') as f: f.write(bytearray([120, 3, 255, 0, 100])) flask_s3._write_files(key_mock, self.app, static_url_loc, static_folder, filenames, None) expected = { 'ACL': 'public-read', 'Bucket': None, 'Metadata': {}, 'ContentEncoding': 'gzip', 'Body': b'x\x03\xff\x00d', 'Key': filenames[0][1:], 'Expires': 'Thu, 31 Dec 2037 23:59:59 GMT'} name, args, kwargs = key_mock.mock_calls[0] self.assertEquals(expected, kwargs)
def test__write_files(self, key_mock): """ Tests _write_files """ static_url_loc = '/foo/static' static_folder = '/home/z' assets = ['/home/z/bar.css', '/home/z/foo.css'] exclude = ['/foo/static/foo.css', '/foo/static/foo/bar.css'] # we expect foo.css to be excluded and not uploaded expected = [call(bucket=None, name=u'/foo/static/bar.css'), call().set_contents_from_filename('/home/z/bar.css')] flask_s3._write_files(static_url_loc, static_folder, assets, None, exclude) self.assertLessEqual(expected, key_mock.mock_calls)
def test__write_files(self, key_mock): """ Tests _write_files """ static_url_loc = '/foo/static' static_folder = '/home/z' assets = ['/home/z/bar.css', '/home/z/foo.css'] exclude = ['/foo/static/foo.css', '/foo/static/foo/bar.css'] # we expect foo.css to be excluded and not uploaded expected = [call(bucket=None, name=six.u('/foo/static/bar.css')), call().set_metadata('Cache-Control', 'cache instruction'), call().set_metadata('Expires', 'Thu, 31 Dec 2037 23:59:59 GMT'), call().set_metadata('Content-Encoding', 'gzip'), call().set_contents_from_filename('/home/z/bar.css')] flask_s3._write_files(key_mock, self.app, static_url_loc, static_folder, assets, None, exclude) self.assertLessEqual(expected, key_mock.mock_calls)
def test__write_files(self, key_mock): """ Tests _write_files """ static_url_loc = '/foo/static' static_folder = '/home/z' assets = ['/home/z/bar.css', '/home/z/foo.css'] exclude = ['/foo/static/foo.css', '/foo/static/foo/bar.css'] # we expect foo.css to be excluded and not uploaded expected = [ call(bucket=None, name=u'/foo/static/bar.css'), call().set_metadata('Cache-Control', 'cache instruction'), call().set_contents_from_filename('/home/z/bar.css') ] flask_s3._write_files(self.app, static_url_loc, static_folder, assets, None, exclude) self.assertLessEqual(expected, key_mock.mock_calls)