4
4
import warnings
5
5
from datetime import datetime , timedelta
6
6
7
- import django
7
+ from django . apps import apps
8
8
from django .contrib .auth import get_user_model
9
9
from django .core .files .base import ContentFile
10
10
from django .db import models
11
11
from django .db .models .fields .proxy import OrderWrt
12
12
from django .test import TestCase
13
+
13
14
from simple_history .models import HistoricalRecords , convert_auto_field
14
15
from simple_history .utils import update_change_reason
15
-
16
16
from ..external .models import ExternalModel2 , ExternalModel4
17
17
from ..models import (AbstractBase , AdminProfile , Book , Bookcase , Choice , City ,
18
- ConcreteAttr , ConcreteUtil , Contact , ContactRegister ,
18
+ ConcreteAttr , ConcreteExternal , ConcreteUtil , Contact , ContactRegister ,
19
19
Country , Document , Employee , ExternalModel1 ,
20
20
ExternalModel3 , FileModel , HistoricalChoice ,
21
21
HistoricalCustomFKError , HistoricalPoll , HistoricalState ,
22
22
Library , MultiOneToOne , Person , Poll , PollInfo ,
23
23
PollWithExcludeFields , Province , Restaurant , SelfFK ,
24
24
Series , SeriesWork , State , Temperature ,
25
25
UnicodeVerboseName , WaterLevel )
26
- from django .apps import apps
27
26
28
27
get_model = apps .get_model
29
28
User = get_user_model ()
@@ -345,7 +344,7 @@ def test_create_history_model_with_one_to_one_field_to_integer_field(self):
345
344
records = HistoricalRecords ()
346
345
records .module = AdminProfile .__module__
347
346
try :
348
- records .create_history_model (AdminProfile )
347
+ records .create_history_model (AdminProfile , False )
349
348
except :
350
349
self .fail ("SimpleHistory should handle foreign keys to one to one"
351
350
"fields to integer fields without throwing an exception" )
@@ -354,7 +353,7 @@ def test_create_history_model_with_one_to_one_field_to_char_field(self):
354
353
records = HistoricalRecords ()
355
354
records .module = Bookcase .__module__
356
355
try :
357
- records .create_history_model (Bookcase )
356
+ records .create_history_model (Bookcase , False )
358
357
except :
359
358
self .fail ("SimpleHistory should handle foreign keys to one to one"
360
359
"fields to char fields without throwing an exception." )
@@ -363,7 +362,7 @@ def test_create_history_model_with_multiple_one_to_ones(self):
363
362
records = HistoricalRecords ()
364
363
records .module = MultiOneToOne .__module__
365
364
try :
366
- records .create_history_model (MultiOneToOne )
365
+ records .create_history_model (MultiOneToOne , False )
367
366
except :
368
367
self .fail ("SimpleHistory should handle foreign keys to one to one"
369
368
"fields to one to one fields without throwing an "
@@ -396,6 +395,10 @@ def test_register_app_label(self):
396
395
'external_externalmodel4' )
397
396
self .assertEqual (self .get_table_name (ExternalModel4 .histories ),
398
397
'tests_historicalexternalmodel4' )
398
+ self .assertEqual (self .get_table_name (ConcreteExternal .objects ),
399
+ 'tests_concreteexternal' )
400
+ self .assertEqual (self .get_table_name (ConcreteExternal .history ),
401
+ 'tests_historicalconcreteexternal' )
399
402
400
403
def test_get_model (self ):
401
404
self .assertEqual (get_model ('external' , 'ExternalModel1' ),
@@ -418,6 +421,13 @@ def test_get_model(self):
418
421
self .assertEqual (get_model ('tests' , 'HistoricalExternalModel4' ),
419
422
ExternalModel4 .histories .model )
420
423
424
+ # Test that historical model is defined within app of concrete
425
+ # model rather than abstract base model
426
+ self .assertEqual (get_model ('tests' , 'ConcreteExternal' ),
427
+ ConcreteExternal )
428
+ self .assertEqual (get_model ('tests' , 'HistoricalConcreteExternal' ),
429
+ ConcreteExternal .history .model )
430
+
421
431
422
432
class HistoryManagerTest (TestCase ):
423
433
def test_most_recent (self ):
0 commit comments