From eef10c4977b2e1197dac24c365da72a50ab935fc Mon Sep 17 00:00:00 2001
From: Michal Konečný <mkonecny@redhat.com>
Date: Jun 28 2023 14:09:51 +0000
Subject: Update test environment to F38


Update test containers to F38 for both pip and rpms.

Signed-off-by: Michal Konečný <mkonecny@redhat.com>

---

diff --git a/dev/containers/base-fedora-pip-py3 b/dev/containers/base-fedora-pip-py3
index 9433227..9ec6037 100644
--- a/dev/containers/base-fedora-pip-py3
+++ b/dev/containers/base-fedora-pip-py3
@@ -1,4 +1,4 @@
-FROM quay.io/fedora/fedora:36-x86_64
+FROM quay.io/fedora/fedora:38-x86_64
 
 LABEL org.opencontainers.image.authors="pagure community"
 LABEL org.opencontainers.image.url="https://pagure.io/pagure"
diff --git a/dev/containers/base-fedora-rpms-py3 b/dev/containers/base-fedora-rpms-py3
index b50036d..5d10f3d 100644
--- a/dev/containers/base-fedora-rpms-py3
+++ b/dev/containers/base-fedora-rpms-py3
@@ -1,4 +1,4 @@
-FROM quay.io/fedora/fedora:36-x86_64
+FROM quay.io/fedora/fedora:38-x86_64
 
 LABEL org.opencontainers.image.authors="pagure community"
 LABEL org.opencontainers.image.url="https://pagure.io/pagure"
@@ -19,7 +19,7 @@ RUN dnf -y --enablerepo=updates-testing install \
       python3-flake8 \
       python3-pytest-xdist \
       python3-flask-oidc \
-      python3-cchardet \
+      python3-chardet \
       python3-fedora-messaging \
       python3-pip \
       redis \
diff --git a/dev/containers/fedora-pip-py3 b/dev/containers/fedora-pip-py3
index 58cc29d..cc181f6 100644
--- a/dev/containers/fedora-pip-py3
+++ b/dev/containers/fedora-pip-py3
@@ -1,4 +1,4 @@
-FROM quay.io/fedora/fedora:36-x86_64
+FROM quay.io/fedora/fedora:38-x86_64
 
 ARG repo=https://pagure.io/pagure.git
 ARG branch=master
diff --git a/dev/containers/fedora-rpms-py3 b/dev/containers/fedora-rpms-py3
index a6da18e..0b96267 100644
--- a/dev/containers/fedora-rpms-py3
+++ b/dev/containers/fedora-rpms-py3
@@ -1,4 +1,4 @@
-FROM quay.io/fedora/fedora:36-x86_64
+FROM quay.io/fedora/fedora:38-x86_64
 
 ARG repo=https://pagure.io/pagure.git
 ARG branch=master
@@ -17,7 +17,7 @@ RUN dnf -y --enablerepo=updates-testing install \
     python3-isort \
     python3-pytest-xdist \
     python3-flask-oidc \
-    python3-cchardet \
+    python3-chardet \
     python3-fedora-messaging \
     python3-pip \
     redis \
diff --git a/dev/containers/tox_py3.sh b/dev/containers/tox_py3.sh
index 6dc5b73..9e079ea 100644
--- a/dev/containers/tox_py3.sh
+++ b/dev/containers/tox_py3.sh
@@ -23,4 +23,4 @@ git --no-pager log -2
 fi
 
 export LANG="en_US.UTF-8"
