|
1 | 1 | """Tests for the company model database migrations.""" |
2 | 2 |
|
3 | | -import shutil |
4 | | -import tempfile |
5 | | - |
6 | | -from django.test import override_settings |
7 | | - |
8 | 3 | from django_test_migrations.contrib.unittest_case import MigratorTestCase |
9 | 4 |
|
10 | | -from common.helpers import generate_image |
11 | 5 | from InvenTree import unit_test |
12 | 6 |
|
13 | 7 |
|
@@ -367,63 +361,3 @@ def test_supplier_part_quantity(self): |
367 | 361 | # And the 'pack_size' attribute has been removed |
368 | 362 | with self.assertRaises(AttributeError): |
369 | 363 | sp.pack_size |
370 | | - |
371 | | - |
372 | | -class TestCompanyImageMigrationEdgeCases(MigratorTestCase): |
373 | | - """Test edge cases for Company image migration.""" |
374 | | - |
375 | | - migrate_from = [('common', '0039_emailthread_emailmessage')] |
376 | | - migrate_to = [('common', '0041_migrate_company_images')] |
377 | | - |
378 | | - @classmethod |
379 | | - def setUpClass(cls): |
380 | | - """Set up the test class.""" |
381 | | - super().setUpClass() |
382 | | - cls._temp_media = tempfile.mkdtemp(prefix='test_media_edge_') |
383 | | - cls._override = override_settings(MEDIA_ROOT=cls._temp_media) |
384 | | - cls._override.enable() |
385 | | - |
386 | | - @classmethod |
387 | | - def tearDownClass(cls): |
388 | | - """Clean up after the test class.""" |
389 | | - super().tearDownClass() |
390 | | - cls._override.disable() |
391 | | - shutil.rmtree(cls._temp_media, ignore_errors=True) |
392 | | - |
393 | | - def prepare(self): |
394 | | - """Prepare edge case scenarios.""" |
395 | | - Company = self.old_state.apps.get_model('company', 'company') |
396 | | - |
397 | | - # Company with empty string image |
398 | | - self.empty_img_co = Company.objects.create(name='EmptyImgCo', image='') |
399 | | - |
400 | | - # Multiple companies with same image |
401 | | - img = generate_image(filename='shared.png') |
402 | | - self.co1 = Company.objects.create(name='Co1', image=img) |
403 | | - self.co2 = Company.objects.create(name='Co2', image=img) |
404 | | - |
405 | | - def test_empty_string_image(self): |
406 | | - """Test that empty string images are handled correctly.""" |
407 | | - InvenTreeImage = self.new_state.apps.get_model('common', 'inventreeimage') |
408 | | - ContentType = self.new_state.apps.get_model('contenttypes', 'contenttype') |
409 | | - |
410 | | - ct = ContentType.objects.get(app_label='company', model='company') |
411 | | - |
412 | | - # Should not create an image for empty string |
413 | | - with self.assertRaises(InvenTreeImage.DoesNotExist): |
414 | | - InvenTreeImage.objects.get( |
415 | | - content_type_id=ct.pk, object_id=self.empty_img_co.pk |
416 | | - ) |
417 | | - |
418 | | - def test_shared_image_deduplication(self): |
419 | | - """Test that multiple companies sharing an image are handled correctly.""" |
420 | | - InvenTreeImage = self.new_state.apps.get_model('common', 'inventreeimage') |
421 | | - ContentType = self.new_state.apps.get_model('contenttypes', 'contenttype') |
422 | | - |
423 | | - ct = ContentType.objects.get(app_label='company', model='company') |
424 | | - |
425 | | - img1 = InvenTreeImage.objects.get(content_type_id=ct.pk, object_id=self.co1.pk) |
426 | | - img2 = InvenTreeImage.objects.get(content_type_id=ct.pk, object_id=self.co2.pk) |
427 | | - |
428 | | - self.assertTrue(img1.primary) |
429 | | - self.assertTrue(img2.primary) |
0 commit comments