@@ -144,3 +144,55 @@ def test_build_complete(self):
144144 # Check status
145145 self .assertEqual (build .status , 40 )
146146 self .assertEqual (build .status_text , 'Complete' )
147+
148+
149+ class BuildOrderOutputTests (InvenTreeTestCase ):
150+ """ Unit tests for build output functionality """
151+
152+ def setUp (self ):
153+ """ Ensure we have a base build order to work with """
154+
155+ super ().setUp ()
156+
157+ builds = Build .list (self .api )
158+
159+ self .build = Build .create (
160+ self .api ,
161+ {
162+ "title" : "A new build order" ,
163+ "part" : 25 ,
164+ "quantity" : 10 ,
165+ "reference" : f"BO-{ len (builds ) + 1 :04d} "
166+ }
167+ )
168+
169+ def test_create_build_output (self ):
170+ """Test that we can create a build output item"""
171+
172+ # Initially, there should be no build outputs
173+ outputs = self .build .getBuildOutputs ()
174+ self .assertEqual (len (outputs ), 0 )
175+
176+ # Let's create 3 new outputs (with serial numbers)
177+ outputs = self .build .createBuildOutput (
178+ quantity = 3 ,
179+ batch_code = 'TEST-BATCH-001' ,
180+ serial_numbers = '300+'
181+ )
182+
183+ self .assertEqual (len (outputs ), 3 )
184+ self .assertEqual (len (self .build .getBuildOutputs ()), 3 )
185+
186+ for output in outputs :
187+ self .assertIsNotNone (output )
188+ self .assertEqual (output .quantity , 1 )
189+ self .assertEqual (output .batch , 'TEST-BATCH-001' )
190+ self .assertEqual (output .build , self .build .pk )
191+ self .assertEqual (output .part , self .build .part )
192+ self .assertTrue (output .is_building )
193+
194+ # Directly delete the build output
195+ output .delete ()
196+
197+ # There should now be no build outputs again
198+ self .assertEqual (len (self .build .getBuildOutputs ()), 0 )
0 commit comments