示例#1
0
def test_remove_files_on_change_same_file():
    test_obj = TestModel1()
    test_obj.test_file = "test_filename"
    test_obj.save()

    with patch('django_transactional_cleanup.service._delete_file') as mock:
        service.remove_files_on_change(TestModel1, test_obj)
        assert not mock.called
示例#2
0
def test_remove_files_on_change_different_file():
    test_obj = TestModel1()
    test_obj.test_file = "test_filename1"
    test_obj.save()
    test_obj.test_file.storage = Mock()
    test_obj.test_file.storage.exists.return_value = True

    test_obj.test_file = Mock()
    test_obj.test_file.name = "test_filename2"

    with patch('django_transactional_cleanup.service._delete_file') as mock:
        service.remove_files_on_change(TestModel1, test_obj)
        assert mock.called