def test_small_chunks(self): self.db.fs.files.remove({}) self.db.fs.chunks.remove({}) self.files = 0 self.chunks = 0 def helper(data): filename = qcheck.gen_printable_string(qcheck.lift(20))() f = GridFile({"filename": filename, "chunkSize": 1}, self.db, "w") f.write(data) f.close() self.files += 1 self.chunks += len(data) self.assertEqual(self.db.fs.files.find().count(), self.files) self.assertEqual(self.db.fs.chunks.find().count(), self.chunks) f = GridFile({"filename": filename}, self.db) self.assertEqual(f.read(), data) f.close() f = GridFile({"filename": filename}, self.db) self.assertEqual(f.read(10) + f.read(10), data) f.close() return True qcheck.check_unittest(self, helper, qcheck.gen_string(qcheck.gen_range(0, 20)))
def test_multi_chunk_file(self): random_string = qcheck.gen_string(qcheck.lift(300000))() f = GridIn(self.db.fs) f.write(random_string) f.close() self.assertEqual(1, self.db.fs.files.find().count()) self.assertEqual(2, self.db.fs.chunks.find().count()) g = GridOut(self.db.fs, f._id) self.assertEqual(random_string, g.read())
def test_multi_chunk_file(self): self.db.fs.files.remove({}) self.db.fs.chunks.remove({}) random_string = qcheck.gen_string(qcheck.lift(300000))() file = GridFile({"filename": "test"}, self.db, "w") file.write(random_string) file.close() self.assertEqual(self.db.fs.files.find().count(), 1) self.assertEqual(self.db.fs.chunks.find().count(), 2) f = GridFile({}, self.db) self.assertEqual(f.read(), random_string) f.close()
def test_small_chunks(self): self.files = 0 self.chunks = 0 def helper(data): f = GridIn(self.db.fs, chunkSize=1) f.write(data) f.close() self.files += 1 self.chunks += len(data) self.assertEqual(self.files, self.db.fs.files.find().count()) self.assertEqual(self.chunks, self.db.fs.chunks.find().count()) g = GridOut(self.db.fs, f._id) self.assertEqual(data, g.read()) g = GridOut(self.db.fs, f._id) self.assertEqual(data, g.read(10) + g.read(10)) return True qcheck.check_unittest(self, helper, qcheck.gen_string(qcheck.gen_range(0, 20)))
def test_random_data_is_not_bson(self): qcheck.check_unittest(self, qcheck.isnt(is_valid), qcheck.gen_string(qcheck.gen_range(0, 40)))