def test_create_empty_group(self): """ create_empty_group creates agroup associated with a Larp. """ empty_group = create_group("") self.assertEqual(empty_group.larp.name, larp_name()) self.assertEqual(str(empty_group), larp_name() + " - no group")
def test_create_group(self): """ create_group creates a Group associated with a Larp. """ group_name = "test group name" group = create_group(group_name) self.assertEqual(group.name, group_name) self.assertEqual(group.larp.name, larp_name())
def create_group(group_name=""): group_search = Group.objects.filter(name=group_name) if group_search: return group_search[0] larp = Larp(name=larp_name()) larp.save() group = Group(larp=larp, name=group_name) group.save() return group
def test_create_character_assigment(self): """ create_character_assigment assigns a character to a player on a concrete larp run for a character without a group. """ user = User(username="******", first_name="Ana", last_name="Garcia") larp = Larp(name=larp_name()) empty_group = Group(name="", larp=larp) character = Character(group=empty_group, name="Marie Curie") character_assigment = CharacterAssigment(run=1, character=character, user=user) self.assertIs(character_assigment.character.name, "Marie Curie") self.assertIs(character_assigment.character.group.larp, larp) self.assertEqual(character_assigment.character.group.larp.name, larp_name()) self.assertIs(character_assigment.user.username, "ana") self.assertEqual( str(character_assigment), larp_name() + " run 1 - Marie Curie assigned to Ana Garcia")
def test_create_character(self): """ create_character creates a character for a larp. """ group = create_group(example_groups[1]) character = Character(group=group, name=example_characters[0]) self.assertEqual(character.name, example_characters[0]) self.assertIs(character.group, group) self.assertEqual(character.group.name, example_groups[1]) self.assertEqual(character.group.larp.name, larp_name())
def test_create_character_assigment(self): """ create_character_assigment assigns a character to a player on a concrete larp run. """ user = User(username="******", first_name="Ana", last_name="Garcia") group = create_group(example_groups[1]) character = Character(group=group, name=example_characters[0]) character_assigment = CharacterAssigment(run=1, character=character, user=user) self.assertIs(character_assigment.character.group.larp.name, larp_name()) self.assertIs(character_assigment.character.name, example_characters[0]) self.assertIs(character_assigment.character.group.name, example_groups[1]) self.assertIs(character_assigment.user.username, "ana") self.assertEqual( str(character_assigment), larp_name() + " run 1 - Marie Curie assigned to Ana Garcia")
def test_create_character_assigment_without_user(self): """ create_character_assigment assigns a character to a larp run but without an asigned user. This is useful when you have a new character that has no player assigned yet. """ larp = Larp(name=larp_name()) group_name = example_groups[1] group = Group(larp=larp, name=group_name) character = Character(group=group, name="Marie Curie") character_assigment = CharacterAssigment(run=1, character=character) self.assertIs(character_assigment.character.group.larp, larp) self.assertEqual(character_assigment.character.group.larp.name, larp_name()) self.assertIs(character_assigment.character, character) self.assertEqual(character_assigment.character.name, example_characters[0]) self.assertIs(character_assigment.character.group, group) self.assertEqual(character_assigment.character.group.name, example_groups[1]) self.assertEqual(str(character_assigment), larp_name() + " run 1 - Marie Curie")
class CSVCharactersTests(TestCase): csv_type = csv_file_types()[0][0] larp_name = larp_name() # Tests for create users def test_create_user_correct(self): player_name = "Ana Perez" new_user = create_user(player_name) self.assertEqual(new_user.username, "Ana_Perez") self.assertEqual(new_user.first_name, "Ana") self.assertEqual(new_user.last_name, "Perez") def test_create_user_one_name(self): player_name = "Ana" new_user = create_user(player_name) self.assertEqual(new_user.username, "Ana") self.assertEqual(new_user.first_name, "Ana") self.assertEqual(new_user.last_name, "") def test_create_user_empty(self): player_name = "" new_user = create_user(player_name) self.assertEqual(new_user, None) def test_create_user_blank_space(self): player_name = " " new_user = create_user(player_name) self.assertEqual(new_user, None) # Tests for create characters def test_create_character_complete_information(self): character_name = "Athena" group = "Scientists" race = "Terrans" new_character = create_character(self.larp_name, character_name, group, race) self.assertEqual(new_character.name, "Athena") self.assertEqual(new_character.group.name, "Scientists") self.assertEqual(new_character.group.larp.name, self.larp_name) def test_create_character_no_race(self): character_name = "Athena" group = "Scientists" race = "" new_character = create_character(self.larp_name, character_name, group, race) self.assertEqual(new_character.name, "Athena") self.assertEqual(new_character.race.name, "") def test_create_character_no_group(self): character_name = "Athena" group = "" race = "Terrans" new_character = create_character(self.larp_name, character_name, group, race) self.assertEqual(new_character.name, "Athena") self.assertEqual(new_character.group, None) def test_create_character_no_information(self): character_name = "" group = "" race = "" new_character = create_character(self.larp_name, character_name, group, race) self.assertEqual(new_character, None) def test_create_character_only_group_information(self): character_name = "" group = "Scientists" race = "" new_character = create_character(self.larp_name, character_name, group, race) self.assertEqual(new_character.group.name, "Scientists") self.assertEqual(new_character.group.larp.name, self.larp_name) def test_create_character_only_race_information(self): character_name = "" group = "" race = "Terrans" new_character = create_character(self.larp_name, character_name, group, race) self.assertEqual(new_character.race.name, "Terrans") self.assertEqual(new_character.group, None) # Test assign characters to users def test_assign_character_to_user(self): run = 2 user = User(username="******", first_name="Ana") user.save() character = Character(name="Ono") character.save() result = assign_character_to_user(user, character, run) self.assertEqual(result, "Character Ono assigned to Ana ") # Test for processing lines def test_process_csv_line_correct(self): column = [ '1', 'Werner Mikolasch', 'Ono', 'agriculture teacher', 'Rhea', 'lieutenant' ] result = process_csv_line(column, self.csv_type) self.assertEqual(result, 'Character Ono assigned to Werner Mikolasch') def test_process_csv_line_no_user(self): column = ['1', '', 'Fuertes', 'artist teacher', 'Kepler', 'lieutenant'] result = process_csv_line(column, self.csv_type) self.assertEqual(result, 'User invalid') def test_process_csv_line_user_blank_space(self): column = [ '1', ' ', 'Fuertes', 'artist teacher', 'Kepler', 'lieutenant' ] result = process_csv_line(column, self.csv_type) self.assertEqual(result, 'User invalid') def test_process_csv_line_correct_user_but_no_character(self): column = ['2', 'Samuel Bascomb', '', '', '', ''] result = process_csv_line(column, self.csv_type) self.assertEqual(result, 'Created user Samuel Bascomb. Character invalid') def test_process_csv_line_no_user_and_no_character(self): column = ['2', '', '', '', '', ''] result = process_csv_line(column, self.csv_type) self.assertEqual(result, 'User invalid. Character invalid') # Test for processing datasets def test_process_data_without_errors(self): """ process_data() checks that the data from the csv file is processed correctly """ result = process_data(characters_data_set) self.assertEqual(result, [ 'Character Ono assigned to Werner Mikolasch', 'Character Fuertes assigned to Fabio ' ]) def test_process_data_with_invalid_users(self): """ process_data_with_invalid_users() checks that no users are created when the player name is empty or a blank space """ data = """run,player,character,group,planet,rank 1,,Fuertes,artist teacher,Kepler,lieutenant 2, ,Ono,agriculture teacher,Rhea,lieutenant""" result = process_data(data) self.assertEqual(result, ['User invalid', 'User invalid']) def test_process_data_with_wrong_character(self): data = """run,player,character,group,planet,rank 2,Samuel Bascomb,,,,""" result = process_data(data) self.assertEqual(result, ['Created user Samuel Bascomb. Character invalid'])