Exemple #1
0
 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)
Exemple #2
0
	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)
Exemple #3
0
 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)
Exemple #4
0
	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')
Exemple #5
0
 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')
Exemple #6
0
	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')
Exemple #7
0
 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')
Exemple #8
0
	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)
Exemple #9
0
 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)
Exemple #10
0
	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)
Exemple #11
0
	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)
Exemple #12
0
 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)
Exemple #13
0
 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)
Exemple #14
0
	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)