Skip to content

Commit

Permalink
Update unit tests (#229)
Browse files Browse the repository at this point in the history
* Update unit tests

- Add test for plugin lookup via "key" attribute

* PEP fix

* Fix for plugin key lookup
  • Loading branch information
SchrodingersGat authored May 15, 2024
1 parent 98a53ac commit 6a92ac1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion inventree/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def printLabelModern(self, template, plugin=None, destination=None, *args, **kwa
if type(plugin) is str:
pass
elif hasattr(plugin, 'key'):
plugin = int(plugin.key)
plugin = plugin.key
else:
raise ValueError(f"Invalid plugin provided: {type(plugin)}")

Expand Down
28 changes: 24 additions & 4 deletions test/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,30 @@
class PluginTest(InvenTreeTestCase):
"""Unit tests for plugin functionality."""

def test_plugin_lookup(self):
"""Test plugin lookup by key."""

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

plugins = InvenTreePlugin.list(self.api)

self.assertGreater(len(plugins), 0)

p1 = plugins[0]

# Access the plugin via primary key value
p2 = InvenTreePlugin(self.api, p1.key)

self.assertEqual(p1.key, p2.key)
self.assertEqual(p1.name, p2.name)

self.assertEqual(p1._data['pk'], p2._data['pk'])

def test_plugin_list(self):
"""Test plugin list API."""

if self.api.api_version < 197:
if self.api.api_version < InvenTreePlugin.MIN_API_VERSION:
return

plugins = InvenTreePlugin.list(self.api)
Expand All @@ -41,7 +61,7 @@ def test_plugin_list(self):
def test_filter_by_active(self):
"""Filter by plugin active status."""

if self.api.api_version < 197:
if self.api.api_version < InvenTreePlugin.MIN_API_VERSION:
return

plugins = InvenTreePlugin.list(self.api, active=True)
Expand All @@ -55,7 +75,7 @@ def test_filter_by_active(self):
def test_filter_by_builtin(self):
"""Filter by plugin builtin status."""

if self.api.api_version < 197:
if self.api.api_version < InvenTreePlugin.MIN_API_VERSION:
return

plugins = InvenTreePlugin.list(self.api, builtin=True)
Expand All @@ -67,7 +87,7 @@ def test_filter_by_builtin(self):
def test_filter_by_mixin(self):
"""Test that we can filter by 'mixin' attribute."""

if self.api.api_version < 197:
if self.api.api_version < InvenTreePlugin.MIN_API_VERSION:
return

n = InvenTreePlugin.count(self.api)
Expand Down
4 changes: 2 additions & 2 deletions test/test_project_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@


class ProjectCodeTest(InvenTreeTestCase):
"""Tests for the ProjectCode model"""
"""Tests for the ProjectCode model."""

def test_project_code_create(self):
"""Test we can create a new project code"""
"""Test we can create a new project code."""

n = ProjectCode.count(self.api)

Expand Down

0 comments on commit 6a92ac1

Please sign in to comment.