Arthur 2 дней назад
Родитель
Сommit
86f6de40d2
2 измененных файлов с 21 добавлено и 1 удалено
  1. 1 1
      docs/models/core/datasource.md
  2. 20 0
      netbox/core/tests/test_models.py

+ 1 - 1
docs/models/core/datasource.md

@@ -43,7 +43,7 @@ A set of rules (one per line) identifying files or paths to ignore during synchr
 | `README`              | Ignore any files named `README`                      |
 | `*.txt`               | Ignore any files with a `.txt` extension             |
 | `data???.json`        | Ignore e.g. `data123.json`                           |
-| `subdir/*`            | Ignore all files directly within `subdir/`           |
+| `subdir/*`            | Ignore all files within `subdir/`                    |
 | `subdir/*/*`          | Ignore all files one level deep within `subdir/`     |
 | `*/dev/*`             | Ignore files inside any directory named `dev/`       |
 

+ 20 - 0
netbox/core/tests/test_models.py

@@ -10,6 +10,26 @@ from dcim.models import Device, Location, Site
 from netbox.constants import CENSOR_TOKEN, CENSOR_TOKEN_CHANGED
 
 
+class DataSourceIgnoreRulesTestCase(TestCase):
+
+    def test_no_ignore_rules(self):
+        ds = DataSource(ignore_rules='')
+        self.assertFalse(ds._ignore('README.md'))
+        self.assertFalse(ds._ignore('subdir/file.py'))
+
+    def test_ignore_by_filename(self):
+        ds = DataSource(ignore_rules='*.txt')
+        self.assertTrue(ds._ignore('notes.txt'))
+        self.assertTrue(ds._ignore('subdir/notes.txt'))
+        self.assertFalse(ds._ignore('notes.py'))
+
+    def test_ignore_by_subdirectory(self):
+        ds = DataSource(ignore_rules='dev/*')
+        self.assertTrue(ds._ignore('dev/README.md'))
+        self.assertTrue(ds._ignore('dev/script.py'))
+        self.assertFalse(ds._ignore('prod/script.py'))
+
+
 class DataSourceChangeLoggingTestCase(TestCase):
 
     def test_password_added_on_create(self):