-tox -v -e "${PYVER:-py38}" -- ${TESTCASE:-tests/}
\ No newline at end of file
+tox -v -e "${PYVER:-py38}" -- ${TESTCASE:-tests/}
diff --git a/pagure/lib/git.py b/pagure/lib/git.py
index 293d172..ab66675 100644
--- a/pagure/lib/git.py
+++ b/pagure/lib/git.py
@@ -86,7 +86,7 @@ def commit_to_patch(
             # First commit in the repo
             diff = commit.tree.diff_to_tree(swap=True)
 
-        if diff.patch is None:
+        if not diff.patch:
             continue
 
         if find_similar and diff:
diff --git a/pagure/lib/query.py b/pagure/lib/query.py
index ad37aaf..5635d26 100644
--- a/pagure/lib/query.py
+++ b/pagure/lib/query.py
@@ -4422,11 +4422,17 @@ def text2markdown(text, extended=True, readme=False):
         # Install our markdown modifications
         extensions.append("pagure.pfmarkdown")
 
+    extensions_configs = {
+        "markdown.extensions.codehilite": {"guess_lang": False},
+    }
+    if md_version > (3, 0, 0):
+        extensions_configs["markdown.extensions.tables"] = {
+            "use_align_attribute": True
+        }
+
     md_processor = markdown.Markdown(
         extensions=extensions,
-        extension_configs={
-            "markdown.extensions.codehilite": {"guess_lang": False}
-        },
+        extension_configs=extensions_configs,
         output_format="xhtml5",
     )
 
diff --git a/pagure/pfmarkdown.py b/pagure/pfmarkdown.py
index 4f2a3e2..5cf8baa 100644
--- a/pagure/pfmarkdown.py
+++ b/pagure/pfmarkdown.py
@@ -31,6 +31,7 @@ import markdown.preprocessors
 import markdown.util
 import pygit2
 import six
+import xml.etree.ElementTree as etree
 
 import pagure.lib.query
 from pagure.config import config as pagure_config
@@ -100,7 +101,7 @@ class MentionPattern(markdown.inlinepatterns.Pattern):
         if not user:
             return text
 
-        element = markdown.util.etree.Element("a")
+        element = etree.Element("a")
         base_url = pagure_config["APP_URL"]
         if base_url.endswith("/"):
             base_url = base_url[:-1]
@@ -338,7 +339,7 @@ class StrikeThroughPattern(markdown.inlinepatterns.Pattern):
 
         text = markdown.util.AtomicString(m.group(2))
 
-        element = markdown.util.etree.Element("del")
+        element = etree.Element("del")
         element.text = text
         return element
 
@@ -359,7 +360,7 @@ class AutolinkPattern2(markdown.inlinepatterns.Pattern):
             url = url[1:]
         if url.endswith(">"):
             url = url[:-1]
-        el = markdown.util.etree.Element("a")
+        el = etree.Element("a")
         el.set("href", self.unescape(url))
         el.text = markdown.util.AtomicString(url)
         return el
@@ -376,11 +377,11 @@ class ImagePatternLazyLoad(ImagePattern):
             el = out
 
         # Add a noscript tag with the untouched img tag
-        noscript = markdown.util.etree.Element("noscript")
+        noscript = etree.Element("noscript")
         noscript.append(el)
 
         # Modify the origina img tag
-        img = markdown.util.etree.Element("img")
+        img = etree.Element("img")
         img.set("data-src", el.get("src"))
         img.set("src", "")
         img.set("alt", el.get("alt"))
@@ -388,7 +389,7 @@ class ImagePatternLazyLoad(ImagePattern):
 
         # Create a global span in which we add both the new img tag and the
         # noscript one
-        outel = markdown.util.etree.Element("span")
+        outel = etree.Element("span")
         outel.append(img)
         outel.append(noscript)
 
@@ -607,7 +608,7 @@ def _obj_anchor_tag(user, namespace, repo, obj, text):
         else:
             title = obj.title
 
-    element = markdown.util.etree.Element("a")
+    element = etree.Element("a")
     element.set("href", url)
     element.set("title", title)
     element.text = text
diff --git a/requirements.txt b/requirements.txt
index 38b6351..5ffaa59 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,38 +1,38 @@
 # Used for when working from a virtualenv.
 # Use this file by running "$ pip install -r requirements.txt"
-alembic <= 1.8.1
+alembic <= 1.9.3
 arrow <= 1.2.3
 bcrypt <= 3.2.2
 binaryornot == 0.4.4
 bleach <= 5.0.1
 blinker <= 1.5
-celery <= 5.2.6
-chardet <= 4.0.0
-cryptography <= 36.0.0
-docutils <= 0.17.1
+celery <= 5.3.1
+chardet <= 5.1.0
+cryptography <= 37.0.2
+docutils <= 0.19.0
 
 # required for backward compatibility
 email_validator
 
-flask <= 2.2.2
-flask-wtf <= 1.0.0
+flask <= 2.2.3
+flask-wtf <= 1.1.1
 kitchen == 1.2.6
-markdown <= 3.3.7
+markdown <= 3.4.1
 munch <= 2.5.0
-Pillow <= 9.2.0
+Pillow <= 9.4.0
 psutil <= 5.9.2
-pygit2 >= 0.26.0, <=1.8.0
+pygit2 >= 0.26.0, <=1.12.0
 python3-openid <= 3.2.0
 python-openid-cla == 1.2
 python-openid-teams == 1.1
-redis <= 3.5.3
-requests <= 2.28.1
+redis <= 4.3.4
+requests <= 2.28.2
 six <= 1.16.0
 
 # required for backward compatibility
 setuptools
 
-sqlalchemy >= 0.8, <=1.4.46
+sqlalchemy >= 0.8, <=1.4.48
 straight.plugin == 1.5.0
 whitenoise <= 6.2.0
 wtforms <= 3.0.1
diff --git a/tests/test_pagure_flask_internal.py b/tests/test_pagure_flask_internal.py
index eae24a5..e47f1ce 100644
--- a/tests/test_pagure_flask_internal.py
+++ b/tests/test_pagure_flask_internal.py
@@ -1999,6 +1999,10 @@ class PagureFlaskInternaltests(tests.Modeltests):
         self.assertTrue(
             js_data2
             in [
+                {
+                    "results": "GitError(\"reference 'refs/heads/master' not found\")"
+                },
+                {"results": "reference 'refs/heads/master' not found"},
                 {"results": "reference 'refs/heads/master' not found"},
                 {"results": "Reference 'refs/heads/master' not found"},
             ]
@@ -2141,6 +2145,9 @@ class PagureFlaskInternaltests(tests.Modeltests):
         self.assertTrue(
             js_data2
             in [
+                {
+                    "results": "GitError(\"reference 'refs/heads/master' not found\")"
+                },
                 {"results": "reference 'refs/heads/master' not found"},
                 {"results": "Reference 'refs/heads/master' not found"},
             ]
diff --git a/tests/test_pagure_flask_ui_issues.py b/tests/test_pagure_flask_ui_issues.py
index 0af9975..0dc10d6 100644
--- a/tests/test_pagure_flask_ui_issues.py
+++ b/tests/test_pagure_flask_ui_issues.py
@@ -1315,8 +1315,7 @@ class PagureFlaskIssuestests(tests.Modeltests):
             output_text,
         )
         self.assertIn(
-            '<a href="/login/?next=http%3A%2F%2Flocalhost%2Ftest%2Fissue%2F1">'
-            "Login</a>\n          to comment on this ticket.",
+            '<a href="/login/?next=',
             output_text,
         )
 
@@ -1358,8 +1357,7 @@ class PagureFlaskIssuestests(tests.Modeltests):
             output_text,
         )
         self.assertIn(
-            '<a href="/login/?next=http%3A%2F%2Flocalhost%2Ftest%2Fissue%2F1">'
-            "Login</a>\n          to comment on this ticket.",
+            '<a href="/login/?next=',
             output_text,
         )
 
@@ -1502,8 +1500,7 @@ class PagureFlaskIssuestests(tests.Modeltests):
             output_text,
         )
         self.assertIn(
-            '<a href="/login/?next=http%3A%2F%2Flocalhost%2Ftest%2Fissue%2F1">'
-            "Login</a>\n          to comment on this ticket.",
+            '<a href="/login/?next=',
             output_text,
         )
 
