|
3 | 3 | import base64
|
4 | 4 | import sys
|
5 | 5 | import unittest
|
| 6 | +from contextlib import contextmanager |
6 | 7 |
|
7 | 8 | import pytest
|
8 | 9 |
|
@@ -55,14 +56,19 @@ def handle_get(request):
|
55 | 56 |
|
56 | 57 | cls.httpserver.expect_request("/" + read_file).respond_with_handler(handle_get)
|
57 | 58 |
|
58 |
| - def assert_http_get_request_data(self, url, read_file, error_handler): |
| 59 | + @contextmanager |
| 60 | + def http_get_request_data(self, url, read_file, error_handler): |
59 | 61 | """Serve a GET request, assert that the accessor returns the content of the GET Request"""
|
60 | 62 | self.serve_a_get_request(self.document_root, read_file, error_handler)
|
61 | 63 |
|
62 | 64 | httpaccessor = createAccessor(url, True)
|
63 | 65 | self.assertEqual(type(httpaccessor), HTTPAccessor)
|
64 | 66 |
|
65 | 67 | with open(self.document_root + read_file, "rb") as ref:
|
| 68 | + yield httpaccessor, ref |
| 69 | + |
| 70 | + def assert_http_get_request_data(self, url, read_file, error_handler): |
| 71 | + with self.http_get_request_data(url, read_file, error_handler) as (httpaccessor, ref): |
66 | 72 | http_accessor_filehandle = httpaccessor.openAddress(read_file)
|
67 | 73 | if sys.version_info >= (3, 0):
|
68 | 74 | assert isinstance(http_accessor_filehandle, HTTPResponse)
|
|
0 commit comments