Repository: torchbox/wagtail-content-import (language: python)

Issue:
40 simplify mapping
Creates Converter classes to simplify mapping, each with a __call__ function which maps an intermediate element to a streamfield block. 

Converter classes can be used to populate a StreamFieldMapper subclass, eg:

```python
class MyMapper(StreamFieldMapper:
    html = RichTextConverter('name_of_my_rich_text_block')
    image = ImageConverter('name_of_my_image_block')
```

Hopefully making this simpler to configure.


Discussion / hints:

Fix patch:
diff --git a/README.md b/README.md
index c8bd76f..dc13594 100644
--- a/README.md
+++ b/README.md
@@ -20,7 +20,7 @@ Currently supports:
 
 ### Requirements:
 * Django >= 3.2
-* Wagtail >= 2.15
+* Wagtail >= 4.1
 
 For the full documentation, see: https://torchbox.github.io/wagtail-content-import/
 
diff --git a/setup.py b/setup.py
index 96118fb..2399a92 100644
--- a/setup.py
+++ b/setup.py
@@ -41,17 +41,16 @@
         "Programming Language :: Python :: 3.8",
         "Programming Language :: Python :: 3.9",
         "Programming Language :: Python :: 3.10",
+        "Programming Language :: Python :: 3.11",
         "Framework :: Django",
         "Framework :: Django :: 3.2",
         "Framework :: Django :: 4.0",
         "Framework :: Django :: 4.1",
         "Framework :: Wagtail",
-        "Framework :: Wagtail :: 2",
-        "Framework :: Wagtail :: 3",
         "Framework :: Wagtail :: 4",
         "Topic :: Internet :: WWW/HTTP :: Site Management",
     ],
-    install_requires=["wagtail>=2.15", "python-docx>=0.8.10"],
+    install_requires=["wagtail>=4.1", "python-docx>=0.8.10"],
     extras_require={"testing": test_requires, },
     zip_safe=False,
 )
diff --git a/tox.ini b/tox.ini
index 12bd1b4..2009c72 100644
--- a/tox.ini
+++ b/tox.ini
@@ -3,9 +3,22 @@ skipsdist = True
 usedevelop = True
 
 envlist =
-    python{3.7,3.8,3.9,3.10}-django{3.2}-wagtail{2.15,2.16,3.0,4.0,master}-{sqlite,postgres}
-    python{3.8,3.9,3.10}-django{4.0}-wagtail{2.16,3.0,4.0,master}-{sqlite,postgres}
-    python{3.8,3.9,3.10}-django{4.1,master}-wagtail{4.0,master}-{sqlite,postgres}
+    python{3.7}-django{3.2}-wagtail{4.1,4.2,master}-{sqlite,postgres}
+    python{3.8,3.9,3.10}-django{3.2}-wagtail{4.1,4.2,master}-{sqlite,postgres}
+    python{3.8,3.9,3.10}-django{4.0,4.1}-wagtail{4.1,4.2,master}-{sqlite,postgres}
+    python{3.11}-django{4.1}-wagtail{4.1,4.2,master}-{sqlite,postgres}
+
+[gh-actions]
+python =
+    3.7: python3.7
+    3.8: python3.8
+    3.9: python3.9
+    3.10: python3.10
+    3.11: python3.11
+
+[gh-actions:env]
+DATABASE = 
+    postgres: postgres
 
 [flake8]
 # E501: Line too long
@@ -17,12 +30,6 @@ exclude = migrations,node_modules
 install_command = pip install -e ".[testing]" -U {opts} {packages}
 commands = coverage run testmanage.py test --deprecation all
 
-basepython =
-    python3.7: python3.7
-    python3.8: python3.8
-    python3.9: python3.9
-    python3.10: python3.10
-
 deps =
     coverage
 
@@ -31,15 +38,13 @@ deps =
     django4.1: Django>=4.1,<4.2
     djangomaster: git+https://github.com/django/django.git@master#egg=Django
 
-    wagtail2.15: wagtail>=2.15,<2.16
-    wagtail2.16: wagtail>=2.16,<3.0
-    wagtail3.0: wagtail>=3.0,<3.1
-    wagtail4.0: wagtail>=4.0,<4.1
+    wagtail4.1: wagtail>=4.1,<4.2
+    wagtail4.2: wagtail>=4.1,<5.0
     wagtailmaster: git+https://github.com/wagtail/wagtail.git
 
