def test_add_to_principle_investigator_role_existing_different_user( self, remove_local_role_mock, add_local_role_mock, role_mock): ''' If the current user in the PI role is the same as the existing one then nothing should happen. ''' settings.PRINCIPLE_INVESTIGATOR_ROLE = 'Principle_Investigator' user1 = self.test_user user2 = User.objects.create_user('test2', '*****@*****.**', 'password2') a_role_mock = MagicMock(name='a_role') a_role_mock.get_local_users.return_value = [user2] role_mock.objects.get.return_value = a_role_mock test_application = EthicsApplication(title='test', principle_investigator=user1) test_application._add_to_principle_investigator_role() a_role_mock.get_local_users.assert_called_once_with(test_application) remove_local_role_mock.assert_called_once_with(test_application, user2, a_role_mock) add_local_role_mock.assert_called_once_with(test_application, user1, a_role_mock)
def test_add_to_principle_investigator_role_no_existing_user(self, remove_local_role_mock, add_local_role_mock, role_mock): ''' If the current user in the PI role is the same as the existing one then nothing should happen. ''' settings.PRINCIPLE_INVESTIGATOR_ROLE = 'Principle_Investigator' a_role_mock = MagicMock(name='a_role') a_role_mock.get_local_users.return_value = [] role_mock.objects.get.return_value = a_role_mock user1 = self.test_user test_application = EthicsApplication(title = 'test', principle_investigator=user1) test_application._add_to_principle_investigator_role() a_role_mock.get_local_users.assert_called_once_with(test_application) self.assertEqual(0, remove_local_role_mock.call_count) self.assertEqual([call(test_application, user1, a_role_mock)], add_local_role_mock.mock_calls)
def test_add_to_principle_investigator_role_existing_different_user(self, remove_local_role_mock, add_local_role_mock, role_mock): ''' If the current user in the PI role is the same as the existing one then nothing should happen. ''' settings.PRINCIPLE_INVESTIGATOR_ROLE = 'Principle_Investigator' user1 = self.test_user user2 = User.objects.create_user('test2', '*****@*****.**', 'password2') a_role_mock = MagicMock(name='a_role') a_role_mock.get_local_users.return_value = [user2] role_mock.objects.get.return_value = a_role_mock test_application = EthicsApplication(title = 'test', principle_investigator=user1) test_application._add_to_principle_investigator_role() a_role_mock.get_local_users.assert_called_once_with(test_application) remove_local_role_mock.assert_called_once_with(test_application, user2, a_role_mock) add_local_role_mock.assert_called_once_with(test_application, user1, a_role_mock)
def test_add_to_principle_investigator_role_existing_same_user( self, remove_local_role_mock, add_local_role_mock, role_mock): ''' If the current user in the PI role is the same as the existing one then nothing should happen. ''' settings.PRINCIPLE_INVESTIGATOR_ROLE = 'Principle_Investigator' user1 = self.test_user a_role_mock = MagicMock(name='a_role') a_role_mock.get_local_users.return_value = [user1] role_mock.objects.get.return_value = a_role_mock test_application = EthicsApplication(title='test', principle_investigator=user1) test_application._add_to_principle_investigator_role() a_role_mock.get_local_users.assert_called_once_with(test_application) self.assertEqual(remove_local_role_mock.call_count, 0) self.assertEqual(add_local_role_mock.call_count, 0)