Skip to content

Commit fc5092a

Browse files
committed
Add FIXTURE_REWRITE
1 parent 4e929f4 commit fc5092a

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
0.7.11 Support FIXTURE_REWRITE env var
2+
13
0.7.6 Support redirects
24

35
0.7.5 Options to remove duplicate fixtures

README.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ it will check that ``response.status_code`` and ``response.content`` is the
3939
same, in future version, or in other configurations (ie. py35, py27, pypy, etc
4040
...).
4141

42+
Instead of deleting the fixtures manually before running the tests to
43+
regenerate them, just run your tests with FIXTURE_REWRITE=1 environment
44+
variable. This will overwrite the fixtures and make the tests look like it
45+
passed.
46+
4247
Requirements
4348
============
4449

responsediff/response.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
'&', ';',
1919
)
2020

21+
REWRITE = os.getenv('FIXTURE_REWRITE')
22+
2123

2224
def crossplatform_compatible(value):
2325
"""Strip out caracters incompatible between platforms."""
@@ -121,15 +123,17 @@ def make_diff(self, response, metadata=None, selector=None): # noqa: C901
121123
)
122124
mode = 'wb+'
123125

124-
if not os.path.exists(self.content_path):
126+
if not os.path.exists(self.content_path) or REWRITE:
125127
with open(self.content_path, mode) as f:
126128
f.write(content)
127-
created[self.content_path] = content
129+
if not REWRITE:
130+
created[self.content_path] = content
128131

129-
if not os.path.exists(self.metadata_path):
132+
if not os.path.exists(self.metadata_path) or REWRITE:
130133
with open(self.metadata_path, 'w+') as f:
131134
json.dump(metadata, f, indent=4, sort_keys=True)
132-
created[self.metadata_path] = json.dumps(metadata, indent=4)
135+
if not REWRITE:
136+
created[self.metadata_path] = json.dumps(metadata, indent=4)
133137

134138
fh, dump_path = tempfile.mkstemp('_responsediff')
135139
with os.fdopen(fh, mode) as f:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def read(fname):
1212

1313
setup(
1414
name='django-responsediff',
15-
version='0.7.6',
15+
version='0.7.11',
1616
description='HTTP response diffing against fixtures for testing',
1717
author='James Pic',
1818
author_email='[email protected]',

0 commit comments

Comments
 (0)