-    postgres: psycopg2>=2.6
+    postgres: psycopg2
 
 [testenv:flake8]
 basepython=python3.7
 deps=flake8>=2.2.0
-commands=flake8 wagtail_content_import
\ No newline at end of file
+commands=flake8 wagtail_content_import
diff --git a/wagtail_content_import/mappers/converters.py b/wagtail_content_import/mappers/converters.py
index 42ea46d..9c4f0db 100644
--- a/wagtail_content_import/mappers/converters.py
+++ b/wagtail_content_import/mappers/converters.py
@@ -5,22 +5,13 @@
 from django.contrib.auth.models import Permission
 from django.core.files.base import ContentFile
 from django.utils.functional import cached_property
-from wagtail import VERSION as WAGTAIL_VERSION
 from wagtail.admin.rich_text.converters.contentstate import (
     ContentstateConverter)
-
-if WAGTAIL_VERSION >= (3, 0):
-    from wagtail.models import Page, Site
-    from wagtail.rich_text import RichText
-    from wagtail.rich_text import features as feature_registry
-    from wagtail.rich_text.rewriters import LinkRewriter
-else:
-    from wagtail.core.models import Page, Site
-    from wagtail.core.rich_text import RichText
-    from wagtail.core.rich_text import features as feature_registry
-    from wagtail.core.rich_text.rewriters import LinkRewriter
-
 from wagtail.images import get_image_model
+from wagtail.models import Page, Site
+from wagtail.rich_text import RichText
+from wagtail.rich_text import features as feature_registry
+from wagtail.rich_text.rewriters import LinkRewriter
 
 USER_NEEDS_IMAGE_CHOOSE_PERMISSION = None
 
diff --git a/wagtail_content_import/pickers/google/wagtail_hooks.py b/wagtail_content_import/pickers/google/wagtail_hooks.py
index 8ecfe1c..48c7e47 100644
--- a/wagtail_content_import/pickers/google/wagtail_hooks.py
+++ b/wagtail_content_import/pickers/google/wagtail_hooks.py
@@ -1,12 +1,7 @@
 import json
 
 from django.conf import settings
