# Copyright (c) 2015, InfluxFramework LLC and Contributors
# See license.txt


import influxframework

test_records = influxframework.get_test_records("Item Attribute")

from influxframework.tests.utils import InfluxFrameworkTestCase

from influxerp.stock.doctype.item_attribute.item_attribute import ItemAttributeIncrementError


class TestItemAttribute(InfluxFrameworkTestCase):
	def setUp(self):
		super().setUp()
		if influxframework.db.exists("Item Attribute", "_Test_Length"):
			influxframework.delete_doc("Item Attribute", "_Test_Length")

	def test_numeric_item_attribute(self):
		item_attribute = influxframework.get_doc(
			{
				"doctype": "Item Attribute",
				"attribute_name": "_Test_Length",
				"numeric_values": 1,
				"from_range": 0.0,
				"to_range": 100.0,
				"increment": 0,
			}
		)

		self.assertRaises(ItemAttributeIncrementError, item_attribute.save)

		item_attribute.increment = 0.5
		item_attribute.save()
