Skip to content

Commit

Permalink
Tweak unit tests
Browse files Browse the repository at this point in the history
- Skip attachment tests for older API version
  • Loading branch information
SchrodingersGat committed Jun 16, 2024
1 parent 9a7106d commit adc39c3
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 13 deletions.
3 changes: 1 addition & 2 deletions inventree/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ class InvenTreeAPI(object):
Basic class for performing Inventree API requests.
"""

# Ref: https://github.com/inventree/InvenTree/pull/7420
MIN_SUPPORTED_API_VERSION = 207
MIN_SUPPORTED_API_VERSION = 206

@staticmethod
def getMinApiVersion():
Expand Down
3 changes: 3 additions & 0 deletions inventree/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,9 @@ class Attachment(BulkDeleteMixin, InventreeObject):

URL = 'attachment/'

# Ref: https://github.com/inventree/InvenTree/pull/7420
MIN_API_VERSION = 207

@classmethod
def add_link(cls, api, link, comment="", **kwargs):
"""
Expand Down
4 changes: 4 additions & 0 deletions test/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from test_api import InvenTreeTestCase # noqa: E402

from inventree.base import Attachment # noqa: E402
from inventree.build import Build # noqa: E402


Expand Down Expand Up @@ -60,6 +61,9 @@ def test_build_attachment(self):
Test that we can upload an attachment against a Build
"""

if self.api.api_version < Attachment.MIN_API_VERSION:
return

build = self.get_build()

n = len(build.getAttachments())
Expand Down
5 changes: 5 additions & 0 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 @@ -268,6 +269,10 @@ def test_upload_company_image(self):
c.uploadImage(None)

def test_attachments(self):
"""Unit tests for attachments."""

if self.api.api_version < Attachment.MIN_API_VERSION:
return

# Create a new manufacturer part, if one does not already exist
mps = company.ManufacturerPart.list(self.api)
Expand Down
6 changes: 6 additions & 0 deletions test/test_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,9 @@ def test_po_attachment(self):
Test upload of attachment against a PurchaseOrder
"""

if self.api.api_version < Attachment.MIN_API_VERSION:
return

# Ensure we have a least one purchase order to work with
n = len(order.PurchaseOrder.list(self.api))

Expand Down Expand Up @@ -498,6 +501,9 @@ def test_so_attachment(self):
Test upload of attachment against a SalesOrder
"""

if self.api.api_version < Attachment.MIN_API_VERSION:
return

# Grab the first available SalesOrder
orders = order.SalesOrder.list(self.api)

Expand Down
29 changes: 18 additions & 11 deletions test/test_part.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,22 @@ def test_part_get_functions(self):
# Get list of parts
parts = Part.list(self.api)

functions = {
'getSupplierParts': SupplierPart,
'getBomItems': BomItem,
'isUsedIn': BomItem,
'getStockItems': StockItem,
'getParameters': Parameter,
'getRelated': PartRelated,
'getInternalPriceList': InternalPrice,
}

if self.api.api_version >= Attachment.MIN_API_VERSION:
functions['getAttachments'] = Attachment

# For each part in list, test some functions
for p in parts:
functions = {
'getSupplierParts': SupplierPart,
'getBomItems': BomItem,
'isUsedIn': BomItem,
'getStockItems': StockItem,
'getParameters': Parameter,
'getRelated': PartRelated,
'getInternalPriceList': InternalPrice,
'getAttachments': Attachment,
}

for fnc, res in functions.items():
A = getattr(p, fnc)()
# Make sure a list is returned
Expand Down Expand Up @@ -301,7 +305,7 @@ def test_part_edit(self):

name = p.name

# Ajdust the name
# Adjust the name
if len(name) < 40:
name += '_append'
else:
Expand Down Expand Up @@ -457,6 +461,9 @@ def test_part_attachment(self):
Check that we can upload attachment files against the part
"""

if self.api.api_version < Attachment.MIN_API_VERSION:
return

prt = Part(self.api, pk=1)
attachments = prt.getAttachments()

Expand Down

0 comments on commit adc39c3

Please sign in to comment.