Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SchrodingersGat committed Jun 11, 2024
1 parent bc29633 commit 98eeb0c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 50 deletions.
49 changes: 3 additions & 46 deletions test/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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')
Expand All @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions test/test_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand Down
5 changes: 3 additions & 2 deletions test/test_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 98eeb0c

Please sign in to comment.