aboutsummaryrefslogtreecommitdiffstats
path: root/meta-python/recipes-devtools/python/python3-betamax/0001-Drop-ptests-fixtures-and-recorde_modes.patch
blob: 52745a9373e83c03bbcda3cc9baf2368f570d48a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
From e5aa66b1af2d49f159c4daefc598f96744ee988d Mon Sep 17 00:00:00 2001
From: Zhixiong Chi <zhixiong.chi@windriver.com>
Date: Thu, 29 Feb 2024 12:31:58 -0800
Subject: [PATCH] [PATCH] Drop ptests fixtures and recorde_modes

The usage of fixture in test_fixtures has been deprecated.
See https://docs.pytest.org/en/stable/explanation/fixtures.html and
https://docs.pytest.org/en/stable/deprecations.html#calling-fixtures-directly
for more information about fixtures.
Meanwhile the test_record_modes relies on httpbin.org which has been sold and
re-sold several times, and it adds X-Amzn-Trace-Id header that can possibly
diff for each request.
It leads to ptest failure, so drop it now until we find the solution.

Upstream-Status: Inappropriate [OE-Specific]

Signed-off-by: Zhixiong Chi <zhixiong.chi@windriver.com>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 tests/integration/test_fixtures.py     |  60 -----------
 tests/integration/test_record_modes.py | 141 -------------------------
 tests/unit/test_fixtures.py            |  94 -----------------
 3 files changed, 295 deletions(-)
 delete mode 100644 tests/integration/test_fixtures.py
 delete mode 100644 tests/integration/test_record_modes.py
 delete mode 100644 tests/unit/test_fixtures.py

