File tree Expand file tree Collapse file tree 2 files changed +14
-8
lines changed
python_advanced_search/models/query Expand file tree Collapse file tree 2 files changed +14
-8
lines changed Original file line number Diff line number Diff line change 27
27
RelatedCommand ,
28
28
DefineCommand ,
29
29
)
30
+ from python_advanced_search .models .location import Location
30
31
from python_advanced_search .services .crawler import GoogleRequest , BingRequest
31
32
32
33
@@ -125,11 +126,11 @@ def exclude(self, **_operators):
125
126
self ._add_commands (exclude = True , ** _operators )
126
127
return self
127
128
128
- def to (self , cls ):
129
- return cls (self )
129
+ def to (self , cls , location = Location . WORLDWIDE ):
130
+ return cls (self , tld = location )
130
131
131
- def to_google (self ):
132
- return self .to (GoogleRequest )
132
+ def to_google (self , location = Location . WORLDWIDE ):
133
+ return self .to (GoogleRequest , location )
133
134
134
- def to_bing (self ):
135
- return self .to (BingRequest )
135
+ def to_bing (self , location = Location . WORLDWIDE ):
136
+ return self .to (BingRequest , location )
Original file line number Diff line number Diff line change 1
1
import unittest
2
2
from unittest .mock import Mock , patch
3
3
4
+ from python_advanced_search .models .location import Location
4
5
from python_advanced_search .services .crawler import GoogleRequest
5
6
from python_advanced_search .models .query import Query
6
7
@@ -21,10 +22,14 @@ def test_request(self):
21
22
with patch ('python_advanced_search.services.crawler.sync_playwright' , return_value = mock_playwright ):
22
23
request = Query ().include (
23
24
expression = 'python unittest'
24
- ).to (GoogleRequest )
25
+ ).to (GoogleRequest , Location . FRANCE )
25
26
26
- response = request .get ()
27
+ self .assertEqual (
28
+ request .url ,
29
+ 'https://google.fr/search?q=python+unittest'
30
+ )
27
31
32
+ response = request .get ()
28
33
self .assertEqual (
29
34
response .html ,
30
35
'<html></html>'
You can’t perform that action at this time.
0 commit comments