|
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | from __future__ import unicode_literals |
3 | | -import os |
| 3 | + |
4 | 4 | import io |
5 | | -import time |
6 | 5 | import json |
7 | | -import mock |
| 6 | +import os |
8 | 7 | import tempfile |
| 8 | +import time |
9 | 9 | from unittest import TestCase |
10 | 10 |
|
| 11 | +import mock |
11 | 12 | import pytest |
12 | 13 | import requests |
| 14 | +from tests import HTTPError, urlencode, urlopen |
13 | 15 |
|
14 | 16 | from mocket import Mocket, mocketize |
15 | 17 | from mocket.mockhttp import Entry, Response |
16 | | -from tests import urlopen, urlencode, HTTPError |
17 | | - |
18 | 18 |
|
19 | 19 | recording_directory = tempfile.mkdtemp() |
20 | 20 |
|
@@ -91,20 +91,6 @@ def test_truesendall_with_chunk_recording(self): |
91 | 91 |
|
92 | 92 | assert len(responses['httpbin.org']['80'].keys()) == 1 |
93 | 93 |
|
94 | | - @mocketize(truesocket_recording_dir=os.path.dirname(__file__)) |
95 | | - def test_truesendall_with_dump_from_recording(self): |
96 | | - requests.get('http://httpbin.org/ip', headers={"user-agent": "Fake-User-Agent"}) |
97 | | - requests.get('http://httpbin.org/gzip', headers={"user-agent": "Fake-User-Agent"}) |
98 | | - |
99 | | - dump_filename = os.path.join( |
100 | | - Mocket.get_truesocket_recording_dir(), |
101 | | - Mocket.get_namespace() + '.json', |
102 | | - ) |
103 | | - with io.open(dump_filename) as f: |
104 | | - responses = json.load(f) |
105 | | - |
106 | | - self.assertEqual(len(responses['httpbin.org']['80'].keys()), 2) |
107 | | - |
108 | 94 | @mocketize |
109 | 95 | def test_wrongpath_truesendall(self): |
110 | 96 | Entry.register(Entry.GET, 'http://httpbin.org/user.agent', Response(status=404)) |
@@ -291,6 +277,20 @@ def test_request_bodies(self): |
291 | 277 | last_request = Mocket.last_request() |
292 | 278 | assert last_request.body == request_body |
293 | 279 |
|
| 280 | + @mocketize(truesocket_recording_dir=os.path.dirname(__file__)) |
| 281 | + def test_truesendall_with_dump_from_recording(self): |
| 282 | + requests.get('http://httpbin.org/ip', headers={"user-agent": "Fake-User-Agent"}) |
| 283 | + requests.get('http://httpbin.org/gzip', headers={"user-agent": "Fake-User-Agent"}) |
| 284 | + |
| 285 | + dump_filename = os.path.join( |
| 286 | + Mocket.get_truesocket_recording_dir(), |
| 287 | + Mocket.get_namespace() + '.json', |
| 288 | + ) |
| 289 | + with io.open(dump_filename) as f: |
| 290 | + responses = json.load(f) |
| 291 | + |
| 292 | + self.assertEqual(len(responses['httpbin.org']['80'].keys()), 2) |
| 293 | + |
294 | 294 | # @mocketize |
295 | 295 | # def test_http_basic_auth(self): |
296 | 296 | # url = 'http://httpbin.org/hidden-basic-auth/hellouser/hellopassword' |
|
0 commit comments