1

嗨,我正在尝试测试save()触发post_save信号的模拟 django-filer。

模型.py

import filer.fields.file import FilerFileField

class DeliveryInvoice(TimeStampedModel):
    invoice_excel = FilerFileField(null=True, blank=True)

测试.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() 方法。可能有什么问题?/

4

0 回答 0