From 98eeb0c299b2bb3ee38a4c97eba21f16766b7799 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 11 Jun 2024 23:15:39 +1000 Subject: [PATCH] Update unit tests --- test/test_build.py | 49 +++----------------------------------------- test/test_company.py | 5 +++-- test/test_order.py | 5 +++-- 3 files changed, 9 insertions(+), 50 deletions(-) diff --git a/test/test_build.py b/test/test_build.py index 5e9e8ea..8453a51 100644 --- a/test/test_build.py +++ b/test/test_build.py @@ -11,7 +11,8 @@ from test_api import InvenTreeTestCase # noqa: E402 -from inventree.build import Build, BuildAttachment # noqa: E402 +from inventree.base import Attachment # noqa: E402 +from inventree.build import Build # noqa: E402 class BuildOrderTest(InvenTreeTestCase): @@ -62,7 +63,7 @@ def test_build_attachment(self): build = self.get_build() - n = len(BuildAttachment.list(self.api, build=build.pk)) + n = len(build.getAttachments()) # Upload *this* file fn = os.path.join(os.path.dirname(__file__), 'test_build.py') @@ -74,50 +75,6 @@ def test_build_attachment(self): self.assertEqual(len(build.getAttachments()), n + 1) - def test_build_attachment_bulk_delete(self): - """Test 'bulk delete' operation for the BuildAttachment class""" - - build = self.get_build() - - n = len(BuildAttachment.list(self.api, build=build.pk)) - - fn = os.path.join(os.path.dirname(__file__), 'test_build.py') - - pk_values = [] - - # Create a number of new attachments - for i in range(10): - response = build.uploadAttachment(fn, comment=f"Build attachment {i}") - pk_values.append(response['pk']) - - self.assertEqual(len(BuildAttachment.list(self.api, build=build.pk)), n + 10) - - # Call without providing required arguments - with self.assertRaises(ValueError): - BuildAttachment.bulkDelete(self.api) - - BuildAttachment.bulkDelete(self.api, items=pk_values) - - # The number of attachments has been reduced to the original value - self.assertEqual(len(BuildAttachment.list(self.api, build=build.pk)), n) - - # Now, delete using the 'filters' argument - for i in range(99, 109): - response = build.uploadAttachment(fn, comment=f"Build attachment {i}") - pk_values.append(response['pk']) - - self.assertEqual(len(BuildAttachment.list(self.api, build=build.pk)), n + 10) - - response = BuildAttachment.bulkDelete( - self.api, - filters={ - "build": build.pk, - } - ) - - # All attachments for this Build should have been deleted - self.assertEqual(len(BuildAttachment.list(self.api, build=build.pk)), 0) - def test_build_cancel(self): """ Test cancelling a build order. diff --git a/test/test_company.py b/test/test_company.py index 61a6b77..30ee552 100644 --- a/test/test_company.py +++ b/test/test_company.py @@ -14,6 +14,7 @@ from test_api import InvenTreeTestCase # noqa: E402 +from inventree.base import Attachment # noqa: E402 from inventree import company # noqa: E402 from inventree.part import Part # noqa: E402 @@ -285,7 +286,7 @@ def test_attachments(self): for attachment in mp.getAttachments(): attachment.delete() - attachments = company.ManufacturerPartAttachment.list(self.api, manufacturer_part=mp.pk) + attachments = mp.getAttachments() self.assertTrue(len(attachments) == 0) @@ -300,7 +301,7 @@ def test_attachments(self): self.assertIsNotNone(response) - attachments = company.ManufacturerPartAttachment.list(self.api) + attachments = mp.getAttachments() self.assertEqual(len(attachments), 1) diff --git a/test/test_order.py b/test/test_order.py index a080e24..68b4d13 100644 --- a/test/test_order.py +++ b/test/test_order.py @@ -9,6 +9,7 @@ from test_api import InvenTreeTestCase # noqa: E402 +from inventree.base import Attachment # noqa: E402 from inventree import company # noqa: E402 from inventree import order # noqa: E402 from inventree import part # noqa: E402 @@ -516,12 +517,12 @@ def test_so_attachment(self): pk = response['pk'] - attachment = order.SalesOrderAttachment(self.api, pk=pk) + attachment = Attachment(self.api, pk=pk) self.assertEqual(attachment.order, so.pk) self.assertEqual(attachment.comment, 'Sales order attachment') - attachments = order.SalesOrderAttachment.list(self.api, order=so.pk) + attachments = order.getAttachments() self.assertEqual(len(attachments), n + 1) def test_so_shipment(self):