|
90 | 90 | PollChildRestaurantWithManyToMany, |
91 | 91 | PollInfo, |
92 | 92 | PollWithAlternativeManager, |
| 93 | + PollWithDefaultCustomBases, |
| 94 | + PollWithDefaultCustomM2MBases, |
93 | 95 | PollWithExcludedFieldsWithDefaults, |
94 | 96 | PollWithExcludedFKField, |
95 | 97 | PollWithExcludeFields, |
| 98 | + PollWithExplicitBasesOverride, |
| 99 | + PollWithExplicitM2MBasesOverride, |
96 | 100 | PollWithHistoricalIPAddress, |
97 | 101 | PollWithManyToMany, |
98 | 102 | PollWithManyToManyCustomHistoryID, |
@@ -1476,6 +1480,67 @@ def test_invalid_bases(self): |
1476 | 1480 | for bases in invalid_bases: |
1477 | 1481 | self.assertRaises(TypeError, HistoricalRecords, bases=bases) |
1478 | 1482 |
|
| 1483 | + def test_custom_bases_from_settings(self): |
| 1484 | + """Test that SIMPLE_HISTORY_CUSTOM_BASES setting is correctly applied.""" |
| 1485 | + # PollWithDefaultCustomBases uses SIMPLE_HISTORY_CUSTOM_BASES |
| 1486 | + history_model = PollWithDefaultCustomBases.history.model |
| 1487 | + # Check that IPAddressHistoricalModel is in the MRO |
| 1488 | + self.assertIn( |
| 1489 | + "IPAddressHistoricalModel", |
| 1490 | + [cls.__name__ for cls in history_model.__mro__], |
| 1491 | + ) |
| 1492 | + # Verify the historical model has ip_address field from IPAddressHistoricalModel |
| 1493 | + self.assertTrue(hasattr(history_model, "ip_address")) |
| 1494 | + |
| 1495 | + def test_custom_bases_explicit_overrides_setting(self): |
| 1496 | + """Test that explicit bases parameter overrides setting.""" |
| 1497 | + # PollWithExplicitBasesOverride uses explicit bases parameter |
| 1498 | + # even though SIMPLE_HISTORY_CUSTOM_BASES was set to [IPAddressHistoricalModel] |
| 1499 | + history_model = PollWithExplicitBasesOverride.history.model |
| 1500 | + # Should have SessionsHistoricalModel, not IPAddressHistoricalModel |
| 1501 | + self.assertIn( |
| 1502 | + "SessionsHistoricalModel", |
| 1503 | + [cls.__name__ for cls in history_model.__mro__], |
| 1504 | + ) |
| 1505 | + self.assertTrue(hasattr(history_model, "session")) |
| 1506 | + # Should NOT have ip_address from IPAddressHistoricalModel |
| 1507 | + self.assertFalse(hasattr(history_model, "ip_address")) |
| 1508 | + |
| 1509 | + def test_custom_m2m_bases_from_settings(self): |
| 1510 | + """Test that SIMPLE_HISTORY_CUSTOM_M2M_BASES setting is applied.""" |
| 1511 | + # PollWithDefaultCustomM2MBases uses SIMPLE_HISTORY_CUSTOM_M2M_BASES |
| 1512 | + # Get the M2M historical model by its generated name |
| 1513 | + from django.apps import apps |
| 1514 | + |
| 1515 | + m2m_history_model = apps.get_model( |
| 1516 | + "tests", "HistoricalPollWithDefaultCustomM2MBases_places" |
| 1517 | + ) |
| 1518 | + # Check that IPAddressHistoricalModel is in the MRO |
| 1519 | + self.assertIn( |
| 1520 | + "IPAddressHistoricalModel", |
| 1521 | + [cls.__name__ for cls in m2m_history_model.__mro__], |
| 1522 | + ) |
| 1523 | + # Verify the M2M historical model has ip_address field |
| 1524 | + self.assertTrue(hasattr(m2m_history_model, "ip_address")) |
| 1525 | + |
| 1526 | + def test_custom_m2m_bases_explicit_overrides_setting(self): |
| 1527 | + """Test that explicit m2m_bases parameter overrides setting.""" |
| 1528 | + # PollWithExplicitM2MBasesOverride uses explicit m2m_bases |
| 1529 | + # even though SIMPLE_HISTORY_CUSTOM_M2M_BASES was set |
| 1530 | + from django.apps import apps |
| 1531 | + |
| 1532 | + m2m_history_model = apps.get_model( |
| 1533 | + "tests", "HistoricalPollWithExplicitM2MBasesOverride_places" |
| 1534 | + ) |
| 1535 | + # Should have SessionsHistoricalModel, not IPAddressHistoricalModel |
| 1536 | + self.assertIn( |
| 1537 | + "SessionsHistoricalModel", |
| 1538 | + [cls.__name__ for cls in m2m_history_model.__mro__], |
| 1539 | + ) |
| 1540 | + self.assertTrue(hasattr(m2m_history_model, "session")) |
| 1541 | + # Should NOT have ip_address from IPAddressHistoricalModel |
| 1542 | + self.assertFalse(hasattr(m2m_history_model, "ip_address")) |
| 1543 | + |
1479 | 1544 | def test_import_related(self): |
1480 | 1545 | field_object = HistoricalChoice._meta.get_field("poll") |
1481 | 1546 | related_model = field_object.remote_field.related_model |
|
0 commit comments