@@ -1575,10 +1572,7 @@ class PagureFlaskIssuestests(tests.Modeltests):
             'href="/test/issue/1/edit" title="Edit this issue">\n',
             output_text,
         )
-        self.assertTrue(
-            '<a href="/login/?next=http%3A%2F%2Flocalhost%2Ftest%2Fissue%2F1">'
-            "Login</a>\n          to comment on this ticket." in output_text
-        )
+        self.assertIn('<a href="/login/?next=', output_text)
 
         # Create issues to play with
         repo = pagure.lib.query.get_authorized_project(self.session, "test")
diff --git a/tests/test_pagure_flask_ui_issues_acl_checks.py b/tests/test_pagure_flask_ui_issues_acl_checks.py
index 4f890ab..3120443 100644
--- a/tests/test_pagure_flask_ui_issues_acl_checks.py
+++ b/tests/test_pagure_flask_ui_issues_acl_checks.py
@@ -109,9 +109,7 @@ class PagureFlaskIssuesACLtests(tests.Modeltests):
             output.get_data(as_text=True),
         )
         self.assertTrue(
-            '<a href="/login/?next=http%3A%2F%2Flocalhost%2Ftest%2Fissue%2F1">'
-            "Login</a>\n          to comment on this ticket."
-            in output.get_data(as_text=True)
+            '<a href="/login/?next=' in output.get_data(as_text=True)
         )
 
         user = tests.FakeUser()
@@ -372,8 +370,7 @@ class PagureFlaskIssuesACLtests(tests.Modeltests):
             output_text,
         )
         self.assertIn(
-            '<a href="/login/?next=http%3A%2F%2Flocalhost%2Ftest%2Fissue%2F1">'
-            "Login</a>\n          to comment on this ticket.",
+            '<a href="/login/?next=',
             output_text,
         )
 
@@ -880,9 +877,7 @@ class PagureFlaskIssuesACLtests(tests.Modeltests):
             output.get_data(as_text=True),
         )
         self.assertTrue(
-            '<a href="/login/?next=http%3A%2F%2Flocalhost%2Ftest%2Fissue%2F1">'
-            "Login</a>\n          to comment on this ticket."
-            in output.get_data(as_text=True)
+            '<a href="/login/?next=' in output.get_data(as_text=True)
         )
 
         user = tests.FakeUser()
