|
@@ -1,6 +1,7 @@
|
|
|
import hashlib
|
|
import hashlib
|
|
|
import uuid
|
|
import uuid
|
|
|
from unittest import skipIf
|
|
from unittest import skipIf
|
|
|
|
|
+from unittest.mock import patch
|
|
|
|
|
|
|
|
from django.apps import apps
|
|
from django.apps import apps
|
|
|
from django.conf import settings
|
|
from django.conf import settings
|
|
@@ -10,7 +11,7 @@ from django.test import RequestFactory, TestCase
|
|
|
from django.utils.timezone import now
|
|
from django.utils.timezone import now
|
|
|
from taggit.models import Tag
|
|
from taggit.models import Tag
|
|
|
|
|
|
|
|
-from core.models import AutoSyncRecord, DataFile, DataSource, ObjectChange
|
|
|
|
|
|
|
+from core.models import AutoSyncRecord, DataFile, DataSource, ManagedFile, ObjectChange
|
|
|
from dcim.models import Site
|
|
from dcim.models import Site
|
|
|
from extras.models import (
|
|
from extras.models import (
|
|
|
ConfigContext,
|
|
ConfigContext,
|
|
@@ -173,6 +174,18 @@ class ModelFeaturesTestCase(TestCase):
|
|
|
self.assertEqual(change.prechange_data['template_code'], 'original\n')
|
|
self.assertEqual(change.prechange_data['template_code'], 'original\n')
|
|
|
self.assertEqual(change.postchange_data['template_code'], 'updated\n')
|
|
self.assertEqual(change.postchange_data['template_code'], 'updated\n')
|
|
|
|
|
|
|
|
|
|
+ @patch.object(ManagedFile, 'sync_data')
|
|
|
|
|
+ def test_synceddatamixin_sync_without_change_logging(self, mock_sync_data):
|
|
|
|
|
+ """Saving a sync succeeds for models which are not change-logged. Ref: #23617"""
|
|
|
|
|
+ datafile = self._create_data_file('script.py', b'# script\n')
|
|
|
|
|
+ obj = ManagedFile.objects.create(file_root='scripts', file_path='script.py', data_file=datafile)
|
|
|
|
|
+
|
|
|
|
|
+ obj.sync(save=True)
|
|
|
|
|
+
|
|
|
|
|
+ mock_sync_data.assert_called_once()
|
|
|
|
|
+ obj.refresh_from_db()
|
|
|
|
|
+ self.assertIsNotNone(obj.data_synced)
|
|
|
|
|
+
|
|
|
def test_synceddatamixin_accepts_plain_text_template(self):
|
|
def test_synceddatamixin_accepts_plain_text_template(self):
|
|
|
"""Text which is not a YAML document is still valid template content."""
|
|
"""Text which is not a YAML document is still valid template content."""
|
|
|
datafile = self._create_data_file('comment-only.j2', b'{# nothing here #}\n')
|
|
datafile = self._create_data_file('comment-only.j2', b'{# nothing here #}\n')
|