本文整理汇总了Python中models.Employee.pk方法的典型用法代码示例。如果您正苦于以下问题:Python Employee.pk方法的具体用法?Python Employee.pk怎么用?Python Employee.pk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Employee
的用法示例。
在下文中一共展示了Employee.pk方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_callingGetEmployeesReturnsListOfDicts
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import pk [as 别名]
def test_callingGetEmployeesReturnsListOfDicts(self):
Employee.objects.filter = mock.MagicMock()
company = Company()
company.pk = 98
employee_one = Employee()
employee_one.pk = 12
employee_one.user = User()
employee_one.user.first_name = 'Fornavn'
employee_one.user.last_name = 'Efternavn'
employee_one.company = company
employee_two = Employee()
employee_two.pk = 13
employee_two.user = User()
employee_two.user.first_name = 'Fornavn'
employee_two.user.last_name = 'Efternavn'
employee_two.company = company
Employee.objects.filter.return_value = [employee_one, employee_two]
employee_one.getMyEmployees = mock.MagicMock()
employee_one.getMyEmployees.return_value = []
employee_list = employee_one.getEmployees()
self.assertEquals(2, len(employee_list))
self.assertTrue(isinstance(employee_list[0], dict))
self.assertTrue(isinstance(employee_list[0]['manager'], Employee))
self.assertEquals(employee_list[0]['manager'].pk, 12)
self.assertTrue(isinstance(employee_list[0]['employees'], list))
self.assertEquals(employee_list[0]['manager'].user.first_name, 'Fornavn')
self.assertEquals(employee_list[0]['manager'].user.last_name, 'Efternavn')
示例2: test_callingGetMyEmployeesWithEmployeeAsArgumentCallsFilterWithEmployeesPkAsArgument
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import pk [as 别名]
def test_callingGetMyEmployeesWithEmployeeAsArgumentCallsFilterWithEmployeesPkAsArgument(self):
master_employee = Employee()
master_employee.pk = 2
a_manager = Employee()
a_manager.pk = 87
with mock.patch.object(Employee, 'objects') as employee_mock:
master_employee.getMyEmployees(a_manager)
employee_mock.filter.assert_called_with(manager__pk=a_manager.pk)
示例3: test_callingGetMyEmployeesCallsOrderByOnFilterResultWithLastNameThenFirstNameAsArguments
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import pk [as 别名]
def test_callingGetMyEmployeesCallsOrderByOnFilterResultWithLastNameThenFirstNameAsArguments(self):
employee = Employee()
employee.pk = 2
with mock.patch.object(Employee, 'objects') as query_mock:
return_employee = Employee()
return_employee.pk = 4
return_employee.user = User()
return_employee.user.first_name = 'Joachim'
return_employee.user.last_name = 'Andersen'
return_employee.manager = employee
employee.getMyEmployees()
query_mock.filter.return_value.order_by.assert_called_with('user__last_name', 'user__first_name')
示例4: test_callingGetDevelopmentPlansWithAsManagerEqualToTrueCallsFilterWithOwnerManagerAsArgument
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import pk [as 别名]
def test_callingGetDevelopmentPlansWithAsManagerEqualToTrueCallsFilterWithOwnerManagerAsArgument(self):
employee = Employee()
employee.pk = 38
DevelopmentPlan.objects.filter = mock.MagicMock()
DevelopmentPlan.objects.filter.return_value.order_by = mock.MagicMock()
employee.getDevelopmentPlans(as_manager=True)
DevelopmentPlan.objects.filter.assert_called_once_with(owner__manager__pk=38)
示例5: test_callingGetMyEmployeesReturnsListOfEmployees
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import pk [as 别名]
def test_callingGetMyEmployeesReturnsListOfEmployees(self):
employee = Employee()
employee.pk = 2
with mock.patch.object(Employee, 'objects') as employee_mock:
return_employee = Employee()
return_employee.pk = 4
return_employee.user = User()
return_employee.user.first_name = 'Joachim'
return_employee.user.last_name = 'Andersen'
return_employee.manager = employee
query_set_mock = mock.MagicMock()
query_set_mock.order_by.return_value = iter([return_employee, ])
employee_mock.filter.return_value = query_set_mock
result = employee.getMyEmployees()
self.assertTrue(isinstance(result[0], Employee))
self.assertEqual(1, len(result))
self.assertEqual(4, result[0].pk)
self.assertEqual('Joachim', result[0].user.first_name)
self.assertEqual('Andersen', result[0].user.last_name)
示例6: test_callingCanAssociateNewPlanReturnsFalseIfTheEmployeeHasAnOpenDevelopmentPlan
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import pk [as 别名]
def test_callingCanAssociateNewPlanReturnsFalseIfTheEmployeeHasAnOpenDevelopmentPlan(self):
employee = Employee()
employee.pk = 38
employee.user = User()
employee.user.pk = 9
CompetenceFieldCollectionToUserRelation.objects.filter = mock.MagicMock()
CompetenceFieldCollectionToUserRelation.objects.filter.return_value.exists = mock.MagicMock()
CompetenceFieldCollectionToUserRelation.objects.filter.return_value.exists.return_value = [CompetenceFieldCollectionToUserRelation(employee.user, finished_at=None),]
self.assertFalse(employee.canAssociateNewPlan())
CompetenceFieldCollectionToUserRelation.objects.filter.assert_called_once_with(user__pk=employee.user.pk, finished_at=None)
示例7: test_callingGetDevelopmentPlansCallsFilterAndOrderByOnDevelopmentPlanWithGivenUserAsArgument
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import pk [as 别名]
def test_callingGetDevelopmentPlansCallsFilterAndOrderByOnDevelopmentPlanWithGivenUserAsArgument(self):
employee = Employee()
employee.pk = 38
employee.user = User()
employee.user.pk = 9
DevelopmentPlan.objects.filter = mock.MagicMock()
DevelopmentPlan.objects.filter.return_value.order_by = mock.MagicMock()
employee.getDevelopmentPlans()
DevelopmentPlan.objects.filter.assert_called_once_with(owner__pk=38)
DevelopmentPlan.objects.filter.return_value.order_by.assert_called_once_with('-created_at')
示例8: test_callingGetEmployeesCallsGetMyEmployeesOneTimePerManagerInSameCompanyAsCaller
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import pk [as 别名]
def test_callingGetEmployeesCallsGetMyEmployeesOneTimePerManagerInSameCompanyAsCaller(self):
Employee.objects.filter = mock.MagicMock()
company = Company()
company.pk = 98
employee_one = Employee()
employee_one.pk = 12
employee_one.company = company
employee_one.user = User()
employee_one.user.first_name = 'Fornavn'
employee_one.user.last_name = 'Efternavn'
employee_two = Employee()
employee_two.pk = 12
employee_two.company = company
employee_two.user = User()
employee_two.user.first_name = 'Fornavn'
employee_two.user.last_name = 'Efternavn'
Employee.objects.filter.return_value = [employee_one, employee_two]
employee_one.getMyEmployees = mock.MagicMock()
employee_one.getEmployees()
self.assertEquals(2, employee_one.getMyEmployees.call_count)
示例9: test_callingGetDevelopmentPlansReturnsListOfDevelopmentPlans
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import pk [as 别名]
def test_callingGetDevelopmentPlansReturnsListOfDevelopmentPlans(self):
employee = Employee()
employee.pk = 38
employee.user = User()
employee.user.pk = 9
development_plan_one = DevelopmentPlan()
development_plan_two = DevelopmentPlan()
DevelopmentPlan.objects.filter = mock.MagicMock()
DevelopmentPlan.objects.filter.return_value.order_by = mock.MagicMock()
DevelopmentPlan.objects.filter.return_value.order_by.return_value = [development_plan_one, development_plan_two]
development_plans = employee.getDevelopmentPlans()
self.assertEquals(2, len(development_plans))
self.assertTrue(isinstance(development_plans[0], DevelopmentPlan))
示例10: test_callingGetEmployeesCallsGetMyEmployeesWithEmployeeAsArgument
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import pk [as 别名]
def test_callingGetEmployeesCallsGetMyEmployeesWithEmployeeAsArgument(self):
Employee.objects.filter = mock.MagicMock()
employee = Employee()
employee.pk = 29
employee.company = Company()
employee.company.pk = 87
employee.user = User()
employee.user.first_name = 'Fornavn'
employee.user.last_name = 'Efternavn'
Employee.objects.filter.return_value = [employee, ]
employee.getMyEmployees = mock.MagicMock()
employee.getEmployees()
employee.getMyEmployees.assert_called_once_with(manager=employee)
示例11: test_callingGetMyEmployeesCallsFilterOnEmployeeWithCurrentUserPkAsArgumentToManager
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import pk [as 别名]
def test_callingGetMyEmployeesCallsFilterOnEmployeeWithCurrentUserPkAsArgumentToManager(self):
employee = Employee()
employee.pk = 2
with mock.patch.object(Employee, 'objects') as query_mock:
employee.getMyEmployees()
query_mock.filter.assert_called_with(manager__pk=employee.pk)