From 970a8cea3cca678962e39311ff3184fe4dee60b760cf65e2be6dcdbe903d818b Mon Sep 17 00:00:00 2001 From: Matej Cepl Date: Wed, 25 Nov 2020 13:44:34 +0000 Subject: [PATCH] Accepting request 850728 from home:mcepl:branches:devel:languages:python - Add two-basic-unit-tests.patch which includes two at least simple test patches (gh#certifi/python-certifi#137). OBS-URL: https://build.opensuse.org/request/show/850728 OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-certifi?expand=0&rev=50 --- ...on-certifi-shipped-requests-cabundle.patch | 24 ++++-- python-certifi.changes | 6 ++ python-certifi.spec | 16 ++-- two-basic-unit-tests.patch | 83 +++++++++++++++++++ 4 files changed, 112 insertions(+), 17 deletions(-) create mode 100644 two-basic-unit-tests.patch diff --git a/python-certifi-shipped-requests-cabundle.patch b/python-certifi-shipped-requests-cabundle.patch index 864f7ba..c8b2728 100644 --- a/python-certifi-shipped-requests-cabundle.patch +++ b/python-certifi-shipped-requests-cabundle.patch @@ -1,22 +1,30 @@ -diff -ur certifi-2020.6.20.o/certifi/core.py certifi-2020.6.20/certifi/core.py ---- certifi-2020.6.20.o/certifi/core.py 2020-06-07 11:35:28.000000000 +0200 -+++ certifi-2020.6.20/certifi/core.py 2020-08-16 19:38:17.167625302 +0200 -@@ -5,56 +5,18 @@ +--- + certifi/core.py | 54 +++++++++--------------------------------------------- + 1 file changed, 9 insertions(+), 45 deletions(-) + +--- a/certifi/core.py ++++ b/certifi/core.py +@@ -1,60 +1,24 @@ + # -*- coding: utf-8 -*- ++import io + + """ + certifi.py ~~~~~~~~~~ This module returns the installation location of cacert.pem or its contents. --""" ++ ++Patched by openSUSE: return the system bundle + """ -import os -try: - from importlib.resources import path as get_path, read_text -+Patched by openSUSE: return the system bundle -+""" - _CACERT_CTX = None - _CACERT_PATH = None +def read_text(_module=None, _path=None, encoding="ascii"): -+ with open(where(), "r", encoding=encoding) as data: ++ with io.open(where(), "r", encoding=encoding) as data: + return data.read() - def where(): diff --git a/python-certifi.changes b/python-certifi.changes index 8d84caf..8c9b068 100644 --- a/python-certifi.changes +++ b/python-certifi.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Wed Nov 25 11:41:29 UTC 2020 - Matej Cepl + +- Add two-basic-unit-tests.patch which includes two at least simple test + patches (gh#certifi/python-certifi#137). + ------------------------------------------------------------------- Sun Aug 16 17:45:09 UTC 2020 - Benjamin Greiner diff --git a/python-certifi.spec b/python-certifi.spec index 93393f0..d79d767 100644 --- a/python-certifi.spec +++ b/python-certifi.spec @@ -25,10 +25,14 @@ License: MPL-2.0 Group: Development/Languages/Python URL: https://github.com/certifi/python-certifi Source: https://files.pythonhosted.org/packages/source/c/certifi/certifi-%{version}.tar.gz -# PATCH-FIX-SUSE -- prefer SUSE certificates (only for use on SUSE platforms) +# PATCH-FIX-SUSE -- prefer SUSE certificates Patch0: python-certifi-shipped-requests-cabundle.patch +# PATCH-FEATURE-UPSTREAM two-basic-unit-tests.patch gh#certifi/python-certifi#137 mcepl@suse.com +# Add at least primitive test suite (by bnavigator) +Patch1: two-basic-unit-tests.patch BuildRequires: %{python_module setuptools} BuildRequires: ca-certificates +BuildRequires: ca-certificates-mozilla BuildRequires: fdupes BuildRequires: python-rpm-macros Requires: ca-certificates @@ -44,10 +48,7 @@ identity of TLS hosts. It has been extracted from the Requests project. Note that on SUSE packages the used CA bundle is actually the system bundle %prep -%setup -q -n certifi-%{version} -%if 0%{?suse_version} -%patch0 -p1 -%endif +%autosetup -p1 -n certifi-%{version} %build %python_build @@ -57,9 +58,7 @@ Note that on SUSE packages the used CA bundle is actually the system bundle %{python_expand chmod +x %{buildroot}%{$python_sitelib}/certifi/core.py sed -i "s|#!%{_bindir}/env python|#!%__$python|" %{buildroot}/%{$python_sitelib}/certifi/core.py - %if 0%{?suse_version} rm %{buildroot}%{$python_sitelib}/certifi/cacert.pem - %endif } %python_expand $python -m compileall %{buildroot}%{$python_sitelib}/certifi/ @@ -68,8 +67,7 @@ Note that on SUSE packages the used CA bundle is actually the system bundle %python_expand %fdupes %{buildroot}%{$python_sitelib} %check -# There are no upstream unit tests https://github.com/certifi/python-certifi/issues/136 -# Please check that downstream packages like python-requests still build after an update of certifi +%pyunittest -v certifi.tests.test_certifi %files %{python_files} %license LICENSE diff --git a/two-basic-unit-tests.patch b/two-basic-unit-tests.patch new file mode 100644 index 0000000..b39bc06 --- /dev/null +++ b/two-basic-unit-tests.patch @@ -0,0 +1,83 @@ +From 7d617ff9dddee73bde86b79c9aa2f1c98f19e339 Mon Sep 17 00:00:00 2001 +From: Benjamin Greiner +Date: Sun, 16 Aug 2020 20:17:39 +0200 +Subject: [PATCH 1/2] add 2 basic unit tests + +--- + .github/workflows/python-package.yml | 40 +++++++++++++++++++++++++++++++++++ + certifi/tests/__init__.py | 2 + + certifi/tests/test_certifi.py | 19 ++++++++++++++++ + 3 files changed, 61 insertions(+) + create mode 100644 certifi/tests/__init__.py + create mode 100755 certifi/tests/test_certifi.py + +--- /dev/null ++++ b/certifi/tests/__init__.py +@@ -0,0 +1,2 @@ ++# certifi.tests module ++ +--- /dev/null ++++ b/certifi/tests/test_certifi.py +@@ -0,0 +1,19 @@ ++# -*- coding: utf-8 -*- ++""" ++unit tests to make sure everything behaves as expected ++""" ++ ++import os ++import unittest ++ ++import certifi ++ ++ ++class TestCertifi(unittest.TestCase): ++ def test_cabundle_exists(self): ++ """Check that the reported bundle exists""" ++ self.assertTrue(os.path.exists(certifi.where())) ++ ++ def test_read_contents(self): ++ """Check that the returned contents contain a certificate""" ++ self.assertIn("-----BEGIN CERTIFICATE-----", certifi.contents()) +--- /dev/null ++++ b/.github/workflows/python-package.yml +@@ -0,0 +1,40 @@ ++# This workflow will install Python dependencies, run tests and lint with a variety of Python versions ++# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions ++ ++name: Python package ++ ++on: ++ push: ++ branches: [ master ] ++ pull_request: ++ branches: [ master ] ++ ++jobs: ++ build: ++ ++ runs-on: ubuntu-latest ++ strategy: ++ matrix: ++ python-version: [3.5, 3.6, 3.7, 3.8] ++ ++ steps: ++ - uses: actions/checkout@v2 ++ - name: Set up Python ${{ matrix.python-version }} ++ uses: actions/setup-python@v2 ++ with: ++ python-version: ${{ matrix.python-version }} ++ - name: Install test dependencies ++ run: | ++ python -m pip install --upgrade pip ++ pip install pytest ++ # pip install flake8 pytest ++ # if [ -f requirements.txt ]; then pip install -r requirements.txt; fi ++ #- name: Lint with flake8 ++ # run: | ++ # # stop the build if there are Python syntax errors or undefined names ++ # flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics ++ # # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide ++ # flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics ++ - name: Test with pytest ++ run: | ++ pytest