def test_image_queryset_existing_device_firmware(self):
     (
         device,
         device_fw,
         img_org2,
         yuncore,
         mesh_image,
     ) = self._prepare_image_qs_test_env()
     # existing DeviceFirmware
     # restricts images to category of image in used
     form = DeviceFirmwareForm(device=device, instance=device_fw)
     self.assertEqual(form.fields['image'].queryset.count(), 1)
     self.assertIn(device_fw.image, form.fields['image'].queryset)
     self.assertNotIn(img_org2, form.fields['image'].queryset)
 def test_image_queryset_new_device_firmware(self):
     (
         device,
         device_fw,
         img_org2,
         yuncore,
         mesh_image,
     ) = self._prepare_image_qs_test_env()
     # new DeviceFirmware
     # shows all the categories related to the model
     form = DeviceFirmwareForm(device=device)
     self.assertEqual(form.fields['image'].queryset.count(), 2)
     self.assertIn(device_fw.image, form.fields['image'].queryset)
     self.assertIn(mesh_image, form.fields['image'].queryset)
     self.assertNotIn(img_org2, form.fields['image'].queryset)
 def test_image_queryset_no_model(self):
     (
         device,
         device_fw,
         img_org2,
         yuncore,
         mesh_image,
     ) = self._prepare_image_qs_test_env()
     # existing DeviceFirmware
     # if no model specified, get all models available
     device.model = ''
     device.save()
     form = DeviceFirmwareForm(device=device, instance=device_fw)
     self.assertEqual(form.fields['image'].queryset.count(), 2)
     self.assertIn(yuncore, form.fields['image'].queryset)
     self.assertNotIn(img_org2, form.fields['image'].queryset)
 def test_image_queryset_no_model_nor_device_firmware(self):
     (
         device,
         device_fw,
         img_org2,
         yuncore,
         mesh_image,
     ) = self._prepare_image_qs_test_env()
     # new DeviceFirmware, no model
     # returns all devices of the org
     device.model = ''
     device.save()
     form = DeviceFirmwareForm(device=device)
     self.assertEqual(form.fields['image'].queryset.count(), 3)
     self.assertIn(device_fw.image, form.fields['image'].queryset)
     self.assertIn(mesh_image, form.fields['image'].queryset)
     self.assertIn(yuncore, form.fields['image'].queryset)
     self.assertNotIn(img_org2, form.fields['image'].queryset)