Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
10d49b96
Kaydet (Commit)
10d49b96
authored
Kas 22, 2016
tarafından
Adam Chainz
Kaydeden (comit)
Tim Graham
Kas 22, 2016
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added tests for contrib.sitemaps.ping_google().
üst
b1a90415
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
76 additions
and
5 deletions
+76
-5
__init__.py
django/contrib/sitemaps/__init__.py
+10
-5
test_management.py
tests/sitemaps_tests/test_management.py
+16
-0
test_utils.py
tests/sitemaps_tests/test_utils.py
+40
-0
empty.py
tests/sitemaps_tests/urls/empty.py
+1
-0
index_only.py
tests/sitemaps_tests/urls/index_only.py
+9
-0
No files found.
django/contrib/sitemaps/__init__.py
Dosyayı görüntüle @
10d49b96
...
...
@@ -21,6 +21,15 @@ def ping_google(sitemap_url=None, ping_url=PING_URL):
for this site -- e.g., '/sitemap.xml'. If sitemap_url is not provided, this
function will attempt to deduce it by using urls.reverse().
"""
sitemap_full_url
=
_get_sitemap_full_url
(
sitemap_url
)
params
=
urlencode
({
'sitemap'
:
sitemap_full_url
})
urlopen
(
'
%
s?
%
s'
%
(
ping_url
,
params
))
def
_get_sitemap_full_url
(
sitemap_url
):
if
not
django_apps
.
is_installed
(
'django.contrib.sites'
):
raise
ImproperlyConfigured
(
"ping_google requires django.contrib.sites, which isn't installed."
)
if
sitemap_url
is
None
:
try
:
# First, try to get the "index" sitemap URL.
...
...
@@ -35,13 +44,9 @@ def ping_google(sitemap_url=None, ping_url=PING_URL):
if
sitemap_url
is
None
:
raise
SitemapNotFound
(
"You didn't provide a sitemap_url, and the sitemap URL couldn't be auto-detected."
)
if
not
django_apps
.
is_installed
(
'django.contrib.sites'
):
raise
ImproperlyConfigured
(
"ping_google requires django.contrib.sites, which isn't installed."
)
Site
=
django_apps
.
get_model
(
'sites.Site'
)
current_site
=
Site
.
objects
.
get_current
()
url
=
"http://
%
s
%
s"
%
(
current_site
.
domain
,
sitemap_url
)
params
=
urlencode
({
'sitemap'
:
url
})
urlopen
(
"
%
s?
%
s"
%
(
ping_url
,
params
))
return
'http://
%
s
%
s'
%
(
current_site
.
domain
,
sitemap_url
)
class
Sitemap
(
object
):
...
...
tests/sitemaps_tests/test_management.py
0 → 100644
Dosyayı görüntüle @
10d49b96
from
django.core.management
import
call_command
from
django.test
import
mock
from
.base
import
SitemapTestsBase
@mock.patch
(
'django.contrib.sitemaps.management.commands.ping_google.ping_google'
)
class
PingGoogleTests
(
SitemapTestsBase
):
def
test_default
(
self
,
ping_google_func
):
call_command
(
'ping_google'
)
ping_google_func
.
assert_called_with
(
sitemap_url
=
None
)
def
test_arg
(
self
,
ping_google_func
):
call_command
(
'ping_google'
,
'foo.xml'
)
ping_google_func
.
assert_called_with
(
sitemap_url
=
'foo.xml'
)
tests/sitemaps_tests/test_utils.py
0 → 100644
Dosyayı görüntüle @
10d49b96
from
django.contrib.sitemaps
import
(
SitemapNotFound
,
_get_sitemap_full_url
,
ping_google
,
)
from
django.core.exceptions
import
ImproperlyConfigured
from
django.test
import
mock
,
modify_settings
,
override_settings
from
django.utils.six.moves.urllib.parse
import
urlencode
from
.base
import
SitemapTestsBase
class
PingGoogleTests
(
SitemapTestsBase
):
@mock.patch
(
'django.contrib.sitemaps.urlopen'
)
def
test_something
(
self
,
urlopen
):
ping_google
()
params
=
urlencode
({
'sitemap'
:
'http://example.com/sitemap-without-entries/sitemap.xml'
})
full_url
=
'https://www.google.com/webmasters/tools/ping?
%
s'
%
params
urlopen
.
assert_called_with
(
full_url
)
def
test_get_sitemap_full_url_global
(
self
):
self
.
assertEqual
(
_get_sitemap_full_url
(
None
),
'http://example.com/sitemap-without-entries/sitemap.xml'
)
@override_settings
(
ROOT_URLCONF
=
'sitemaps_tests.urls.index_only'
)
def
test_get_sitemap_full_url_index
(
self
):
self
.
assertEqual
(
_get_sitemap_full_url
(
None
),
'http://example.com/simple/index.xml'
)
@override_settings
(
ROOT_URLCONF
=
'sitemaps_tests.urls.empty'
)
def
test_get_sitemap_full_url_not_detected
(
self
):
msg
=
"You didn't provide a sitemap_url, and the sitemap URL couldn't be auto-detected."
with
self
.
assertRaisesMessage
(
SitemapNotFound
,
msg
):
_get_sitemap_full_url
(
None
)
def
test_get_sitemap_full_url_exact_url
(
self
):
self
.
assertEqual
(
_get_sitemap_full_url
(
'/foo.xml'
),
'http://example.com/foo.xml'
)
@modify_settings
(
INSTALLED_APPS
=
{
'remove'
:
'django.contrib.sites'
})
def
test_get_sitemap_full_url_no_sites
(
self
):
msg
=
"ping_google requires django.contrib.sites, which isn't installed."
with
self
.
assertRaisesMessage
(
ImproperlyConfigured
,
msg
):
_get_sitemap_full_url
(
None
)
tests/sitemaps_tests/urls/empty.py
0 → 100644
Dosyayı görüntüle @
10d49b96
urlpatterns
=
[]
tests/sitemaps_tests/urls/index_only.py
0 → 100644
Dosyayı görüntüle @
10d49b96
from
django.conf.urls
import
url
from
django.contrib.sitemaps
import
views
from
.http
import
simple_sitemaps
urlpatterns
=
[
url
(
r'^simple/index\.xml$'
,
views
.
index
,
{
'sitemaps'
:
simple_sitemaps
},
name
=
'django.contrib.sitemaps.views.index'
),
]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment