forked from erp-dev/erp
fix
This commit is contained in:
@@ -1198,3 +1198,32 @@ class PrintingJobAPITestCase(TestCase):
|
||||
result = response.data['results'][0]
|
||||
self.assertIn('product_image_url', result)
|
||||
self.assertIsNone(result['product_image_url'])
|
||||
|
||||
def test_list_printing_jobs_product_image_url_fallback_to_local_image(self):
|
||||
"""测试产品图片 URL fallback 到本地 image 字段"""
|
||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||
|
||||
# 确保 mdy_image_url 和 description 都为空
|
||||
self.product.mdy_image_url = None
|
||||
self.product.description = None
|
||||
# 设置本地图片(模拟已上传的文件路径)
|
||||
self.product.image = 'product_images/test_product.jpg'
|
||||
self.product.save()
|
||||
|
||||
job = printing_models.PrintingJob.objects.create(
|
||||
printing_order=self.printing_order,
|
||||
product=self.product,
|
||||
quantity=100,
|
||||
unit='米',
|
||||
size='50*60',
|
||||
pieces=10
|
||||
)
|
||||
|
||||
response = self.client.get('/api/v1/printing-jobs/')
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
# 验证 product_image_url 字段存在且包含本地图片路径
|
||||
result = response.data['results'][0]
|
||||
self.assertIn('product_image_url', result)
|
||||
self.assertIsNotNone(result['product_image_url'])
|
||||
self.assertIn('product_images/test_product.jpg', result['product_image_url'])
|
||||
|
||||
Reference in New Issue
Block a user