diff --git a/CHANGELOG.md b/CHANGELOG.md index 191eb47..5a59f4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ ### Added ### Fixed ### Changed +- requests status code is optional, defaults to 200 + ### Deprecated ### Removed ### Security diff --git a/pytest_filedata/__init__.py b/pytest_filedata/__init__.py index 1a1c9cc..f94c815 100644 --- a/pytest_filedata/__init__.py +++ b/pytest_filedata/__init__.py @@ -114,13 +114,18 @@ def callback(self, request, context): path = urlparse.urlparse(request.url).path path = os.path.join(test_dir, 'data', self.prefix, path.lstrip('/')) files = get_test_files(path) + if len(files) != 1: raise NotImplementedError("Currently there must be only one response file") fname = files[0] - # file extension is status code - context.status_code = int(os.path.splitext(fname)[1].lstrip('.')) + try: + # file extension is status code + context.status_code = int(os.path.splitext(fname)[1].lstrip('.')) + + except ValueError: + context.status_code = 200 with open(fname) as fobj: return fobj.read() diff --git a/tests/data/req/test0/data.200 b/tests/data/req/test0/data similarity index 100% rename from tests/data/req/test0/data.200 rename to tests/data/req/test0/data