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
efbcd60a
Kaydet (Commit)
efbcd60a
authored
Mar 25, 2018
tarafından
Paulo
Kaydeden (comit)
Tim Graham
Haz 21, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added test for contenttype redirect with m2m objects.
Thanks carltongibson for the test logic.
üst
b49ed4be
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
1 deletion
+40
-1
models.py
tests/contenttypes_tests/models.py
+8
-0
test_views.py
tests/contenttypes_tests/test_views.py
+32
-1
No files found.
tests/contenttypes_tests/models.py
Dosyayı görüntüle @
efbcd60a
...
...
@@ -128,3 +128,11 @@ class ModelWithNullFKToSite(models.Model):
def
get_absolute_url
(
self
):
return
'/title/
%
s/'
%
quote
(
self
.
title
)
class
ModelWithM2MToSite
(
models
.
Model
):
title
=
models
.
CharField
(
max_length
=
200
)
sites
=
models
.
ManyToManyField
(
Site
)
def
get_absolute_url
(
self
):
return
'/title/
%
s/'
%
quote
(
self
.
title
)
tests/contenttypes_tests/test_views.py
Dosyayı görüntüle @
efbcd60a
...
...
@@ -10,7 +10,8 @@ from django.test import TestCase, override_settings
from
.models
import
(
Article
,
Author
,
FooWithBrokenAbsoluteUrl
,
FooWithoutUrl
,
FooWithUrl
,
ModelWithNullFKToSite
,
SchemeIncludedURL
,
Site
as
MockSite
,
ModelWithM2MToSite
,
ModelWithNullFKToSite
,
SchemeIncludedURL
,
Site
as
MockSite
,
)
...
...
@@ -107,6 +108,36 @@ class ContentTypesViewsTests(TestCase):
response
=
self
.
client
.
get
(
url
)
self
.
assertRedirects
(
response
,
'
%
s'
%
obj
.
get_absolute_url
(),
fetch_redirect_response
=
False
)
@mock.patch
(
'django.apps.apps.get_model'
)
def
test_shortcut_view_with_site_m2m
(
self
,
get_model
):
"""
When the object has a ManyToManyField to Site, redirect to the
domain of the first site found in the m2m relationship.
"""
get_model
.
side_effect
=
lambda
*
args
,
**
kwargs
:
MockSite
if
args
[
0
]
==
'sites.Site'
else
ModelWithM2MToSite
# get_current_site() will lookup a Site object, so these must match the
# domains in the MockSite model.
Site
.
objects
.
bulk_create
([
Site
(
domain
=
'example2.com'
,
name
=
'example2.com'
),
Site
(
domain
=
'example3.com'
,
name
=
'example3.com'
),
])
MockSite
.
objects
.
bulk_create
([
MockSite
(
pk
=
1
,
domain
=
'example1.com'
),
MockSite
(
pk
=
2
,
domain
=
'example2.com'
),
MockSite
(
pk
=
3
,
domain
=
'example3.com'
),
])
ct
=
ContentType
.
objects
.
get_for_model
(
ModelWithM2MToSite
)
site_3_obj
=
ModelWithM2MToSite
.
objects
.
create
(
title
=
'Not Linked to Current Site'
)
site_3_obj
.
sites
.
add
(
MockSite
.
objects
.
get
(
pk
=
3
))
expected_url
=
'http://example3.com
%
s'
%
site_3_obj
.
get_absolute_url
()
with
self
.
settings
(
SITE_ID
=
2
):
# Redirects to the domain of the first Site found in the m2m
# relationship (ordering is arbitrary).
response
=
self
.
client
.
get
(
'/shortcut/
%
s/
%
s/'
%
(
ct
.
pk
,
site_3_obj
.
pk
))
self
.
assertRedirects
(
response
,
expected_url
,
fetch_redirect_response
=
False
)
class
ShortcutViewTests
(
TestCase
):
...
...
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