Example #1
0
    def test_hasAccessSuccessIsManagerInSameCompany(self):

        comp = models.Company(pk=1)

        currentEmpl = models.Employee(pk=1, company=comp, is_manager=True)
        currentEmpl.isEnsoUser = Mock(return_value=False)

        targetEmpl = models.Employee(pk=2, company=comp)

        self.assertTrue(currentEmpl.hasAccessTo(targetEmpl))
Example #2
0
    def test_hasAccessSuccessTargetIsCurrentUser(self):

        currentEmpl = models.Employee()
        currentEmpl.pk = 1
        currentEmpl.isEnsoUser = Mock(return_value=False)

        targetEmpl = models.Employee()
        targetEmpl.pk = 1

        self.assertTrue(currentEmpl.hasAccessTo(targetEmpl))
Example #3
0
    def test_hasAccessSuccessIsSuperUserOrHigher(self):

        comp = models.Company(pk=1)

        currentEmpl = models.Employee(pk=1, company=comp, is_manager=False)
        currentEmpl.isEnsoUser = Mock(return_value=False)
        currentEmpl.isCompanySuperUserOrHigher = Mock(return_value=True)

        tarcomp = models.Company(pk=2)
        targetEmpl = models.Employee(pk=2, company=tarcomp)

        self.assertTrue(currentEmpl.hasAccessTo(targetEmpl))
Example #4
0
    def test_isCompanySuperUserOrHigherSuccess(self):

        currentEmpl = models.Employee()

        with patch.object(models.Employee, 'roles') as mock_roles:
            mock_roles.count.return_value = 1
            self.assertTrue(currentEmpl.isCompanySuperUserOrHigher())
Example #5
0
    def test_isCompanySuperUserOrHigherFalseZeroRoles(self):

        currentEmpl = models.Employee()

        with patch.object(models.Employee, 'roles') as mock_roles:
            mock_roles.count.return_value = 0
            self.assertFalse(currentEmpl.isCompanySuperUserOrHigher())
Example #6
0
    def test_isEnsoUserFalseWrongRole(self):

        currentEmpl = models.Employee()

        with patch.object(models.Employee, 'roles') as mock_roles:

            mock_roles.count.return_value = 1

            mock_filter = Mock()
            mock_filter.exists.return_value = False
            mock_roles.filter.return_value = mock_filter

            self.assertFalse(currentEmpl.isEnsoUser())
            mock_roles.filter.assert_called_with(name=u'Enso-bruger')
Example #7
0
	def test_canManageIsEnsoUser(self):

		emps = models.Employee.objects.all()
		print(emps)

		return


		currentCompany = models.Company()
		currentCompany.pk = 1
		currentEmpl = models.Employee()
		currentEmpl.isEnsoUser = Mock(return_value=False)
		currentEmpl.company = currentCompany


		targetCompany = models.Company()
		targetCompany.pk = 2

		targetEmpl = models.Employee()
		muser = Mock(spec=User)
		muser._state = Mock()
		muser.id = 1
		try:
			targetEmpl.user = muser
		except ValueError:
			pass

		targetEmpl.company = targetCompany

		devplan = models.DevelopmentPlan()
		devplan.owner = targetEmpl

		self.assertTrue(devplan.canManage(currentEmpl))

		currentEmpl.isEnsoUser.assert_called_once_with()
		currentEmpl.isManager.assert_called_once_with()
Example #8
0
    def test_hasAccessSuccessToIsEnsoUser(self):

        currentEmpl = models.Employee()
        currentEmpl.isEnsoUser = Mock(return_value=True)
        self.assertTrue(currentEmpl.hasAccessTo(None))