factory/apps/vm/tests.py

39 lines
1.1 KiB
Python

from datetime import timedelta
from unittest.mock import patch
from django.test import TestCase
from django.utils import timezone
from apps.hrm.models import Employee
from apps.hrm.services import HrmService
from apps.vm.models import Visit
class VisitTest(TestCase):
@patch.object(HrmService, 'sync_dahua_employee')
def test_sync_employee_uses_visit_time_window(self, sync_employee):
visit_time = timezone.now()
leave_time = visit_time + timedelta(hours=2)
visit = Visit.objects.create(
purpose=Visit.V_PURPOSE_CHOICES[0][0],
level=Visit.V_LEVEL_CHOICES[0][0],
name='访客同步测试',
visit_time=visit_time,
leave_time=leave_time,
)
employee = Employee.objects.create(name='测试访客', type='visitor')
HrmService.sync_dahua_employee(
employee,
'',
visit.visit_time,
visit.leave_time,
)
sync_employee.assert_called_once_with(
employee,
'',
visit_time,
leave_time,
)