MCPcopy Index your code
hub / github.com/MongoEngine/mongoengine / test_file_multidb

Method test_file_multidb

tests/fields/test_file_field.py:484–514  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

482 t.image.delete()
483
484 def test_file_multidb(self):
485 register_connection("test_files", "test_files")
486
487 class TestFile(Document):
488 name = StringField()
489 the_file = FileField(db_alias="test_files", collection_name="macumba")
490
491 TestFile.drop_collection()
492
493 # delete old filesystem
494 get_db("test_files").macumba.files.drop()
495 get_db("test_files").macumba.chunks.drop()
496
497 # First instance
498 test_file = TestFile()
499 test_file.name = "Hello, World!"
500 test_file.the_file.put(b"Hello, World!", name="hello.txt")
501 test_file.save()
502
503 data = get_db("test_files").macumba.files.find_one()
504 assert data.get("name") == "hello.txt"
505
506 test_file = TestFile.objects.first()
507 assert test_file.the_file.read() == b"Hello, World!"
508
509 test_file = TestFile.objects.first()
510 test_file.the_file = b"Hello, World!"
511 test_file.save()
512
513 test_file = TestFile.objects.first()
514 assert test_file.the_file.read() == b"Hello, World!"
515
516 def test_copyable(self):
517 class PutFile(Document):

Callers

nothing calls this directly

Calls 9

get_dbFunction · 0.90
register_connectionFunction · 0.85
TestFileClass · 0.85
drop_collectionMethod · 0.80
readMethod · 0.80
putMethod · 0.45
saveMethod · 0.45
getMethod · 0.45
firstMethod · 0.45

Tested by

no test coverage detected