|
|
@@ -6,6 +6,7 @@ from unittest.mock import patch
|
|
|
|
|
|
from django.contrib.contenttypes.models import ContentType
|
|
|
from django.db import connection, transaction
|
|
|
+from django.test import override_settings
|
|
|
from django.test.utils import CaptureQueriesContext
|
|
|
from django.urls import reverse
|
|
|
from django.utils import timezone
|
|
|
@@ -126,6 +127,42 @@ class DataSourceTestCase(ViewTestCases.PrimaryObjectViewTestCase):
|
|
|
response, f'formaction="{url}?return_url={list_url}" formmethod="post" data-disable-on-submit>'
|
|
|
)
|
|
|
|
|
|
+ @override_settings(ALLOWED_DATA_BACKENDS=['git'])
|
|
|
+ def test_disallowed_backend(self):
|
|
|
+ """Only allowed backends are offered, and a source with a disallowed backend can't be synced."""
|
|
|
+ self.add_permissions('core.add_datasource', 'core.view_datasource', 'core.sync_datasource')
|
|
|
+ datasource = DataSource.objects.first()
|
|
|
+ sync_url = reverse('core:datasource_sync', kwargs={'pk': datasource.pk})
|
|
|
+
|
|
|
+ response = self.client.get(reverse('core:datasource_add'))
|
|
|
+ self.assertContains(response, '<option value="git"')
|
|
|
+ self.assertNotContains(response, '<option value="local"')
|
|
|
+
|
|
|
+ response = self.client.get(datasource.get_absolute_url())
|
|
|
+ self.assertHttpStatus(response, 200)
|
|
|
+ self.assertNotContains(response, sync_url)
|
|
|
+
|
|
|
+ with patch('core.views.SyncDataSourceJob') as sync_job:
|
|
|
+ response = self.client.post(sync_url)
|
|
|
+ self.assertHttpStatus(response, 302)
|
|
|
+ sync_job.enqueue.assert_not_called()
|
|
|
+
|
|
|
+ @override_settings(ALLOWED_DATA_BACKENDS=[])
|
|
|
+ def test_edit_source_with_disallowed_backend(self):
|
|
|
+ """An existing data source whose backend isn't allowed can still be edited."""
|
|
|
+ self.add_permissions('core.change_datasource')
|
|
|
+ datasource = DataSource.objects.first()
|
|
|
+
|
|
|
+ response = self.client.post(reverse('core:datasource_edit', kwargs={'pk': datasource.pk}), {
|
|
|
+ 'name': datasource.name,
|
|
|
+ 'type': datasource.type,
|
|
|
+ 'source_url': datasource.source_url,
|
|
|
+ })
|
|
|
+
|
|
|
+ self.assertHttpStatus(response, 302)
|
|
|
+ datasource.refresh_from_db()
|
|
|
+ self.assertFalse(datasource.enabled)
|
|
|
+
|
|
|
|
|
|
class DataFileTestCase(
|
|
|
ViewTestCases.GetObjectViewTestCase,
|