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


import xhiveframework

test_records = xhiveframework.get_test_records("Item Attribute")

from xhiveframework.tests.utils import XhiveframeworkTestCase

from xhiveerp.stock.doctype.item_attribute.item_attribute import ItemAttributeIncrementError


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

	def test_numeric_item_attribute(self):
		item_attribute = xhiveframework.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()
