4
4
from google import currency , images
5
5
from mock import Mock
6
6
import os
7
+ import vcr
8
+
9
+ BASE_DIR = os .path .dirname (__file__ )
7
10
8
11
9
12
def load_html_file (path ):
@@ -26,6 +29,11 @@ def test_decorated(self):
26
29
return test_decorator
27
30
28
31
32
+ # HELPERS
33
+ def get_dir_vcr (name ):
34
+ return os .path .join (BASE_DIR , "vcr_cassetes" , name )
35
+
36
+
29
37
class GoogleTest (unittest .TestCase ):
30
38
31
39
@load_html_file ("html_files" )
@@ -85,14 +93,11 @@ def test_convert_currency(self, html_f):
85
93
euros = google .convert_currency (5.0 , "USD" , "EUR" )
86
94
self .assertGreater (euros , 0.0 )
87
95
88
- @load_html_file ("html_files" )
89
- def test_standard_search (self , html_f ):
96
+ # @load_html_file("html_files")
97
+ @vcr .use_cassette ("test_standard_search.yaml" )
98
+ def test_standard_search (self ):
90
99
"""Test method to search in google."""
91
100
92
- # replace method to get html from a test html file
93
- google .standard_search .get_html = \
94
- Mock (return_value = html_f .read ().decode ('utf8' ))
95
-
96
101
search = google .search ("github" )
97
102
self .assertNotEqual (len (search ), 0 )
98
103
@@ -150,15 +155,17 @@ def test_get_images_req_url(self):
150
155
151
156
def test_repr (self ):
152
157
res = images .ImageResult ()
153
- assert repr (res ) == 'ImageResult(index=None, page=None, domain=None, link=None)'
158
+ assert repr (
159
+ res ) == 'ImageResult(index=None, page=None, domain=None, link=None)'
154
160
res .page = 1
155
161
res .index = 11
156
162
res .name = 'test'
157
163
res .thumb = 'test'
158
164
res .format = 'test'
159
165
res .domain = 'test'
160
166
res .link = 'http://aa.com'
161
- assert repr (res ) == 'ImageResult(index=11, page=1, domain=test, link=http://aa.com)'
167
+ assert repr (
168
+ res ) == 'ImageResult(index=11, page=1, domain=test, link=http://aa.com)'
162
169
163
170
def test_download (self ):
164
171
pass
0 commit comments