Skip to content

Commit 8fd0c1f

Browse files
committed
add tld i18n
1 parent 367c382 commit 8fd0c1f

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

python_advanced_search/models/query/__init__.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
RelatedCommand,
2828
DefineCommand,
2929
)
30+
from python_advanced_search.models.location import Location
3031
from python_advanced_search.services.crawler import GoogleRequest, BingRequest
3132

3233

@@ -125,11 +126,11 @@ def exclude(self, **_operators):
125126
self._add_commands(exclude=True, **_operators)
126127
return self
127128

128-
def to(self, cls):
129-
return cls(self)
129+
def to(self, cls, location=Location.WORLDWIDE):
130+
return cls(self, tld=location)
130131

131-
def to_google(self):
132-
return self.to(GoogleRequest)
132+
def to_google(self, location=Location.WORLDWIDE):
133+
return self.to(GoogleRequest, location)
133134

134-
def to_bing(self):
135-
return self.to(BingRequest)
135+
def to_bing(self, location=Location.WORLDWIDE):
136+
return self.to(BingRequest, location)

tests/services/crawler/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import unittest
22
from unittest.mock import Mock, patch
33

4+
from python_advanced_search.models.location import Location
45
from python_advanced_search.services.crawler import GoogleRequest
56
from python_advanced_search.models.query import Query
67

@@ -21,10 +22,14 @@ def test_request(self):
2122
with patch('python_advanced_search.services.crawler.sync_playwright', return_value=mock_playwright):
2223
request = Query().include(
2324
expression='python unittest'
24-
).to(GoogleRequest)
25+
).to(GoogleRequest, Location.FRANCE)
2526

26-
response = request.get()
27+
self.assertEqual(
28+
request.url,
29+
'https://google.fr/search?q=python+unittest'
30+
)
2731

32+
response = request.get()
2833
self.assertEqual(
2934
response.html,
3035
'<html></html>'

0 commit comments

Comments
 (0)