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
0eefda49
Kaydet (Commit)
0eefda49
authored
Mar 17, 2017
tarafından
Anton Samarchyan
Kaydeden (comit)
Tim Graham
Tem 26, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Improved test coverage for django.contrib.sitemaps.
üst
5bb9b9a3
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
72 additions
and
3 deletions
+72
-3
models.py
tests/sitemaps_tests/models.py
+1
-0
test_generic.py
tests/sitemaps_tests/test_generic.py
+12
-0
test_http.py
tests/sitemaps_tests/test_http.py
+35
-0
http.py
tests/sitemaps_tests/urls/http.py
+24
-3
No files found.
tests/sitemaps_tests/models.py
Dosyayı görüntüle @
0eefda49
...
...
@@ -4,6 +4,7 @@ from django.urls import reverse
class
TestModel
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
100
)
lastmod
=
models
.
DateTimeField
(
null
=
True
)
def
get_absolute_url
(
self
):
return
'/testmodel/
%
s/'
%
self
.
id
...
...
tests/sitemaps_tests/test_generic.py
Dosyayı görüntüle @
0eefda49
...
...
@@ -45,3 +45,15 @@ class GenericViewsSitemapTests(SitemapTestsBase):
</urlset>
"""
%
expected
self
.
assertXMLEqual
(
response
.
content
.
decode
(),
expected_content
)
def
test_generic_sitemap_lastmod
(
self
):
test_model
=
TestModel
.
objects
.
first
()
TestModel
.
objects
.
update
(
lastmod
=
datetime
(
2013
,
3
,
13
,
10
,
0
,
0
))
response
=
self
.
client
.
get
(
'/generic-lastmod/sitemap.xml'
)
expected_content
=
"""<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url><loc>
%
s/testmodel/
%
s/</loc><lastmod>2013-03-13</lastmod></url>
</urlset>
"""
%
(
self
.
base_url
,
test_model
.
pk
)
self
.
assertXMLEqual
(
response
.
content
.
decode
(),
expected_content
)
self
.
assertEqual
(
response
[
'Last-Modified'
],
'Wed, 13 Mar 2013 10:00:00 GMT'
)
tests/sitemaps_tests/test_http.py
Dosyayı görüntüle @
0eefda49
...
...
@@ -27,6 +27,26 @@ class HTTPSitemapTests(SitemapTestsBase):
"""
%
self
.
base_url
self
.
assertXMLEqual
(
response
.
content
.
decode
(),
expected_content
)
def
test_sitemap_not_callable
(
self
):
"""A sitemap may not be callable."""
response
=
self
.
client
.
get
(
'/simple-not-callable/index.xml'
)
expected_content
=
"""<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap><loc>
%
s/simple/sitemap-simple.xml</loc></sitemap>
</sitemapindex>
"""
%
self
.
base_url
self
.
assertXMLEqual
(
response
.
content
.
decode
(),
expected_content
)
def
test_paged_sitemap
(
self
):
"""A sitemap may have multiple pages."""
response
=
self
.
client
.
get
(
'/simple-paged/index.xml'
)
expected_content
=
"""<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap><loc>{0}/simple/sitemap-simple.xml</loc></sitemap><sitemap><loc>{0}/simple/sitemap-simple.xml?p=2</loc></sitemap>
</sitemapindex>
"""
.
format
(
self
.
base_url
)
self
.
assertXMLEqual
(
response
.
content
.
decode
(),
expected_content
)
@override_settings
(
TEMPLATES
=
[{
'BACKEND'
:
'django.template.backends.django.DjangoTemplates'
,
'DIRS'
:
[
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'templates'
)],
...
...
@@ -52,6 +72,21 @@ class HTTPSitemapTests(SitemapTestsBase):
"""
%
(
self
.
base_url
,
date
.
today
())
self
.
assertXMLEqual
(
response
.
content
.
decode
(),
expected_content
)
def
test_no_section
(
self
):
response
=
self
.
client
.
get
(
'/simple/sitemap-simple2.xml'
)
self
.
assertEqual
(
str
(
response
.
context
[
'exception'
]),
"No sitemap available for section: 'simple2'"
)
self
.
assertEqual
(
response
.
status_code
,
404
)
def
test_empty_page
(
self
):
response
=
self
.
client
.
get
(
'/simple/sitemap-simple.xml?p=0'
)
self
.
assertEqual
(
str
(
response
.
context
[
'exception'
]),
'Page 0 empty'
)
self
.
assertEqual
(
response
.
status_code
,
404
)
def
test_page_not_int
(
self
):
response
=
self
.
client
.
get
(
'/simple/sitemap-simple.xml?p=test'
)
self
.
assertEqual
(
str
(
response
.
context
[
'exception'
]),
"No page 'test'"
)
self
.
assertEqual
(
response
.
status_code
,
404
)
def
test_simple_sitemap
(
self
):
"A simple sitemap can be rendered"
response
=
self
.
client
.
get
(
'/simple/sitemap.xml'
)
...
...
tests/sitemaps_tests/urls/http.py
Dosyayı görüntüle @
0eefda49
...
...
@@ -21,6 +21,11 @@ class SimpleSitemap(Sitemap):
return
[
object
()]
class
SimplePagedSitemap
(
Sitemap
):
def
items
(
self
):
return
[
object
()
for
x
in
range
(
Sitemap
.
limit
+
1
)]
class
SimpleI18nSitemap
(
Sitemap
):
changefreq
=
"never"
priority
=
0.5
...
...
@@ -35,9 +40,6 @@ class EmptySitemap(Sitemap):
priority
=
0.5
location
=
'/location/'
def
items
(
self
):
return
[]
class
FixedLastmodSitemap
(
SimpleSitemap
):
lastmod
=
datetime
(
2013
,
3
,
13
,
10
,
0
,
0
)
...
...
@@ -80,6 +82,14 @@ simple_i18nsitemaps = {
'simple'
:
SimpleI18nSitemap
,
}
simple_sitemaps_not_callable
=
{
'simple'
:
SimpleSitemap
(),
}
simple_sitemaps_paged
=
{
'simple'
:
SimplePagedSitemap
,
}
empty_sitemaps
=
{
'empty'
:
EmptySitemap
,
}
...
...
@@ -118,9 +128,17 @@ generic_sitemaps = {
'generic'
:
GenericSitemap
({
'queryset'
:
TestModel
.
objects
.
order_by
(
'pk'
)
.
all
()}),
}
generic_sitemaps_lastmod
=
{
'generic'
:
GenericSitemap
({
'queryset'
:
TestModel
.
objects
.
order_by
(
'pk'
)
.
all
(),
'date_field'
:
'lastmod'
,
}),
}
urlpatterns
=
[
url
(
r'^simple/index\.xml$'
,
views
.
index
,
{
'sitemaps'
:
simple_sitemaps
}),
url
(
r'^simple-paged/index\.xml$'
,
views
.
index
,
{
'sitemaps'
:
simple_sitemaps_paged
}),
url
(
r'^simple-not-callable/index\.xml$'
,
views
.
index
,
{
'sitemaps'
:
simple_sitemaps_not_callable
}),
url
(
r'^simple/custom-index\.xml$'
,
views
.
index
,
{
'sitemaps'
:
simple_sitemaps
,
'template_name'
:
'custom_sitemap_index.xml'
}),
url
(
r'^simple/sitemap-(?P<section>.+)\.xml$'
,
views
.
sitemap
,
...
...
@@ -165,6 +183,9 @@ urlpatterns = [
url
(
r'^generic/sitemap\.xml$'
,
views
.
sitemap
,
{
'sitemaps'
:
generic_sitemaps
},
name
=
'django.contrib.sitemaps.views.sitemap'
),
url
(
r'^generic-lastmod/sitemap\.xml$'
,
views
.
sitemap
,
{
'sitemaps'
:
generic_sitemaps_lastmod
},
name
=
'django.contrib.sitemaps.views.sitemap'
),
url
(
r'^cached/index\.xml$'
,
cache_page
(
1
)(
views
.
index
),
{
'sitemaps'
:
simple_sitemaps
,
'sitemap_url_name'
:
'cached_sitemap'
}),
url
(
r'^cached/sitemap-(?P<section>.+)\.xml'
,
cache_page
(
1
)(
views
.
sitemap
),
...
...
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