Skip to content

Commit

Permalink
Revert "Setup VCR for dry tests"
Browse files Browse the repository at this point in the history
This reverts commit 34ca29a.

Bug: T198454
Bug: T184081
Bug: T196838
Change-Id: Ida8867830068c5e9df200849ea7dc7995d33fec0
  • Loading branch information
5j9 committed Sep 2, 2018
1 parent 35796fb commit 787f9ea
Show file tree
Hide file tree
Showing 9 changed files with 1 addition and 2,018 deletions.
6 changes: 0 additions & 6 deletions dev-requirements.txt
Expand Up @@ -23,12 +23,6 @@ codecov
coverage
mock ; python_version < '3'

# vcrpy requires yarl in Python 3.4, yarl v1.0.0 requires multidict>=4.0.0,
# multidict v4.0.0 requires Python>=3.4.1 (T185000)
yarl<1.0.0 ; python_version == "3.4" and python_full_version < "3.4.1"
multidict<4.0.0,>=2.0 ; python_version == "3.4" and python_full_version < "3.4.1"
vcrpy-unittest

# pywin32 & pywinauto>=0.4.0 are Win32 UI test dependencies that have been
# excluded from this file as they are quite expensive to install, and they
# are not useful on the Appveyor Win32 builds since the relevant UI tests
Expand Down
5 changes: 0 additions & 5 deletions tests/README.rst
Expand Up @@ -228,10 +228,6 @@ To enable 'write' tests, set PYWIKIBOT_TEST_WRITE=1
Enabling only 'edit failure' tests or 'write' tests won't enable the other tests
automatically.

Some tests are also using VCR.py, which means that these tests are dry and all
requests are recorded and used later, being stored in 'tests/cassettes'.
To avoid using recorded requests and to run live tests set PYWIKIBOT_LIVE_TESTS=1

Decorators
=====================

Expand Down Expand Up @@ -362,4 +358,3 @@ Other class attributes
- ``user = True`` : test class needs to login to site
- ``sysop = True`` : test class needs to login to site as a sysop
- ``write = True`` : test class needs to write to a site
- ``vcr = True``: test class uses VCR.py to record requests for dry testing
14 changes: 0 additions & 14 deletions tests/api_tests.py
Expand Up @@ -883,11 +883,9 @@ class TestCachedRequest(DefaultSiteTestCase):
"""Test API Request caching.
This test class does not use the forced test caching.
This class contains test cases with requests which are mocked with VCR.
"""

cached = False
vcr = True

def test_normal_use(self):
"""Test the caching of CachedRequest with an ordinary request."""
Expand Down Expand Up @@ -915,18 +913,6 @@ def test_normal_use(self):
self.assertIsNotNone(req3._cachetime)
self.assertEqual(req2._cachetime, req3._cachetime)


class TestCachedRequestNonVCR(DefaultSiteTestCase):

"""Test API Request caching (live without VCR).
This test class does not use the forced test caching.
This class contains test cases with requests which can't be mocked
with VCR.
"""

cached = False

def test_internals(self):
"""Test the caching of CachedRequest by faking a unique request."""
mysite = self.get_site()
Expand Down
68 changes: 1 addition & 67 deletions tests/aspects.py
Expand Up @@ -54,15 +54,6 @@
WarningSourceSkipContextManager, AssertAPIErrorContextManager,
)

try:
import vcr_unittest
VCRUnittestMixin = vcr_unittest.VCRMixin
except ImportError:
class VCRUnittestMixin(object):
"""Empty mixin class in case vcr_unittest is not installed."""

pass

try:
import pytest_httpbin
optional_pytest_httpbin_cls_decorator = pytest_httpbin.use_class_based_httpbin
Expand Down Expand Up @@ -713,59 +704,6 @@ def get_userpage(self, site=None):
return userpage


class VCRMixin(VCRUnittestMixin):

"""Run dry tests using vcrpy to record and mock requests."""

def _get_vcr(self, **kwargs):
"""Configure VCR."""
vcr = super(VCRMixin, self)._get_vcr(**kwargs)
vcr.record_mode = 'once'
vcr.decode_compressed_response = True
vcr.before_record_request = self.before_record_request
vcr.before_record_response = self.before_record_response
return vcr

def _get_cassette_name(self):
"""Get name of VCR cassette."""
if hasattr(self, 'sites'):
# Multiple sites are used in this class
# Let's guess which of them is used for this test method by name
for name in self.sites:
if self._testMethodName.endswith('_' + name.replace('-', '_')):
break
family = self.sites[name]['family']
code = self.sites[name]['code']
return '{0}.{1}/{2}.{3}.yaml'.format(family, code,
self.__class__.__name__,
self._testMethodName)
else:
return '{0}/{1}.{2}.yaml'.format(str(self.site).replace(':', '.'),
self.__class__.__name__,
self._testMethodName)

def before_record_request(self, request):
"""Remove headers containing sensitive data from request."""
# TODO: custom cookie processing if user=True
if 'Cookie' in request.headers:
del request.headers['Cookie']
if 'user-agent' in request.headers:
del request.headers['user-agent']

return request

def before_record_response(self, response):
"""Remove headers containing sensitive data from response."""
# TODO: custom cookie processing if user=True
for header in ['Set-Cookie', 'X-Client-IP']:
if header in response['headers']:
del response['headers'][header]
if header.lower() in response['headers']:
del response['headers'][header.lower()]

return response


class MetaTestCaseClass(type):

"""Test meta class."""
Expand Down Expand Up @@ -907,11 +845,7 @@ def wrapped_method(self):
if 'cached' in dct and dct['cached']:
bases = cls.add_base(bases, ForceCacheMixin)

if ('vcr' in dct and dct['vcr'] and
'PYWIKIBOT_LIVE_TESTS' not in os.environ):
bases = cls.add_base(bases, VCRMixin)
del dct['net']
elif 'net' in dct and dct['net']:
if 'net' in dct and dct['net']:
bases = cls.add_base(bases, CheckHostnameMixin)
else:
assert not hostnames, 'net must be True with hostnames defined'
Expand Down

This file was deleted.

1,111 changes: 0 additions & 1,111 deletions tests/cassettes/wikidata.wikidata/TestOwnClient.test_own_client_wikidata.yaml

This file was deleted.

394 changes: 0 additions & 394 deletions tests/cassettes/wikipedia.en/TestCachedRequest.test_normal_use.yaml

This file was deleted.

2 changes: 0 additions & 2 deletions tests/wikibase_tests.py
Expand Up @@ -1863,8 +1863,6 @@ class TestOwnClient(TestCase):
},
}

vcr = True

def test_own_client(self, key):
"""Test that a data repository family can be its own client."""
site = self.get_site(key)
Expand Down
2 changes: 0 additions & 2 deletions tox.ini
Expand Up @@ -79,7 +79,6 @@ deps =
nose-detecthttp
unicodecsv
mock
vcrpy-unittest

[testenv:nose34]
basepython = python3
Expand All @@ -94,7 +93,6 @@ deps =
nose-detecthttp>=0.1.3
six
mock
vcrpy-unittest

[testenv:doctest]
commands =
Expand Down

0 comments on commit 787f9ea

Please sign in to comment.