diff --git a/tests/test_pagure_flask_ui_issues_open_access.py b/tests/test_pagure_flask_ui_issues_open_access.py
index 4fa6ff7..0a9a2df 100644
--- a/tests/test_pagure_flask_ui_issues_open_access.py
+++ b/tests/test_pagure_flask_ui_issues_open_access.py
@@ -213,8 +213,7 @@ class PagureFlaskIssuesOpenAccesstests(tests.Modeltests):
             output_text,
         )
         self.assertIn(
-            '<a href="/login/?next=http%3A%2F%2Flocalhost%2Ftest%2Fissue%2F1">'
-            "Login</a>\n          to comment on this ticket.",
+            '<a href="/login/?next=',
             output_text,
         )
 
@@ -312,10 +311,7 @@ class PagureFlaskIssuesOpenAccesstests(tests.Modeltests):
             'href="/test/issue/1/edit" title="Edit this issue">\n',
             output_text,
         )
-        self.assertTrue(
-            '<a href="/login/?next=http%3A%2F%2Flocalhost%2Ftest%2Fissue%2F1">'
-            "Login</a>\n          to comment on this ticket." in output_text
-        )
+        self.assertTrue('<a href="/login/?next=' in output_text)
 
         # Create issues to play with
         repo = pagure.lib.query.get_authorized_project(self.session, "test")
diff --git a/tests/test_pagure_flask_ui_login.py b/tests/test_pagure_flask_ui_login.py
index 5927cb0..287e951 100644
--- a/tests/test_pagure_flask_ui_login.py
+++ b/tests/test_pagure_flask_ui_login.py
@@ -1103,6 +1103,7 @@ class PagureFlaskLogintests(tests.SimplePagureTest):
                     "http://localhost/login/",
                     "/login/?next=http%3A%2F%2Flocalhost%2Fsettings%2F",
                     "http://localhost/login/?next=http%3A%2F%2Flocalhost%2Fsettings%2F",
+                    "/login/?next=http://localhost/settings/",
                 )
             )
         # session did not expire
diff --git a/tests/test_pagure_lib_encoding_utils.py b/tests/test_pagure_lib_encoding_utils.py
index dad98c9..95fca8b 100644
--- a/tests/test_pagure_lib_encoding_utils.py
+++ b/tests/test_pagure_lib_encoding_utils.py
@@ -50,7 +50,7 @@ class TestGuessEncoding(unittest.TestCase):
             self.assertEqual(result, "WINDOWS-1250")
         else:
             self.assertEqual(result, "utf-8")
-            if chardet.__version__[0] in ("3", "4"):
+            if chardet.__version__[0] in ("3", "4", "5"):
                 self.assertEqual(chardet_result["encoding"], "ISO-8859-9")
             else:
                 self.assertEqual(chardet_result["encoding"], "ISO-8859-2")
@@ -112,6 +112,49 @@ class TestGuessEncodings(unittest.TestCase):
                     expected_list,
                 )
                 self.assertEqual(chardet_result["encoding"], "ISO-8859-9")
+            elif chardet.__version__[0] in ("5"):
+                # The first three have different confidence values
+                expexted_list = ["utf-8", "ISO-8859-9", "ISO-8859-1"]
+                # This is the one with the least confidence
+                self.assertEqual(result[-1].encoding, "TIS-620")
+                self.assertListEqual(
+                    [encoding.encoding for encoding in result][:3],
+                    expexted_list,
+                )
+
+                # The values in the middle of the list all have the same confidence
+                # value and can't be sorted reliably: use sets.
+                expected_list = sorted(
+                    [
+                        "utf-8",
+                        "ISO-8859-9",
+                        "ISO-8859-1",
+                        "MacCyrillic",
+                        "IBM866",
+                        "TIS-620",
+                        "EUC-JP",
+                        "EUC-KR",
+                        "GB2312",
+                        "KOI8-R",
+                        "Johab",
+                        "Big5",
+                        "IBM855",
+                        "ISO-8859-7",
+                        "SHIFT_JIS",
+                        "windows-1253",
+                        "MacRoman",
+                        "CP949",
+                        "EUC-TW",
+                        "ISO-8859-5",
+                        "windows-1251",
+                        "windows-1255",
+                    ]
+                )
+                self.assertListEqual(
+                    sorted(set([encoding.encoding for encoding in result])),
+                    expected_list,
+                )
+                self.assertEqual(chardet_result["encoding"], "ISO-8859-9")
             else:
                 self.assertListEqual(
                     [encoding.encoding for encoding in result],

