Fix occasional failures in check stage

(cherry picked from commit d86db279b1bc46e88aa69f128d7eaee7cb48b4b0)
This commit is contained in:
starlet-dx 2022-12-30 14:52:52 +08:00 committed by openeuler-sync-bot
parent 9749f8231e
commit eaca40cb98
2 changed files with 230 additions and 3 deletions

View File

@ -0,0 +1,221 @@
From 863a3107ec46f56a2cea1a122dc3c78f34b7f132 Mon Sep 17 00:00:00 2001
From: starlet-dx <15929766099@163.com>
Date: Fri, 30 Dec 2022 14:44:57 +0800
Subject: [PATCH 1/1] Mock time to make date based tests reliable
---
tests/functional/test_httplib2.py | 19 ++++++++++---------
tests/functional/test_requests.py | 19 ++++++++++---------
tests/functional/test_urllib2.py | 19 ++++++++++---------
3 files changed, 30 insertions(+), 27 deletions(-)
diff --git a/tests/functional/test_httplib2.py b/tests/functional/test_httplib2.py
index 3b78043..519d430 100644
--- a/tests/functional/test_httplib2.py
+++ b/tests/functional/test_httplib2.py
@@ -28,6 +28,7 @@ from __future__ import unicode_literals
import re
import httplib2
+from freezegun import freeze_time
from sure import expect, within, microseconds
from httpretty import HTTPretty, httprettified
from httpretty.core import decode_utf8
@@ -64,8 +65,8 @@ def test_httpretty_provides_easy_access_to_querystrings(now):
@httprettified
-@within(two=microseconds)
-def test_httpretty_should_mock_headers_httplib2(now):
+@freeze_time("2013-10-04 04:20:00")
+def test_httpretty_should_mock_headers_httplib2():
"HTTPretty should mock basic headers with httplib2"
HTTPretty.register_uri(HTTPretty.GET, "http://github.com/",
@@ -80,13 +81,13 @@ def test_httpretty_should_mock_headers_httplib2(now):
'content-length': '35',
'status': '201',
'server': 'Python/HTTPretty',
- 'date': now.strftime('%a, %d %b %Y %H:%M:%S GMT'),
+ 'date': 'Fri, 04 Oct 2013 04:20:00 GMT',
})
@httprettified
-@within(two=microseconds)
-def test_httpretty_should_allow_adding_and_overwritting_httplib2(now):
+@freeze_time("2013-10-04 04:20:00")
+def test_httpretty_should_allow_adding_and_overwritting_httplib2():
"HTTPretty should allow adding and overwritting headers with httplib2"
HTTPretty.register_uri(HTTPretty.GET, "http://github.com/foo",
@@ -106,7 +107,7 @@ def test_httpretty_should_allow_adding_and_overwritting_httplib2(now):
'content-length': '27',
'status': '200',
'server': 'Apache',
- 'date': now.strftime('%a, %d %b %Y %H:%M:%S GMT'),
+ 'date': 'Fri, 04 Oct 2013 04:20:00 GMT',
})
@@ -135,8 +136,8 @@ def test_httpretty_should_allow_forcing_headers_httplib2(now):
@httprettified
-@within(two=microseconds)
-def test_httpretty_should_allow_adding_and_overwritting_by_kwargs_u2(now):
+@freeze_time("2013-10-04 04:20:00")
+def test_httpretty_should_allow_adding_and_overwritting_by_kwargs_u2():
"HTTPretty should allow adding and overwritting headers by keyword args " \
"with httplib2"
@@ -159,7 +160,7 @@ def test_httpretty_should_allow_adding_and_overwritting_by_kwargs_u2(now):
'content-length': '27',
'status': '200',
'server': 'Apache',
- 'date': now.strftime('%a, %d %b %Y %H:%M:%S GMT'),
+ 'date': 'Fri, 04 Oct 2013 04:20:00 GMT',
})
diff --git a/tests/functional/test_requests.py b/tests/functional/test_requests.py
index e98b23f..4428039 100644
--- a/tests/functional/test_requests.py
+++ b/tests/functional/test_requests.py
@@ -31,6 +31,7 @@ import os
import re
import json
import requests
+from freezegun import freeze_time
from sure import within, microseconds, expect
from tornado import version as tornado_version
from httpretty import HTTPretty, httprettified
@@ -93,8 +94,8 @@ def test_httpretty_provides_easy_access_to_querystrings(now):
@httprettified
-@within(two=microseconds)
-def test_httpretty_should_mock_headers_requests(now):
+@freeze_time("2013-10-04 04:20:00")
+def test_httpretty_should_mock_headers_requests():
"HTTPretty should mock basic headers with requests"
HTTPretty.register_uri(HTTPretty.GET, "http://github.com/",
@@ -110,13 +111,13 @@ def test_httpretty_should_mock_headers_requests(now):
'content-length': '35',
'status': '201',
'server': 'Python/HTTPretty',
- 'date': now.strftime('%a, %d %b %Y %H:%M:%S GMT'),
+ 'date': 'Fri, 04 Oct 2013 04:20:00 GMT',
})
@httprettified
-@within(two=microseconds)
-def test_httpretty_should_allow_adding_and_overwritting_requests(now):
+@freeze_time("2013-10-04 04:20:00")
+def test_httpretty_should_allow_adding_and_overwritting_requests():
"HTTPretty should allow adding and overwritting headers with requests"
HTTPretty.register_uri(HTTPretty.GET, "http://github.com/foo",
@@ -135,7 +136,7 @@ def test_httpretty_should_allow_adding_and_overwritting_requests(now):
'content-length': '27',
'status': '200',
'server': 'Apache',
- 'date': now.strftime('%a, %d %b %Y %H:%M:%S GMT'),
+ 'date': 'Fri, 04 Oct 2013 04:20:00 GMT',
})
@@ -160,8 +161,8 @@ def test_httpretty_should_allow_forcing_headers_requests(now):
@httprettified
-@within(two=microseconds)
-def test_httpretty_should_allow_adding_and_overwritting_by_kwargs_u2(now):
+@freeze_time("2013-10-04 04:20:00")
+def test_httpretty_should_allow_adding_and_overwritting_by_kwargs_u2():
"HTTPretty should allow adding and overwritting headers by keyword args " \
"with requests"
@@ -179,7 +180,7 @@ def test_httpretty_should_allow_adding_and_overwritting_by_kwargs_u2(now):
'content-length': '27',
'status': '200',
'server': 'Apache',
- 'date': now.strftime('%a, %d %b %Y %H:%M:%S GMT'),
+ 'date': 'Fri, 04 Oct 2013 04:20:00 GMT',
})
diff --git a/tests/functional/test_urllib2.py b/tests/functional/test_urllib2.py
index d1b92ee..90e4c46 100644
--- a/tests/functional/test_urllib2.py
+++ b/tests/functional/test_urllib2.py
@@ -34,6 +34,7 @@ except ImportError:
import urllib2
urlopen = urllib2.urlopen
+from freezegun import freeze_time
from sure import within, microseconds
from httpretty import HTTPretty, httprettified
from httpretty.core import decode_utf8
@@ -73,8 +74,8 @@ def test_httpretty_provides_easy_access_to_querystrings(now):
@httprettified
-@within(two=microseconds)
-def test_httpretty_should_mock_headers_urllib2(now):
+@freeze_time("2013-10-04 04:20:00")
+def test_httpretty_should_mock_headers_urllib2():
"HTTPretty should mock basic headers with urllib2"
HTTPretty.register_uri(HTTPretty.GET, "http://github.com/",
@@ -93,13 +94,13 @@ def test_httpretty_should_mock_headers_urllib2(now):
'content-length': '35',
'status': '201',
'server': 'Python/HTTPretty',
- 'date': now.strftime('%a, %d %b %Y %H:%M:%S GMT'),
+ 'date': 'Fri, 04 Oct 2013 04:20:00 GMT',
})
@httprettified
-@within(two=microseconds)
-def test_httpretty_should_allow_adding_and_overwritting_urllib2(now):
+@freeze_time("2013-10-04 04:20:00")
+def test_httpretty_should_allow_adding_and_overwritting_urllib2():
"HTTPretty should allow adding and overwritting headers with urllib2"
HTTPretty.register_uri(HTTPretty.GET, "http://github.com/",
@@ -121,7 +122,7 @@ def test_httpretty_should_allow_adding_and_overwritting_urllib2(now):
'content-length': '27',
'status': '200',
'server': 'Apache',
- 'date': now.strftime('%a, %d %b %Y %H:%M:%S GMT'),
+ 'date': 'Fri, 04 Oct 2013 04:20:00 GMT',
})
@@ -148,8 +149,8 @@ def test_httpretty_should_allow_forcing_headers_urllib2():
@httprettified
-@within(two=microseconds)
-def test_httpretty_should_allow_adding_and_overwritting_by_kwargs_u2(now):
+@freeze_time("2013-10-04 04:20:00")
+def test_httpretty_should_allow_adding_and_overwritting_by_kwargs_u2():
("HTTPretty should allow adding and overwritting headers by "
"keyword args with urllib2")
@@ -171,7 +172,7 @@ def test_httpretty_should_allow_adding_and_overwritting_by_kwargs_u2(now):
'content-length': str(len(body)),
'status': '200',
'server': 'Apache',
- 'date': now.strftime('%a, %d %b %Y %H:%M:%S GMT'),
+ 'date': 'Fri, 04 Oct 2013 04:20:00 GMT',
})
--
2.30.0