-from wagtail import VERSION as WAGTAIL_VERSION
-
-if WAGTAIL_VERSION >= (3, 0):
-    from wagtail import hooks
-else:
-    from wagtail.core import hooks
+from wagtail import hooks
 
 from ...utils import (
     create_page_from_import, is_importing, set_importing,
diff --git a/wagtail_content_import/pickers/local/wagtail_hooks.py b/wagtail_content_import/pickers/local/wagtail_hooks.py
index 9e603d4..fbe957b 100644
--- a/wagtail_content_import/pickers/local/wagtail_hooks.py
+++ b/wagtail_content_import/pickers/local/wagtail_hooks.py
@@ -1,9 +1,4 @@
-from wagtail import VERSION as WAGTAIL_VERSION
-
-if WAGTAIL_VERSION >= (3, 0):
-    from wagtail import hooks
-else:
-    from wagtail.core import hooks
+from wagtail import hooks
 
 from ...utils import (
     create_page_from_import, is_importing, set_importing,
diff --git a/wagtail_content_import/pickers/microsoft/wagtail_hooks.py b/wagtail_content_import/pickers/microsoft/wagtail_hooks.py
index 11f2bcd..26cb060 100644
--- a/wagtail_content_import/pickers/microsoft/wagtail_hooks.py
+++ b/wagtail_content_import/pickers/microsoft/wagtail_hooks.py
@@ -2,19 +2,11 @@
 
 import requests
 from django.conf import settings
-from wagtail import VERSION as WAGTAIL_VERSION
-
-if WAGTAIL_VERSION >= (3, 0):
-    from wagtail import hooks
-else:
-    from wagtail.core import hooks
+from wagtail import hooks
 
 from ...utils import (
-    create_page_from_import,
-    is_importing,
-    set_importing,
-    update_page_from_import,
-)
+    create_page_from_import, is_importing, set_importing,
+    update_page_from_import)
 from .utils import MicrosoftPicker, parse_document
 
 
diff --git a/wagtail_content_import/templatetags/wagtailcontentimport_tags.py b/wagtail_content_import/templatetags/wagtailcontentimport_tags.py
index e2d328c..8f9e4a6 100644
--- a/wagtail_content_import/templatetags/wagtailcontentimport_tags.py
+++ b/wagtail_content_import/templatetags/wagtailcontentimport_tags.py
@@ -1,11 +1,6 @@
 from django import template
 from django.utils.safestring import mark_safe
-from wagtail import VERSION as WAGTAIL_VERSION
-
-if WAGTAIL_VERSION >= (3, 0):
-    from wagtail import hooks
-else:
-    from wagtail.core import hooks
+from wagtail import hooks
 
 register = template.Library()
 
diff --git a/wagtail_content_import/wagtail_hooks.py b/wagtail_content_import/wagtail_hooks.py
index abe7cd3..f113538 100644
--- a/wagtail_content_import/wagtail_hooks.py
+++ b/wagtail_content_import/wagtail_hooks.py
@@ -1,13 +1,8 @@
 from django.urls import include, path
 from django.utils.html import format_html
-from wagtail import VERSION as WAGTAIL_VERSION
+from wagtail import hooks
 from wagtail.admin.staticfiles import versioned_static
 
-if WAGTAIL_VERSION >= (3, 0):
-    from wagtail import hooks
-else:
-    from wagtail.core import hooks
-
 from . import admin_views
 
 


Test patch:
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 7efd758..555c939 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -10,51 +10,6 @@ on:
   pull_request:
 
 jobs:
-  test-sqlite:
-    runs-on: ubuntu-latest
-    strategy:
-      matrix:
-        python: ['3.8', '3.9', '3.10']
-        django: ['3.2', '4.0']
-        wagtail: ['2.16', '3.0', '4.0']
-        include:
-          - wagtail: '2.15'
-            django: '3.2'
-            python: '3.7'
-          - wagtail: '2.15'
-            django: '3.2'
-            python: '3.8'
-          - wagtail: '2.15'
-            django: '3.2'
-            python: '3.9'
-          - wagtail: '2.15'
-            django: '3.2'
-            python: '3.10'
-          - wagtail: '4.0'
-            django: '4.1'
-            python: '3.8'
-          - wagtail: '4.0'
-            django: '4.1'
-            python: '3.9'
-          - wagtail: '4.0'
-            django: '4.1'
-            python: '3.10'
-
-    steps:
-      - uses: actions/checkout@v3
-      - name: Set up Python ${{ matrix.python }}
-        uses: actions/setup-python@v4
-        with:
-          python-version: ${{ matrix.python }}
-      - name: Install Tox
-        run: |
-          python -m pip install tox
-      - name: Test
-        run: |
-          tox
-        env:
-          TOXENV: python${{ matrix.python }}-django${{ matrix.django }}-wagtail${{ matrix.wagtail }}-sqlite
-
   lint:
     runs-on: ubuntu-latest
     steps:
@@ -76,63 +31,66 @@ jobs:
         run: |
           isort .
 
+  test-sqlite:
+    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        python: ["3.7", "3.8", "3.9", "3.10", "3.11"]
+
+    steps:
+      - uses: actions/checkout@v3
+      - name: Set up Python ${{ matrix.python }}
+        uses: actions/setup-python@v4
+        with:
+          python-version: ${{ matrix.python }}
+      - name: Install dependencies
+        run: |
+          python -m pip install --upgrade pip
+          python -m pip install tox tox-gh-actions
+      - name: Test with tox
+        run: tox
+
   test-postgres:
     runs-on: ubuntu-latest
     strategy:
       matrix:
-        python: ['3.8', '3.9', '3.10']
-        django: ['3.2', '4.0']
-        wagtail: ['2.16', '3.0', '4.0']
-        postgres: ['10.8']
-        include:
-          - wagtail: '2.15'
-            django: '3.2'
-            postgres: '10.8'
-            python: '3.7'
-          - wagtail: '2.15'
-            django: '3.2'
-            postgres: '10.8'
-            python: '3.8'
-          - wagtail: '2.15'
-            django: '3.2'
-            postgres: '10.8'
-            python: '3.9'
-          - wagtail: '2.15'
-            django: '3.2'
-            postgres: '10.8'
-            python: '3.10'
-          - wagtail: '4.0'
-            django: '4.1'
-            postgres: '10.8'
-            python: '3.8'
-          - wagtail: '4.0'
-            django: '4.1'
-            postgres: '10.8'
-            python: '3.9'
-          - wagtail: '4.0'
-            django: '4.1'
-            postgres: '10.8'
-            python: '3.10'
+        python: ["3.7", "3.8", "3.9", "3.10", "3.11"]
+        database: ["postgres"]
 
     services:
       postgres:
-        image: postgres:${{ matrix.postgres }}
+        image: postgres
+        env:
+          POSTGRES_USER: postgres
+          POSTGRES_PASSWORD: postgres
+          POSTGRES_DB: postgres
         ports:
           - 5432:5432
         options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
 
     steps:
-      - uses: actions/checkout@v3
-      - name: Set up Python ${{ matrix.python }}
+      - name: Checkout repository
+        uses: actions/checkout@v3
+
+      - name: Set up Python
+        id: setup-python
         uses: actions/setup-python@v4
         with:
           python-version: ${{ matrix.python }}
-      - name: Install Tox
+
+      - name: Install dependencies
+        id: install-dependencies
         run: |
-          python -m pip install tox
-      - name: Test
+          python -m pip install --upgrade pip
+          python -m pip install tox tox-gh-actions
+      - name: Test with tox
+        id: test-with-tox
         run: |
           tox
         env:
-          DATABASE_URL: postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}
-          TOXENV: python${{ matrix.python }}-django${{ matrix.django }}-wagtail${{ matrix.wagtail }}-postgres
\ No newline at end of file
+          DB_NAME: postgres
+          DB_USER: postgres
+          DB_PASSWORD: postgres
+          DB_HOST: localhost
+          DB_PORT: 5432
+          DATABASE: ${{ matrix.database }}
diff --git a/testmanage.py b/testmanage.py
index 972b0b0..c026b5c 100644
--- a/testmanage.py
+++ b/testmanage.py
@@ -55,7 +55,7 @@ def runtests():
     try:
         execute_from_command_line(argv)
     finally:
