forked from erp-dev/erp
feat: added plate_at_from and plate_at_to in plate order query api
This commit is contained in:
@@ -531,6 +531,110 @@ class PlateOrderAPITestCase(TestCase):
|
||||
else:
|
||||
self.assertEqual(len(response.data), 1)
|
||||
self.assertEqual(response.data[0]['is_invalid'], False)
|
||||
|
||||
def test_filter_by_plate_at_from(self):
|
||||
"""测试按开版时间起始筛选(带时分秒)"""
|
||||
from django.utils import timezone
|
||||
from datetime import timedelta
|
||||
from urllib.parse import quote
|
||||
|
||||
now = timezone.now()
|
||||
# 创建两个订单,分别在不同时间点
|
||||
order1 = printing_models.PlateOrder.objects.create(
|
||||
customer=self.customer,
|
||||
design_code='DESIGN001',
|
||||
plate_type='圆网',
|
||||
plate_date=now - timedelta(hours=2),
|
||||
)
|
||||
order2 = printing_models.PlateOrder.objects.create(
|
||||
customer=self.customer,
|
||||
design_code='DESIGN002',
|
||||
plate_type='平网',
|
||||
plate_date=now,
|
||||
)
|
||||
|
||||
# 筛选 1 小时前之后的订单(应该只返回 order2)
|
||||
one_hour_ago = quote((now - timedelta(hours=1)).isoformat())
|
||||
response = self.client.get(f'/api/v1/plate-orders/?plate_at_from={one_hour_ago}')
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
if isinstance(response.data, dict):
|
||||
ids = [r['id'] for r in response.data['results']]
|
||||
else:
|
||||
ids = [r['id'] for r in response.data]
|
||||
self.assertIn(order2.id, ids)
|
||||
self.assertNotIn(order1.id, ids)
|
||||
|
||||
def test_filter_by_plate_at_to(self):
|
||||
"""测试按开版时间结束筛选(带时分秒)"""
|
||||
from django.utils import timezone
|
||||
from datetime import timedelta
|
||||
from urllib.parse import quote
|
||||
|
||||
now = timezone.now()
|
||||
# 创建两个订单,分别在不同时间点
|
||||
order1 = printing_models.PlateOrder.objects.create(
|
||||
customer=self.customer,
|
||||
design_code='DESIGN001',
|
||||
plate_type='圆网',
|
||||
plate_date=now - timedelta(hours=2),
|
||||
)
|
||||
order2 = printing_models.PlateOrder.objects.create(
|
||||
customer=self.customer,
|
||||
design_code='DESIGN002',
|
||||
plate_type='平网',
|
||||
plate_date=now,
|
||||
)
|
||||
|
||||
# 筛选 1 小时前之前的订单(应该只返回 order1)
|
||||
one_hour_ago = quote((now - timedelta(hours=1)).isoformat())
|
||||
response = self.client.get(f'/api/v1/plate-orders/?plate_at_to={one_hour_ago}')
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
if isinstance(response.data, dict):
|
||||
ids = [r['id'] for r in response.data['results']]
|
||||
else:
|
||||
ids = [r['id'] for r in response.data]
|
||||
self.assertIn(order1.id, ids)
|
||||
self.assertNotIn(order2.id, ids)
|
||||
|
||||
def test_filter_by_plate_at_range(self):
|
||||
"""测试按开版时间范围筛选(带时分秒)"""
|
||||
from django.utils import timezone
|
||||
from datetime import timedelta
|
||||
from urllib.parse import quote
|
||||
|
||||
now = timezone.now()
|
||||
# 创建三个订单,分别在不同时间点
|
||||
order1 = printing_models.PlateOrder.objects.create(
|
||||
customer=self.customer,
|
||||
design_code='DESIGN001',
|
||||
plate_type='圆网',
|
||||
plate_date=now - timedelta(hours=3),
|
||||
)
|
||||
order2 = printing_models.PlateOrder.objects.create(
|
||||
customer=self.customer,
|
||||
design_code='DESIGN002',
|
||||
plate_type='平网',
|
||||
plate_date=now - timedelta(hours=1),
|
||||
)
|
||||
order3 = printing_models.PlateOrder.objects.create(
|
||||
customer=self.customer,
|
||||
design_code='DESIGN003',
|
||||
plate_type='圆网',
|
||||
plate_date=now + timedelta(hours=1),
|
||||
)
|
||||
|
||||
# 筛选 2 小时前到现在之间的订单(应该只返回 order2)
|
||||
two_hours_ago = quote((now - timedelta(hours=2)).isoformat())
|
||||
now_iso = quote(now.isoformat())
|
||||
response = self.client.get(f'/api/v1/plate-orders/?plate_at_from={two_hours_ago}&plate_at_to={now_iso}')
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
if isinstance(response.data, dict):
|
||||
ids = [r['id'] for r in response.data['results']]
|
||||
else:
|
||||
ids = [r['id'] for r in response.data]
|
||||
self.assertIn(order2.id, ids)
|
||||
self.assertNotIn(order1.id, ids)
|
||||
self.assertNotIn(order3.id, ids)
|
||||
|
||||
def test_search_by_design_code(self):
|
||||
"""测试按设计编号搜索"""
|
||||
|
||||
Reference in New Issue
Block a user