我正在尝试测试一些包括调用 celery 任务的函数。任务涉及调用 3rd 方网站,我需要在测试期间避免它。
知道如何在测试期间禁用所有 celery 任务吗?
当我在我的一个项目应用程序上执行迁移时,我收到以下错误:
ValueError:模型的未处理挂起操作:common.shipmentaddress(由fields:catalog.Fulfillment.address引用)
Django 1.9,python 2.7.10
我一直在寻找循环导入,但我不认为这是它
这些是模型:
class ShipmentAddress(models.Model):
recipient_first_name = models.CharField(max_length=50, null=True, blank=True)
recipient_last_name = models.CharField(max_length=50, null=True, blank=True)
street_name = models.CharField(max_length=50)
state = models.ForeignKey(State)
postal_code = models.IntegerField(default=0)
city = models.CharField(max_length=50)
class Meta:
db_table = 'shipment_address'
class Fulfillment(models.Model):
address = models.ForeignKey(ShipmentAddress)
inventory_items = models.ManyToManyField(Item_With_Size, through='Inventory_Item')
class Meta:
verbose_name = 'fulfilment'
verbose_name_plural = 'fulfilments'
db_table = 'fulfilment'
Run Code Online (Sandbox Code Playgroud)
迁移看起来像这样:
class Migration(migrations.Migration):
dependencies = [
('catalog', '0009_auto_20151130_1118'),
]
operations = [
migrations.AlterField(
model_name='fulfillment',
name='address',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='common.ShipmentAddress'),
),
]
class Migration(migrations.Migration):
dependencies = [ …Run Code Online (Sandbox Code Playgroud) 我有一个带有clean方法的模型,它检查两个字段是否为null,如果是,则引发ValidationError
如何在不使测试失败的情况下执行测试(通常我使用鼻子)来进行实例创建.我想做一些断言以确保实例的创建失败.
这是干净的方法:
def clean(self):
if not self.message and not self.image:
raise ValidationError('You must provide either Message and/or '
'Image')
Run Code Online (Sandbox Code Playgroud)