forked from inventree/inventree-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_project_codes.py
More file actions
47 lines (32 loc) · 1.24 KB
/
test_project_codes.py
File metadata and controls
47 lines (32 loc) · 1.24 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
"""Unit tests for the ProjectCode model"""
import os
import sys
sys.path.append(os.path.abspath(os.path.dirname(__file__)))
from test_api import InvenTreeTestCase # noqa: E402
from inventree.project_code import ProjectCode # noqa: E402
class ProjectCodeTest(InvenTreeTestCase):
"""Tests for the ProjectCode model."""
def test_project_code_create(self):
"""Test we can create a new project code."""
n = ProjectCode.count(self.api)
ProjectCode.create(self.api, {
'code': f'TEST {n + 1}',
'description': 'Test project code',
})
self.assertEqual(ProjectCode.count(self.api), n + 1)
# Try to create a duplicate code
with self.assertRaises(Exception):
ProjectCode.create(self.api, {
'code': f'TEST {n + 1}',
'description': 'Test project code',
})
n = ProjectCode.count(self.api)
# Create 5 more codes
for idx in range(5):
ProjectCode.create(self.api, {
'code': f'CODE-{idx + n}',
'description': f'Description {idx + n}',
})
# List all codes
codes = ProjectCode.list(self.api)
self.assertEqual(len(codes), n + 5)