def LibraryFactory(**kwargs): map_color_to_land = { GREEN: Forest, RED: Mountain, BLUE: Island, BLACK: Swamp, WHITE: Plains, } colors = kwargs.get('colors', 'red') land_data = kwargs.get('land_data', []) if not land_data: land_data = [{'number': 20, 'color': RED}] lands = [] for ld in land_data: cls = map_color_to_land[ld['color']] for _ in range(0, ld['number']): lands.append(cls()) bulk_create = kwargs.get('bulk_create', 1) if bulk_create == 1: return Library(colors, lands) libraries_list = [] for index in range(0, bulk_create): libraries_list.append(Library(colors, lands)) return libraries_list
def test_override_data_to_update_library_and_made_invalid( field_name, invalid_data): lands = [Mountain()] creatures = [CreatureCardFactory(color='red')] library = Library('red', lands=lands, creatures=creatures) setattr(library, field_name, invalid_data) assert not library.is_valid()
def test_append_creatures_to_library(): lands = [Mountain()] creatures = [CreatureCardFactory(color='red')] library = Library('red', lands=lands, creatures=creatures) assert library.is_valid() assert 1 == len(library.lands) assert 1 == len(library.creatures) assert 2 == len(library.cards)
def test_override_data_to_update_library_and_raise_exception( expected_exception, field_name, invalid_data): lands = [Mountain()] creatures = [CreatureCardFactory(color='red')] library = Library('red', lands=lands, creatures=creatures) setattr(library, field_name, invalid_data) with pytest.raises(expected_exception): library.is_valid(raise_exception=True)
def test_valid_instance_library(): lands = [Mountain(), Forest()] library = Library('red,green', lands=lands) assert 'green,red' == str(library) assert '<Library green,red>' == repr(library) assert 2 == len(library.lands)
def test_invalid_color_instance_library(invalid_colors): with pytest.raises(InvalidColorError): Library(invalid_colors)
def test_valid_number_and_type_lands_instance_library(): lands = [Mountain(), Forest(), Island(), Plains(), Swamp()] library = Library('red', lands=lands) assert 5 == len(library.lands)
def test_invalid_type_of_land_instance_library(): lands = ['land1', Mountain()] with pytest.raises(InvalidLandError): Library('red', lands=lands)
def test_valid_colors_instance_library(expected_colors, valid_colors): library = Library(valid_colors) assert expected_colors == library.colors