Skip to content

Commit

Permalink
Added unit tests. #1659
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdspencer77 committed Feb 27, 2025
1 parent 79f1e33 commit cf87194
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6673,7 +6673,6 @@ class product(JSONEndpoint):

def controller(self, o):
dbo = o.dbo
username = o.user
#asm3.al.debug("publish started for mode %s" % mode, "main.publish", dbo)
productid = 0
if o.post["id"]:
Expand Down
55 changes: 55 additions & 0 deletions unittest/test_stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class TestStock(unittest.TestCase):
nid = 0

def setUp(self):

# Create a stocklevel
data = {
"name": "Test Stock",
"description": "Test Description",
Expand All @@ -25,9 +27,46 @@ def setUp(self):
post = asm3.utils.PostedData(data, "en")
self.nid = asm3.stock.insert_stocklevel_from_form(base.get_dbo(), post, "test")

# Create a supplier
data = {
"title": "Mr",
"forenames": "Test",
"surname": "Testing",
"ownertype": "1",
"address": "123 test street",
"flags": "supplier"
}
post = asm3.utils.PostedData(data, "en")
self.sid = asm3.person.insert_person_from_form(base.get_dbo(), post, "test", geocode=False)

# Create a product type
self.tid = asm3.lookups.insert_lookup(base.get_dbo(), "test", "lkproducttype", "Test Product Type", "Just for testing")

# Create a stock location
self.lid = asm3.lookups.insert_lookup(base.get_dbo(), "test", "stocklocation", "Test Stock Location", "Just for testing")

# Create a stock usage type
self.uid = asm3.lookups.insert_lookup(base.get_dbo(), "test", "stockusagetype", "Test Usage Type", "Just for testing")

# Create a product to test
data = {
"productname": "Test Product",
"description": "Test Description",
"producttypeid": "1",
"supplierid": str(self.sid),
"taxrateid": "1"
}
post = asm3.utils.PostedData(data, "en")
self.pid = asm3.stock.insert_product_from_form(base.get_dbo(), post, "test")

def tearDown(self):
base.execute("DELETE FROM stockusage WHERE StockLevelID = %d" % self.nid)
asm3.stock.delete_stocklevel(base.get_dbo(), "test", self.nid)
base.execute("DELETE FROM owner WHERE ID = %d" % self.sid)
base.execute("DELETE FROM lkproducttype WHERE ID = %d" % self.tid)
base.execute("DELETE FROM product WHERE ID = %d" % self.pid)
base.execute("DELETE FROM stocklocation WHERE ID = %d" % self.lid)
base.execute("DELETE FROM stockusagetype WHERE ID = %d" % self.uid)

def test_get_stocklevel(self):
self.assertIsNotNone(asm3.stock.get_stocklevel(base.get_dbo(), self.nid))
Expand Down Expand Up @@ -55,6 +94,22 @@ def test_get_stock_locations_totals(self):

def test_get_stock_units(self):
self.assertNotEqual(0, len(asm3.stock.get_stock_units(base.get_dbo())))

def test_move_product(self):
data = {
"movementdate": base.today_display(),
"producttypeid": str(self.tid),
"movementfromtype" : "0",
"movementfromtype" : "1",
"movementquantity": "1",
"unitratio": "1",
"productid": str(self.pid),
"movementfrom": str(self.lid),
"movementto": str(self.uid),
"comments": "A test movement"
}
post = asm3.utils.PostedData(data, "en")
asm3.stock.insert_productmovement_from_form(base.get_dbo(), "test", post)

def test_update_stocklevel_from_form(self):
data = {
Expand Down

0 comments on commit cf87194

Please sign in to comment.