def test_grid_out_custom_opts(self): db = self.db.with_options(codec_options=UPPERSTR_DECODER_CODECOPTS) one = GridIn(db.fs, _id=5, filename="my_file", contentType="text/html", chunkSize=1000, aliases=["foo"], metadata={"foo": 'red', "bar": 'blue'}, bar=3, baz="hello") one.write(b"hello world") one.close() two = GridOut(db.fs, 5) self.assertEqual("my_file", two.name) self.assertEqual("my_file", two.filename) self.assertEqual(5, two._id) self.assertEqual(11, two.length) self.assertEqual("text/html", two.content_type) self.assertEqual(1000, two.chunk_size) self.assertTrue(isinstance(two.upload_date, datetime.datetime)) self.assertEqual(["foo"], two.aliases) self.assertEqual({"foo": 'red', "bar": 'blue'}, two.metadata) self.assertEqual(3, two.bar) self.assertEqual("5eb63bbbe01eeed093cb22bb8f5acdc3", two.md5) for attr in ["_id", "name", "content_type", "length", "chunk_size", "upload_date", "aliases", "metadata", "md5"]: self.assertRaises(AttributeError, setattr, two, attr, 5)
def test_gridin_attrs(self): motor_gridin_only = set(["set"]).union(motor_only) gridin_only = set(["md5"]) self.assertEqual( attrs(GridIn(env.sync_cx.test.fs)) - gridin_only, attrs(MotorGridIn(self.cx.test.fs)) - motor_gridin_only, )
def create(self, path, mode=FMODE, fi=None): with self._ent(path) as spec: spec._file['stat'].update(st_mode=mode | S_IFREG) file = spec._file file.pop('_id') fh, spec = self._ctx.acquire(GridIn(self.fs, **file)) if fi is not None: fi.fh = fh return 0 return fh
def test_gridin_attrs(self): motor_gridin_only = set(['set']).union(motor_only) self.assertEqual( attrs(GridIn(env.sync_cx.test.fs)), attrs(MotorGridIn(self.cx.test.fs)) - motor_gridin_only)