forked from inventree/inventree-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_label.py
More file actions
71 lines (48 loc) · 2.16 KB
/
test_label.py
File metadata and controls
71 lines (48 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# -*- coding: utf-8 -*-
import os
import sys
sys.path.append(os.path.abspath(os.path.dirname(__file__)))
from test_api import InvenTreeTestCase # noqa: E402
from inventree.label import LabelTemplate # noqa: E402
from inventree.part import Part # noqa: E402
from inventree.plugin import InvenTreePlugin # noqa: E402
class LabelTemplateTests(InvenTreeTestCase):
"""Unit tests for label templates and printing, using the modern API."""
def test_label_template_list(self):
"""List available label templates."""
n = LabelTemplate.count(self.api)
templates = LabelTemplate.list(self.api)
self.assertEqual(n, len(templates))
self.assertGreater(len(templates), 0)
# Check some expected attributes
for attr in ['name', 'description', 'enabled', 'model_type', 'template']:
for template in templates:
self.assertIn(attr, template)
for idx, template in enumerate(templates):
enabled = idx > 0
if template.enabled != enabled:
template.save(data={'enabled': idx > 0})
# Filter by 'enabled' status
templates = LabelTemplate.list(self.api, enabled=True)
self.assertGreater(len(templates), 0)
self.assertLess(len(templates), n)
# Filter by 'disabled' status
templates = LabelTemplate.list(self.api, enabled=False)
self.assertGreater(len(templates), 0)
self.assertLess(len(templates), n)
def test_label_print(self):
"""Print a template!"""
# Find a part to print
part = Part.list(self.api, limit=1)[0]
templates = part.getLabelTemplates()
self.assertGreater(len(templates), 0)
template = templates[0]
# Find an available plugin
plugins = InvenTreePlugin.list(self.api, active=True, mixin='labels')
self.assertGreater(len(plugins), 0)
plugin = plugins[0]
response = part.printLabel(template, plugin=plugin)
for key in ['created', 'complete', 'output']:
self.assertIn(key, response)
self.assertEqual(response['complete'], True)
self.assertIsNotNone(response['output'])