diff --git a/tests/integration/test_fixtures.py b/tests/integration/test_fixtures.py
deleted file mode 100644
index fc3d1e7..0000000
--- a/tests/integration/test_fixtures.py
+++ /dev/null
@@ -1,60 +0,0 @@
-import os.path
-
-import pytest
-
-
-@pytest.mark.usefixtures('betamax_session')
-class TestPyTestFixtures:
-    @pytest.fixture(autouse=True)
-    def setup(self, request):
-        """After test hook to assert everything."""
-        def finalizer():
-            test_dir = os.path.abspath('.')
-            cassette_name = ('tests.integration.test_fixtures.'  # Module name
-                             'TestPyTestFixtures.'  # Class name
-                             'test_pytest_fixture'  # Test function name
-                             '.json')
-            file_name = os.path.join(test_dir, 'tests', 'cassettes',
-                                     cassette_name)
-            assert os.path.exists(file_name) is True
-
-        request.addfinalizer(finalizer)
-
-    def test_pytest_fixture(self, betamax_session):
-        """Exercise the fixture itself."""
-        resp = betamax_session.get('https://httpbin.org/get')
-        assert resp.ok
-
-
-@pytest.mark.usefixtures('betamax_parametrized_session')
-class TestPyTestParametrizedFixtures:
-    @pytest.fixture(autouse=True)
-    def setup(self, request):
-        """After test hook to assert everything."""
-        def finalizer():
-            test_dir = os.path.abspath('.')
-            cassette_name = ('tests.integration.test_fixtures.'  # Module name
-                             'TestPyTestParametrizedFixtures.'  # Class name
-                             'test_pytest_fixture'  # Test function name
-                             '[https---httpbin.org-get]'  # Parameter
-                             '.json')
-            file_name = os.path.join(test_dir, 'tests', 'cassettes',
-                                     cassette_name)
-            assert os.path.exists(file_name) is True
-
-        request.addfinalizer(finalizer)
-
-    @pytest.mark.parametrize('url', ('https://httpbin.org/get',))
-    def test_pytest_fixture(self, betamax_parametrized_session, url):
-        """Exercise the fixture itself."""
-        resp = betamax_parametrized_session.get(url)
-        assert resp.ok
-
-
-@pytest.mark.parametrize('problematic_arg', [r'aaa\bbb', 'ccc:ddd', 'eee*fff'])
-def test_pytest_parametrize_with_filesystem_problematic_chars(
-        betamax_parametrized_session, problematic_arg):
-    """
-    Exercice parametrized args containing characters which might cause
-    problems when getting translated into file names. """
-    assert True
diff --git a/tests/integration/test_record_modes.py b/tests/integration/test_record_modes.py
deleted file mode 100644
index 988b851..0000000
--- a/tests/integration/test_record_modes.py
+++ /dev/null
@@ -1,141 +0,0 @@
-import re
-
-from betamax import Betamax, BetamaxError
-
-from tests.integration.helper import IntegrationHelper
-
-
-class TestRecordOnce(IntegrationHelper):
-    def test_records_new_interaction(self):
-        s = self.session
-        with Betamax(s).use_cassette('test_record_once') as betamax:
-            self.cassette_path = betamax.current_cassette.cassette_path
-            assert betamax.current_cassette.is_empty() is True
-            r = s.get('http://httpbin.org/get')
-            assert r.status_code == 200
-            assert betamax.current_cassette.is_empty() is True
-            assert betamax.current_cassette.interactions != []
-
-    def test_replays_response_from_cassette(self):
-        s = self.session
-        with Betamax(s).use_cassette('test_replays_response') as betamax:
-            self.cassette_path = betamax.current_cassette.cassette_path
-            assert betamax.current_cassette.is_empty() is True
-            r0 = s.get('http://httpbin.org/get')
-            assert r0.status_code == 200
-            assert betamax.current_cassette.interactions != []
-            assert len(betamax.current_cassette.interactions) == 1
-            r1 = s.get('http://httpbin.org/get')
-            assert len(betamax.current_cassette.interactions) == 2
-            assert r1.status_code == 200
-            r0_headers = r0.headers.copy()
-            r0_headers.pop('Date')
-            r0_headers.pop('Age', None)
-            r0_headers.pop('X-Processed-Time', None)
-            r1_headers = r1.headers.copy()
-            r1_headers.pop('Date')
-            r1_headers.pop('Age', None)
-            r1_headers.pop('X-Processed-Time', None)
-            # NOTE(sigmavirus24): This fails if the second request is
-            # technically a second later. Ignoring the Date headers allows
-            # this test to succeed.
-            # NOTE(hroncok): httpbin.org added X-Processed-Time header that
-            # can possibly differ (and often does)
-            r0_content = r0.content.decode(encoding='utf-8', errors='strict')
-            r1_content = r1.content.decode(encoding='utf-8', errors='strict')
-            r0_content = re.sub('"X-Amzn-Trace-Id": "[^"]+"', '"X-Amzn-Trace-Id": ""', r0_content)
-            r1_content = re.sub('"X-Amzn-Trace-Id": "[^"]+"', '"X-Amzn-Trace-Id": ""', r1_content)
-            # NOTE(jhatler): httpbin.org added "X-Amzn-Trace-Id" to their
-            # response, which is a unique ID that will differ between requests.
-            # We remove it from the response body before comparing.
-            assert r0_headers == r1_headers
-            assert r0_content == r1_content
-
-
-class TestRecordNone(IntegrationHelper):
-    def test_raises_exception_when_no_interactions_present(self):
-        s = self.session
-        with Betamax(s) as betamax:
-            betamax.use_cassette('test', record='none')
-            self.cassette_created = False
-            assert betamax.current_cassette is not None
-            self.assertRaises(BetamaxError, s.get, 'http://httpbin.org/get')
-
-    def test_record_none_does_not_create_cassettes(self):
-        s = self.session
-        with Betamax(s) as betamax:
-            self.assertRaises(ValueError, betamax.use_cassette,
-                              'test_record_none', record='none')
-        self.cassette_created = False
-
-
-class TestRecordNewEpisodes(IntegrationHelper):
-    def setUp(self):
-        super(TestRecordNewEpisodes, self).setUp()
-        with Betamax(self.session).use_cassette('test_record_new'):
-            self.session.get('http://httpbin.org/get')
-            self.session.get('http://httpbin.org/redirect/2')
-
-    def test_records_new_events_with_existing_cassette(self):
-        s = self.session
-        opts = {'record': 'new_episodes'}
-        with Betamax(s).use_cassette('test_record_new', **opts) as betamax:
-            cassette = betamax.current_cassette
-            self.cassette_path = cassette.cassette_path
-            assert cassette.interactions != []
-            assert len(cassette.interactions) == 4
-            assert cassette.is_empty() is False
-            s.get('https://httpbin.org/get')
-            assert len(cassette.interactions) == 5
-
-        with Betamax(s).use_cassette('test_record_new') as betamax:
-            cassette = betamax.current_cassette
-            assert len(cassette.interactions) == 5
-            r = s.get('https://httpbin.org/get')
-            assert r.status_code == 200
-
-
-class TestRecordNewEpisodesCreatesCassettes(IntegrationHelper):
-    def test_creates_new_cassettes(self):
-        recorder = Betamax(self.session)
-        opts = {'record': 'new_episodes'}
-        cassette_name = 'test_record_new_makes_new_cassettes'
-        with recorder.use_cassette(cassette_name, **opts) as betamax:
-            self.cassette_path = betamax.current_cassette.cassette_path
-            self.session.get('https://httpbin.org/get')
-
-
-class TestRecordAll(IntegrationHelper):
-    def setUp(self):
-        super(TestRecordAll, self).setUp()
-        with Betamax(self.session).use_cassette('test_record_all'):
-            self.session.get('http://httpbin.org/get')
-            self.session.get('http://httpbin.org/redirect/2')
-            self.session.get('http://httpbin.org/get')
-
-    def test_records_new_interactions(self):
-        s = self.session
-        opts = {'record': 'all'}
-        with Betamax(s).use_cassette('test_record_all', **opts) as betamax:
-            cassette = betamax.current_cassette
-            self.cassette_path = cassette.cassette_path
-            assert cassette.interactions != []
-            assert len(cassette.interactions) == 5
-            assert cassette.is_empty() is False
-            s.post('http://httpbin.org/post', data={'foo': 'bar'})
-            assert len(cassette.interactions) == 6
-
-        with Betamax(s).use_cassette('test_record_all') as betamax:
-            assert len(betamax.current_cassette.interactions) == 6
-
-    def test_replaces_old_interactions(self):
-        s = self.session
-        opts = {'record': 'all'}
-        with Betamax(s).use_cassette('test_record_all', **opts) as betamax:
-            cassette = betamax.current_cassette
-            self.cassette_path = cassette.cassette_path
-            assert cassette.interactions != []
-            assert len(cassette.interactions) == 5
-            assert cassette.is_empty() is False
-            s.get('http://httpbin.org/get')
-            assert len(cassette.interactions) == 5
diff --git a/tests/unit/test_fixtures.py b/tests/unit/test_fixtures.py
deleted file mode 100644
index 41f33eb..0000000
--- a/tests/unit/test_fixtures.py
+++ /dev/null
@@ -1,94 +0,0 @@
-try:
-    import unittest.mock as mock
-except ImportError:
-    import mock
-
-import pytest
-import unittest
-
-import requests
-
-import betamax
-from betamax.fixtures import pytest as pytest_fixture
-from betamax.fixtures import unittest as unittest_fixture
-
-
-class TestPyTestFixture(unittest.TestCase):
-    def setUp(self):
-        self.mocked_betamax = mock.MagicMock()
-        self.patched_betamax = mock.patch.object(
-            betamax.recorder, 'Betamax', return_value=self.mocked_betamax)
-        self.patched_betamax.start()
-
-    def tearDown(self):
-        self.patched_betamax.stop()
-
-    def test_adds_stop_as_a_finalizer(self):
-        # Mock a pytest request object
-        request = mock.MagicMock()
-        request.cls = request.module = None
-        request.node.name = request.function.__name__ = 'test'
-
-        pytest_fixture._betamax_recorder(request)
-        assert request.addfinalizer.called is True
-        request.addfinalizer.assert_called_once_with(self.mocked_betamax.stop)
-
-    def test_auto_starts_the_recorder(self):
-        # Mock a pytest request object
-        request = mock.MagicMock()
-        request.cls = request.module = None
-        request.node.name = request.function.__name__ = 'test'
-
-        pytest_fixture._betamax_recorder(request)
-        self.mocked_betamax.start.assert_called_once_with()
-
-
-class FakeBetamaxTestCase(unittest_fixture.BetamaxTestCase):
-    def test_fake(self):
-        pass
-
-
-class TestUnittestFixture(unittest.TestCase):
-    def setUp(self):
-        self.mocked_betamax = mock.MagicMock()
-        self.patched_betamax = mock.patch.object(
-            betamax.recorder, 'Betamax', return_value=self.mocked_betamax)
-        self.betamax = self.patched_betamax.start()
-        self.fixture = FakeBetamaxTestCase(methodName='test_fake')
-
-    def tearDown(self):
-        self.patched_betamax.stop()
-
-    def test_setUp(self):
-        self.fixture.setUp()
-
-        self.mocked_betamax.use_cassette.assert_called_once_with(
-            'FakeBetamaxTestCase.test_fake'
-        )
-        self.mocked_betamax.start.assert_called_once_with()
-
-    def test_setUp_rejects_arbitrary_session_classes(self):
-        self.fixture.SESSION_CLASS = object
-
-        with pytest.raises(AssertionError):
-            self.fixture.setUp()
-
-    def test_setUp_accepts_session_subclasses(self):
-        class TestSession(requests.Session):
-            pass
-
-        self.fixture.SESSION_CLASS = TestSession
-
-        self.fixture.setUp()
-
-        assert self.betamax.called is True
-        call_kwargs = self.betamax.call_args[-1]
-        assert isinstance(call_kwargs['session'], TestSession)
-
-    def test_tearDown_calls_stop(self):
-        recorder = mock.Mock()
-        self.fixture.recorder = recorder
-
-        self.fixture.tearDown()
-
-        recorder.stop.assert_called_once_with()
-- 
2.44.0