def setUp(self): super().setUp() self.pclass = ProductClassFactory(name='T-Shirts', slug='tshirts') for attribute_type, __ in ProductAttribute.TYPE_CHOICES: values = { 'type': attribute_type, 'code': attribute_type, 'product_class': self.pclass, 'name': attribute_type, } if attribute_type == ProductAttribute.OPTION: option_group = factories.AttributeOptionGroupFactory() self.option = factories.AttributeOptionFactory( group=option_group) values['option_group'] = option_group elif attribute_type == ProductAttribute.MULTI_OPTION: option_group = factories.AttributeOptionGroupFactory() self.multi_option = factories.AttributeOptionFactory( group=option_group) values['option_group'] = option_group ProductAttributeFactory(**values) self.product = factories.ProductFactory(product_class=self.pclass) self.url = reverse('dashboard:catalogue-product', kwargs={'pk': self.product.id})
def test_validating_option_attribute(self): option_group = factories.AttributeOptionGroupFactory() option_1 = factories.AttributeOptionFactory(group=option_group) option_2 = factories.AttributeOptionFactory(group=option_group) pa = factories.ProductAttribute(type='option', option_group=option_group) self.assertRaises(ValidationError, pa.validate_value, 'invalid') pa.validate_value(option_1) pa.validate_value(option_2) invalid_option = AttributeOption(option='invalid option') self.assertRaises(ValidationError, pa.validate_value, invalid_option)