(self)
| 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): |
nothing calls this directly
no test coverage detected