def test_get_full_name_without_structure_level_and_without_title(self): """ Tests that get_full_name returns the write string. """ user = User() user.title = '' user.structure_level = '' user.get_short_name = MagicMock(return_value='test_short_name') self.assertEqual( user.get_full_name(), 'test_short_name', "User.get_full_name() returns wrong string when it has no " "structure_level and no title.")
def test_get_short_name_no_names(self): """ Tests the output of get_short_name. """ user = User(username='******') with patch('openslides.users.models.config') as mock_config: mock_config.__getitem__.return_value = False short_name = user.get_short_name() self.assertEqual( short_name, 'test_username', "User.get_short_name() returns wrong string when it has no fist_name " "and no last_name and is sorted by last_name.")
def test_get_full_name_with_structure_level_and_title(self): """ Tests, that get_full_name returns the write string. """ user = User() user.title = 'test_title' user.structure_level = 'test_structure_level' user.get_short_name = MagicMock(return_value='test_short_name') self.assertEqual( user.get_full_name(), 'test_title test_short_name (test_structure_level)', "User.get_full_name() returns wrong string when it has a structure_level and title" )
def test_get_short_name_sort_first_name_only_first_name(self): """ Tests the output of get_short_name. """ user = User() user.first_name = 'test_first_name' with patch('openslides.users.models.config') as mock_config: mock_config.__getitem__.return_value = True short_name = user.get_short_name() self.assertEqual( short_name, 'test_first_name', "User.get_short_name() returns wrong string when it has only a " "first_name and is sorted by first_name.")
def test_get_short_name_sort_last_name_both_names(self): """ Tests the output of get_short_name. """ user = User() user.first_name = 'test_first_name' user.last_name = 'test_last_name' with patch('openslides.users.models.config') as mock_config: mock_config.__getitem__.return_value = False short_name = user.get_short_name() self.assertEqual( short_name, 'test_last_name, test_first_name', "User.get_short_name() returns wrong string when it has a fist_name " "and a last_name and is sorted by last_name")
def test_while_spaces_in_name_parts(self): """ Tests the output if the name parts have white spaces at the begin or end. """ user = User() user.first_name = ' test_first_name\n ' user.last_name = ' test_last_name \n' with patch('openslides.users.models.config') as mock_config: mock_config.__getitem__.return_value = True short_name = user.get_short_name() self.assertEqual( short_name, 'test_first_name test_last_name', "User.get_short_name() has to strip whitespaces from the name parts.")