View File

@ -1,6 +1,6 @@
Name: python-httpretty Name: python-httpretty
Version: 0.9.5 Version: 0.9.5
Release: 4 Release: 5
Summary: HTTP Client mocking tool for Python Summary: HTTP Client mocking tool for Python
License: MIT License: MIT
URL: https://pypi.org/project/httpretty/ URL: https://pypi.org/project/httpretty/
@ -9,9 +9,11 @@ Source0: https://files.pythonhosted.org/packages/source/h/httpretty/httpr
Patch0001: python-httpretty-fakesock_getpeercert_noconnect.patch Patch0001: python-httpretty-fakesock_getpeercert_noconnect.patch
Patch0002: 0001-Handle-bugs-in-older-urllib3-versions-in-one-of-the-.patch Patch0002: 0001-Handle-bugs-in-older-urllib3-versions-in-one-of-the-.patch
Patch0003: 0001-Call-reset-from-setUp-and-tearDown-in-addition-to-en.patch Patch0003: 0001-Call-reset-from-setUp-and-tearDown-in-addition-to-en.patch
Patch0004: Mock-time-to-make-date-based-tests-reliable.patch
BuildRequires: python2-devel python2-setuptools python2-httplib2 python2-mock python2-nose BuildRequires: python2-devel python2-setuptools python2-httplib2 python2-mock python2-nose
BuildRequires: python2-requests python2-sure python2-urllib3 python2-tornado python-unittest2 BuildRequires: python2-requests python2-sure python2-urllib3 python2-tornado python-unittest2
BuildRequires: python2-freezegun
BuildArch: noarch BuildArch: noarch
@ -29,7 +31,8 @@ HTTP Client mocking tool for Python2.Provides a full fake TCP socket module.
%package -n python3-httpretty %package -n python3-httpretty
Summary: HTTP Client mocking tool for Python3 Summary: HTTP Client mocking tool for Python3
BuildRequires: python3-devel python3-setuptools python3-httplib2 python3-mock BuildRequires: python3-devel python3-setuptools python3-httplib2 python3-mock
BuildRequires: python3-nose python3-requests python3-sure python3-urllib3 python3-tornado BuildRequires: python3-nose2 python3-requests python3-sure python3-urllib3 python3-tornado
BuildRequires: python3-freezegun
Requires: python3-six Requires: python3-six
%{?python_provide:%python_provide python3-httpretty} %{?python_provide:%python_provide python3-httpretty}
@ -51,7 +54,7 @@ LANG=en_US.UTF-8 %py3_install
%check %check
LANG=en_US.UTF-8 %{__python2} -m nose -v LANG=en_US.UTF-8 %{__python2} -m nose -v
LANG=en_US.UTF-8 %{__python3} -m nose -v LANG=en_US.UTF-8 %{__python3} -m nose2 -v
%files -n python2-httpretty %files -n python2-httpretty
%doc README.rst %doc README.rst
@ -66,5 +69,8 @@ LANG=en_US.UTF-8 %{__python3} -m nose -v
%{python3_sitelib}/httpretty-%{version}-py3.?.egg-info %{python3_sitelib}/httpretty-%{version}-py3.?.egg-info
%changelog %changelog
* Fri Dec 30 2022 yaoxin <yaoxin30@h-partners.com> - 0.9.5-5
- Fix occasional failures in check stage
* Sat Nov 23 2019 zhouyihang <zhouyihang1@huawei.com> - 0.9.5-4 * Sat Nov 23 2019 zhouyihang <zhouyihang1@huawei.com> - 0.9.5-4
- Package init - Package init