def test_validate_sku(self, db): """Raise ValidationError if SKU already exists in db.""" packet = Packet() cultivar = Cultivar() db.session.add_all([packet, cultivar]) packet.sku = '8675309' cultivar.name = 'Jenny' packet.cultivar = cultivar db.session.commit() form = AddPacketForm(cultivar=cultivar) form.sku.data = '8675309' with pytest.raises(ValidationError): form.validate_sku(form.sku)
def test_validate_quantity(self, app): """Raise ValidationError if quantity can't be parsed.""" field = mock.MagicMock() field.data = "100" AddPacketForm.validate_quantity(None, field) field.data = "2.3423" AddPacketForm.validate_quantity(None, field) field.data = "3/4" AddPacketForm.validate_quantity(None, field) field.data = "1 1/2" AddPacketForm.validate_quantity(None, field) field.data = "$2" with pytest.raises(ValidationError): AddPacketForm.validate_quantity(None, field) field.data = "3/4/13" with pytest.raises(ValidationError): AddPacketForm.validate_quantity(None, field) field.data = "127.0.0.1" with pytest.raises(ValidationError): AddPacketForm.validate_quantity(None, field)