def cost_card(self, color=None, cost_card_str=None): if cost_card_str: return CostCard(cost_card_str) if color is None: color = _faker.random_choices(VALID_COLORS)[0] digit = _faker.random_digit_not_null() return CostCard(f'{color}:{digit}')
def CreatureCardFactory(**kwargs): name = kwargs.get('name', _faker.name()) description = kwargs.get('description', _faker.text()) colors = kwargs.get('colors', [_faker.color()]) cost = kwargs.get('cost', _faker.cost_card(colors[0])) power_toughness = kwargs.get('power_toughness', _faker.power_toughness()) image_uris = kwargs.get('image_uris') if isinstance(cost, str): cost = CostCard(cost) bulk_create = kwargs.get('bulk_create', 1) if bulk_create == 1: return CreatureCard(name=name, description=description, cost=cost, colors=colors, power_toughness=power_toughness, image_uris=image_uris) creature_cards_list = [] for index in range(0, bulk_create): card = CreatureCard(name=name, description=description, cost=cost, colors=colors, power_toughness=power_toughness, image_uris=image_uris) creature_cards_list.append(card) return creature_cards_list
def test_invalid_instance_base_card_by_color(): cost = CostCard('red:1') base_card = BaseCard(name='Card name', description='Long text...', cost=cost, colors=['brown']) with pytest.raises(InvalidCardError): base_card.is_valid() assert 'colors' in base_card.errors
def test_is_valid_instance_base_card(): cost = CostCard('red:1') base_card = BaseCard(name='Card name', description='Long text...', cost=cost, colors=['red']) assert base_card.is_valid() assert f'<BaseCard Card name>' == repr(base_card) assert 'Card name (red:1)' == str(base_card) assert base_card._id assert 'Card name' == base_card.name assert 'Long text...' == base_card.description assert 'red:1' == str(base_card.cost) assert cost == base_card.cost assert isinstance(base_card.cost, CostCard) assert ['red'] == base_card.colors
def test_is_valid_instance_creature_card(): cost = CostCard('red:1') creature_card = CreatureCard(name='Card name', description='Long text...', cost=cost, colors=['red'], power_toughness='1/1') assert creature_card.is_valid() assert creature_card._id assert f'<CreatureCard Card name (red:1)>' == repr(creature_card) assert 'Card name - 1/1 (red:1)' == str(creature_card) assert 'Card name' == creature_card.name assert 'Long text...' == creature_card.description assert 'red:1' == str(creature_card.cost) assert cost == creature_card.cost assert isinstance(creature_card.cost, CostCard) assert ['red'] == creature_card.colors assert '1/1' == creature_card.power_toughness assert None is creature_card.image_uris
assert {'foo': 'bar'} == creature_card.image_uris @pytest.mark.parametrize('field_name,custom_value', [ ('name', 'Custom name'), ('description', 'Custom description'), ('power_toughness', '5/5'), ]) def test_custom_simple_data_creature_card_factory(field_name, custom_value): creature_card = CreatureCardFactory(**{field_name: custom_value}) assert custom_value == getattr(creature_card, field_name) @pytest.mark.parametrize('cost_card_value', ['red:1', CostCard('red:1')]) def test_custom_cost_card_data_creature_card_factory(cost_card_value): creature_card = CreatureCardFactory(cost=cost_card_value) assert str(cost_card_value) == str(creature_card.cost) assert isinstance(creature_card.cost, CostCard) def test_invalid_color_creature_card_factory(): with pytest.raises(InvalidColorError): CreatureCardFactory(colors=['brown']) def test_valid_library_factory(): library = LibraryFactory()
def test_raise_exception_by_invalid_instance_cost_card(): with pytest.raises(InvalidCostError): CostCard('black')
def test_invalid_cost_str(cost): assert not CostCard._validate_cost_str(cost)
def test_validate_get_sanitized_cost_by_color(): cost_card = CostCard('incolor:x;red:1') assert 'x' == cost_card['incolor'] assert 1 == cost_card['red']
def test_valid_instance_cost_card(cost_str): cost_card = CostCard(cost_str) assert f'<CostCard {cost_str}>' == repr(cost_card) assert cost_str == str(cost_card)