@@ -55,6 +55,9 @@ def setUp(self):
55
55
pass
56
56
57
57
def test_integer_choices (self ):
58
+ self .do_test_integer_choices ()
59
+
60
+ def do_test_integer_choices (self ):
58
61
59
62
EnumTester .objects .create (dj_int_enum = DJIntEnum .ONE )
60
63
EnumTester .objects .create (dj_int_enum = DJIntEnum .TWO )
@@ -84,6 +87,9 @@ def test_integer_choices(self):
84
87
EnumTester .objects .all ().delete ()
85
88
86
89
def test_text_choices (self ):
90
+ self .do_test_text_choices ()
91
+
92
+ def do_test_text_choices (self ):
87
93
88
94
EnumTester .objects .create (dj_text_enum = DJTextEnum .A )
89
95
EnumTester .objects .create (dj_text_enum = DJTextEnum .B )
@@ -1530,3 +1536,78 @@ def test_migration_test_marker_tag():
1530
1536
assert MIGRATION_TEST_MARKER in TestRemoveBlackMigration .tags
1531
1537
assert MIGRATION_TEST_MARKER in TestRemoveIntEnumMigration .tags
1532
1538
assert MIGRATION_TEST_MARKER in TestAddIntEnumMigration .tags
1539
+
1540
+
1541
+ class TestOptionalDependencies (TestChoices ):
1542
+
1543
+ def test_django_filters_missing (self ):
1544
+ import sys
1545
+ from unittest .mock import patch
1546
+ from importlib import reload
1547
+
1548
+ with patch .dict (sys .modules , {'django_filters' : None }):
1549
+ reload (sys .modules ['django_enum.filters' ])
1550
+ from django_enum .filters import (
1551
+ FilterSet as EnumFilterSet ,
1552
+ EnumFilter
1553
+ )
1554
+
1555
+ class EnumTesterFilter (EnumFilterSet ):
1556
+ class Meta :
1557
+ model = EnumTester
1558
+ fields = '__all__'
1559
+
1560
+ self .assertRaises (ImportError , EnumTesterFilter )
1561
+ self .assertRaises (ImportError , EnumFilter )
1562
+
1563
+ def test_enum_properties_missing (self ):
1564
+ import sys
1565
+ from unittest .mock import patch
1566
+ from importlib import reload
1567
+ import enum
1568
+
1569
+ with patch .dict (sys .modules , {'enum_properties' : None }):
1570
+ reload (sys .modules ['django_enum.choices' ])
1571
+ from django_enum .choices import (
1572
+ DjangoEnumPropertiesMeta ,
1573
+ DjangoSymmetricMixin ,
1574
+ TextChoices ,
1575
+ IntegerChoices ,
1576
+ FloatChoices
1577
+ )
1578
+
1579
+ with self .assertRaises (ImportError ):
1580
+ class ThrowsEnum (DjangoSymmetricMixin , enum .Enum ):
1581
+ A = 1
1582
+ B = 2
1583
+ C = 3
1584
+
1585
+ with self .assertRaises (ImportError ):
1586
+ class ThrowsEnum (
1587
+ enum .Enum ,
1588
+ metaclass = DjangoEnumPropertiesMeta
1589
+ ):
1590
+ A = 1
1591
+ B = 2
1592
+ C = 3
1593
+
1594
+ with self .assertRaises (ImportError ):
1595
+ class ThrowsEnum (IntegerChoices ):
1596
+ A = 1
1597
+ B = 2
1598
+ C = 3
1599
+
1600
+ with self .assertRaises (ImportError ):
1601
+ class ThrowsEnum (TextChoices ):
1602
+ A = 'A'
1603
+ B = 'B'
1604
+ C = 'C'
1605
+
1606
+ with self .assertRaises (ImportError ):
1607
+ class ThrowsEnum (FloatChoices ):
1608
+ A = 1.1
1609
+ B = 2.2
1610
+ C = 3.3
1611
+
1612
+ self .do_test_integer_choices ()
1613
+ self .do_test_text_choices ()
0 commit comments