-        from wagtail.tests.settings import MEDIA_ROOT, STATIC_ROOT
+        from wagtail.test.settings import MEDIA_ROOT, STATIC_ROOT
 
         shutil.rmtree(STATIC_ROOT, ignore_errors=True)
         shutil.rmtree(MEDIA_ROOT, ignore_errors=True)
diff --git a/wagtail_content_import/mappers/tests.py b/wagtail_content_import/mappers/tests.py
index b24573c..48b5e78 100644
--- a/wagtail_content_import/mappers/tests.py
+++ b/wagtail_content_import/mappers/tests.py
@@ -3,16 +3,10 @@
 
 from django.contrib.auth.models import User
 from django.test import TestCase
-from wagtail import VERSION as WAGTAIL_VERSION
-
-if WAGTAIL_VERSION >= (3, 0):
-    from wagtail.models import Page
-else:
-    from wagtail.core.models import Page
-
 from wagtail.images import get_image_model
 from wagtail.images.tests.utils import (
     get_test_image_file, get_test_image_file_jpeg)
+from wagtail.models import Page
 
 from ..parsers.tables import Cell, Table
 from .converters import (
diff --git a/wagtail_content_import/test/settings.py b/wagtail_content_import/test/settings.py
index 06ef7a8..02d1c7d 100644
--- a/wagtail_content_import/test/settings.py
+++ b/wagtail_content_import/test/settings.py
@@ -10,7 +10,6 @@
 import os
 
 import dj_database_url
-from wagtail import VERSION as WAGTAIL_VERSION
 
 # Build paths inside the project like this: os.path.join(PROJECT_DIR, ...)
 PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -48,7 +47,7 @@
     "wagtail.contrib.routable_page",
     "wagtail.contrib.styleguide",
     "wagtail.sites",
-    "wagtail" if WAGTAIL_VERSION >= (3, 0) else "wagtail.core",
+    "wagtail",
     "taggit",
     "rest_framework",
     "django.contrib.admin",
diff --git a/wagtail_content_import/test/urls.py b/wagtail_content_import/test/urls.py
index 55644c7..a8f8ce2 100644
--- a/wagtail_content_import/test/urls.py
+++ b/wagtail_content_import/test/urls.py
@@ -1,13 +1,7 @@
 from django.contrib import admin
 from django.urls import include, path
-from wagtail import VERSION as WAGTAIL_VERSION
+from wagtail import urls as wagtail_urls
 from wagtail.admin import urls as wagtailadmin_urls
-
-if WAGTAIL_VERSION >= (3, 0):
-    from wagtail import urls as wagtail_urls
-else:
-    from wagtail.core import urls as wagtail_urls
-
 from wagtail.documents import urls as wagtaildocs_urls
 
 from wagtail_content_import import urls as wagtail_content_import_urls