您好我正在尝试测试触发save()
信号的模拟django-filer post_save
。
models.py
import filer.fields.file import FilerFileField
class DeliveryInvoice(TimeStampedModel):
invoice_excel = FilerFileField(null=True, blank=True)
tests.py
from filer.models.filemodels import File as FilerFile
from django.core.files import File
def test_if_delivery_invoice_number_updated_on_file_save_through_admin(self):
with patch("orders.utils.apply_invoice_number_to_orders") as signal_mock_handler:
post_save.connect(signal_mock_handler, sender=DeliveryInvoice)
filename = 'test_invoice_excel'
filepath = 'orders/fixtures/delivery_invoices.xlsx'
with open(filepath, 'rb') as f:
file_obj = File(f, name=filename)
error -> invoice_excel = FilerFile.objects.create(owner=self.user, file=file_obj, original_filename=filename)
instance = DeliveryInvoice(invoice_excel=invoice_excel)
instance.save()
self.assertTrue(signal_mock_handler.called)
错误消息
....
File "/Users/mhjeon/.pyenv/versions/3.6.0/envs/modernlab/lib/python3.6/site-packages/boto/auth.py", line 1070, in _wrapper
if test in self.host:
TypeError: argument of type 'NoneType' is not iterable
几天前用于工作的代码,但经过一些我认为与订单模型无关的代码重构之后,它突然无法调用django-filer的FilerModel.save()方法。 可能有什么不对?/