|
| 1 | +from django.test import TestCase |
| 2 | + |
| 3 | +from core.management.commands.generate_artworks import ( |
| 4 | + Command as GenerateArtworksCommand, |
| 5 | +) |
| 6 | +from core.management.commands.generate_exhibits import ( |
| 7 | + Command as GenerateExhibitsCommand, |
| 8 | +) |
| 9 | +from core.management.commands.generate_markers import Command as GenerateMarkersCommand |
| 10 | +from core.management.commands.generate_objects import Command as GenerateObjectsCommand |
| 11 | +from core.models import Artwork, Exhibit, Marker, Object |
| 12 | + |
| 13 | + |
| 14 | +class TestGenerateObjectsCommand(TestCase): |
| 15 | + def test_generate_objects_command(self): |
| 16 | + command = GenerateObjectsCommand() |
| 17 | + command.handle(count=1) |
| 18 | + # Check if an object was created |
| 19 | + self.assertEqual(Object.objects.count(), 1) |
| 20 | + obj = Object.objects.first() |
| 21 | + self.assertIsNotNone(obj) |
| 22 | + self.assertIsNotNone(obj.owner) |
| 23 | + self.assertIsNotNone(obj.title) |
| 24 | + self.assertIsNotNone(obj.source) |
| 25 | + self.assertIsNotNone(obj.file_extension) |
| 26 | + self.assertIsNotNone(obj.file_name_original) |
| 27 | + self.assertIsNotNone(obj.file_size) |
| 28 | + |
| 29 | + def test_generate_multiple(self): |
| 30 | + command = GenerateObjectsCommand() |
| 31 | + command.handle(count=5) |
| 32 | + # Check if 5 objects were created |
| 33 | + self.assertEqual(Object.objects.count(), 5) |
| 34 | + for obj in Object.objects.all(): |
| 35 | + self.assertIsNotNone(obj.owner) |
| 36 | + self.assertIsNotNone(obj.title) |
| 37 | + self.assertIsNotNone(obj.source) |
| 38 | + self.assertIsNotNone(obj.file_extension) |
| 39 | + self.assertIsNotNone(obj.file_name_original) |
| 40 | + self.assertIsNotNone(obj.file_size) |
| 41 | + |
| 42 | + |
| 43 | +class TestGenerateMarkersCommand(TestCase): |
| 44 | + def test_generate_markers_command(self): |
| 45 | + command = GenerateMarkersCommand() |
| 46 | + command.handle(count=1) |
| 47 | + # Check if a marker was created |
| 48 | + self.assertEqual(Marker.objects.count(), 1) |
| 49 | + marker = Marker.objects.first() |
| 50 | + self.assertIsNotNone(marker) |
| 51 | + self.assertIsNotNone(marker.title) |
| 52 | + |
| 53 | + def test_generate_multiple_markers(self): |
| 54 | + command = GenerateMarkersCommand() |
| 55 | + command.handle(count=3) |
| 56 | + # Check if 3 markers were created |
| 57 | + self.assertEqual(Marker.objects.count(), 3) |
| 58 | + for marker in Marker.objects.all(): |
| 59 | + self.assertIsNotNone(marker.title) |
| 60 | + |
| 61 | + |
| 62 | +class TestGenerateArtworksCommand(TestCase): |
| 63 | + def test_generate_artworks_command(self): |
| 64 | + command = GenerateArtworksCommand() |
| 65 | + command.handle(count=1) |
| 66 | + # Check if an artwork was created |
| 67 | + self.assertEqual(Artwork.objects.count(), 1) |
| 68 | + artwork = Artwork.objects.first() |
| 69 | + self.assertIsNotNone(artwork) |
| 70 | + self.assertIsNotNone(artwork.title) |
| 71 | + self.assertIsNotNone(artwork.description) |
| 72 | + self.assertEqual( |
| 73 | + Object.objects.count(), 1 |
| 74 | + ) # Ensure an object is created as well |
| 75 | + self.assertEqual( |
| 76 | + Marker.objects.count(), 1 |
| 77 | + ) # Ensure a marker is created as well |
| 78 | + self.assertIsNotNone(artwork.augmented) |
| 79 | + self.assertIsNotNone(artwork.marker) |
| 80 | + |
| 81 | + def test_generate_multiple_artworks(self): |
| 82 | + command = GenerateArtworksCommand() |
| 83 | + command.handle(count=3) |
| 84 | + # Check if 3 artworks were created |
| 85 | + self.assertEqual(Artwork.objects.count(), 3) |
| 86 | + for artwork in Artwork.objects.all(): |
| 87 | + self.assertIsNotNone(artwork.title) |
| 88 | + self.assertIsNotNone(artwork.description) |
| 89 | + self.assertIsNotNone(artwork.augmented) |
| 90 | + self.assertIsNotNone(artwork.marker) |
| 91 | + self.assertEqual(Object.objects.count(), 3) |
| 92 | + self.assertEqual(Marker.objects.count(), 3) |
| 93 | + |
| 94 | + |
| 95 | +class TestGenerateExhibitsCommand(TestCase): |
| 96 | + def test_generate_exhibits_command(self): |
| 97 | + command = GenerateExhibitsCommand() |
| 98 | + command.handle(count=1) |
| 99 | + # Check if an exhibit was created |
| 100 | + self.assertEqual(Exhibit.objects.count(), 1) |
| 101 | + exhibit = Exhibit.objects.first() |
| 102 | + self.assertIsNotNone(exhibit) |
| 103 | + self.assertIsNotNone(exhibit.name) |
| 104 | + self.assertIsNotNone(exhibit.artworks) |
| 105 | + self.assertGreater( |
| 106 | + exhibit.artworks.count(), 0 |
| 107 | + ) # Ensure at least one artwork is associated |
| 108 | + |
| 109 | + def test_generate_multiple_exhibits(self): |
| 110 | + command = GenerateExhibitsCommand() |
| 111 | + command.handle(count=2) |
| 112 | + # Check if 2 exhibits were created |
| 113 | + self.assertEqual(Exhibit.objects.count(), 2) |
| 114 | + for exhibit in Exhibit.objects.all(): |
| 115 | + self.assertIsNotNone(exhibit.name) |
| 116 | + self.assertGreater(exhibit.artworks.count(), 0) |
0 commit comments