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
995ffbb2
Kaydet (Commit)
995ffbb2
authored
Agu 04, 2013
tarafından
Julien Phalip
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added some Selenium tests for the admin raw id widget.
üst
1593a864
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
104 additions
and
9 deletions
+104
-9
models.py
tests/admin_widgets/models.py
+2
-1
tests.py
tests/admin_widgets/tests.py
+101
-7
widgetadmin.py
tests/admin_widgets/widgetadmin.py
+1
-1
No files found.
tests/admin_widgets/models.py
Dosyayı görüntüle @
995ffbb2
...
...
@@ -56,7 +56,8 @@ class Inventory(models.Model):
return
self
.
name
class
Event
(
models
.
Model
):
band
=
models
.
ForeignKey
(
Band
,
limit_choices_to
=
models
.
Q
(
pk__gt
=
0
))
main_band
=
models
.
ForeignKey
(
Band
,
limit_choices_to
=
models
.
Q
(
pk__gt
=
0
),
related_name
=
'events_main_band_at'
)
supporting_bands
=
models
.
ManyToManyField
(
Band
,
null
=
True
,
blank
=
True
,
related_name
=
'events_supporting_band_at'
)
start_date
=
models
.
DateField
(
blank
=
True
,
null
=
True
)
start_time
=
models
.
TimeField
(
blank
=
True
,
null
=
True
)
description
=
models
.
TextField
(
blank
=
True
)
...
...
tests/admin_widgets/tests.py
Dosyayı görüntüle @
995ffbb2
...
...
@@ -90,15 +90,15 @@ class AdminFormfieldForDBFieldTests(TestCase):
self
.
assertFormfield
(
models
.
Album
,
'cover_art'
,
widgets
.
AdminFileWidget
)
def
testForeignKey
(
self
):
self
.
assertFormfield
(
models
.
Event
,
'band'
,
forms
.
Select
)
self
.
assertFormfield
(
models
.
Event
,
'
main_
band'
,
forms
.
Select
)
def
testRawIDForeignKey
(
self
):
self
.
assertFormfield
(
models
.
Event
,
'band'
,
widgets
.
ForeignKeyRawIdWidget
,
raw_id_fields
=
[
'band'
])
self
.
assertFormfield
(
models
.
Event
,
'
main_
band'
,
widgets
.
ForeignKeyRawIdWidget
,
raw_id_fields
=
[
'
main_
band'
])
def
testRadioFieldsForeignKey
(
self
):
ff
=
self
.
assertFormfield
(
models
.
Event
,
'band'
,
widgets
.
AdminRadioSelect
,
radio_fields
=
{
'band'
:
admin
.
VERTICAL
})
ff
=
self
.
assertFormfield
(
models
.
Event
,
'
main_
band'
,
widgets
.
AdminRadioSelect
,
radio_fields
=
{
'
main_
band'
:
admin
.
VERTICAL
})
self
.
assertEqual
(
ff
.
empty_label
,
None
)
def
testManyToMany
(
self
):
...
...
@@ -201,7 +201,7 @@ class AdminForeignKeyRawIdWidget(DjangoTestCase):
pk
=
band
.
pk
band
.
delete
()
post_data
=
{
"band"
:
'
%
s'
%
pk
,
"
main_
band"
:
'
%
s'
%
pk
,
}
# Try posting with a non-existent pk in a raw id field: this
# should result in an error message, not a server exception.
...
...
@@ -215,7 +215,7 @@ class AdminForeignKeyRawIdWidget(DjangoTestCase):
for
test_str
in
(
'Iñtërnâtiônàlizætiøn'
,
"1234'"
,
-
1234
):
# This should result in an error message, not a server exception.
response
=
self
.
client
.
post
(
'
%
s/admin_widgets/event/add/'
%
self
.
admin_root
,
{
"band"
:
test_str
})
{
"
main_
band"
:
test_str
})
self
.
assertContains
(
response
,
'Select a valid choice. That choice is not one of the available choices.'
)
...
...
@@ -819,3 +819,96 @@ class HorizontalVerticalFilterSeleniumChromeTests(HorizontalVerticalFilterSeleni
class
HorizontalVerticalFilterSeleniumIETests
(
HorizontalVerticalFilterSeleniumFirefoxTests
):
webdriver_class
=
'selenium.webdriver.ie.webdriver.WebDriver'
@override_settings
(
PASSWORD_HASHERS
=
(
'django.contrib.auth.hashers.SHA1PasswordHasher'
,))
class
AdminRawIdWidgetSeleniumFirefoxTests
(
AdminSeleniumWebDriverTestCase
):
available_apps
=
[
'admin_widgets'
]
+
AdminSeleniumWebDriverTestCase
.
available_apps
fixtures
=
[
'admin-widgets-users.xml'
]
urls
=
"admin_widgets.urls"
webdriver_class
=
'selenium.webdriver.firefox.webdriver.WebDriver'
def
setUp
(
self
):
models
.
Band
.
objects
.
create
(
id
=
42
,
name
=
'Bogey Blues'
)
models
.
Band
.
objects
.
create
(
id
=
98
,
name
=
'Green Potatoes'
)
super
(
AdminRawIdWidgetSeleniumFirefoxTests
,
self
)
.
setUp
()
def
test_foreignkey
(
self
):
self
.
admin_login
(
username
=
'super'
,
password
=
'secret'
,
login_url
=
'/'
)
self
.
selenium
.
get
(
'
%
s
%
s'
%
(
self
.
live_server_url
,
'/admin_widgets/event/add/'
))
main_window
=
self
.
selenium
.
current_window_handle
# No value has been selected yet
self
.
assertEqual
(
self
.
selenium
.
find_element_by_id
(
'id_main_band'
)
.
get_attribute
(
'value'
),
''
)
# Open the popup window and click on a band
self
.
selenium
.
find_element_by_id
(
'lookup_id_main_band'
)
.
click
()
self
.
selenium
.
switch_to_window
(
'id_main_band'
)
link
=
self
.
selenium
.
find_element_by_link_text
(
'Bogey Blues'
)
self
.
assertTrue
(
'/band/42/'
in
link
.
get_attribute
(
'href'
))
link
.
click
()
# The field now contains the selected band's id
self
.
selenium
.
switch_to_window
(
main_window
)
self
.
assertEqual
(
self
.
selenium
.
find_element_by_id
(
'id_main_band'
)
.
get_attribute
(
'value'
),
'42'
)
# Reopen the popup window and click on another band
self
.
selenium
.
find_element_by_id
(
'lookup_id_main_band'
)
.
click
()
self
.
selenium
.
switch_to_window
(
'id_main_band'
)
link
=
self
.
selenium
.
find_element_by_link_text
(
'Green Potatoes'
)
self
.
assertTrue
(
'/band/98/'
in
link
.
get_attribute
(
'href'
))
link
.
click
()
# The field now contains the other selected band's id
self
.
selenium
.
switch_to_window
(
main_window
)
self
.
assertEqual
(
self
.
selenium
.
find_element_by_id
(
'id_main_band'
)
.
get_attribute
(
'value'
),
'98'
)
def
test_many_to_many
(
self
):
self
.
admin_login
(
username
=
'super'
,
password
=
'secret'
,
login_url
=
'/'
)
self
.
selenium
.
get
(
'
%
s
%
s'
%
(
self
.
live_server_url
,
'/admin_widgets/event/add/'
))
main_window
=
self
.
selenium
.
current_window_handle
# No value has been selected yet
self
.
assertEqual
(
self
.
selenium
.
find_element_by_id
(
'id_supporting_bands'
)
.
get_attribute
(
'value'
),
''
)
# Open the popup window and click on a band
self
.
selenium
.
find_element_by_id
(
'lookup_id_supporting_bands'
)
.
click
()
self
.
selenium
.
switch_to_window
(
'id_supporting_bands'
)
link
=
self
.
selenium
.
find_element_by_link_text
(
'Bogey Blues'
)
self
.
assertTrue
(
'/band/42/'
in
link
.
get_attribute
(
'href'
))
link
.
click
()
# The field now contains the selected band's id
self
.
selenium
.
switch_to_window
(
main_window
)
self
.
assertEqual
(
self
.
selenium
.
find_element_by_id
(
'id_supporting_bands'
)
.
get_attribute
(
'value'
),
'42'
)
# Reopen the popup window and click on another band
self
.
selenium
.
find_element_by_id
(
'lookup_id_supporting_bands'
)
.
click
()
self
.
selenium
.
switch_to_window
(
'id_supporting_bands'
)
link
=
self
.
selenium
.
find_element_by_link_text
(
'Green Potatoes'
)
self
.
assertTrue
(
'/band/98/'
in
link
.
get_attribute
(
'href'
))
link
.
click
()
# The field now contains the two selected bands' ids
self
.
selenium
.
switch_to_window
(
main_window
)
self
.
assertEqual
(
self
.
selenium
.
find_element_by_id
(
'id_supporting_bands'
)
.
get_attribute
(
'value'
),
'42,98'
)
class
AdminRawIdWidgetSeleniumChromeTests
(
AdminRawIdWidgetSeleniumFirefoxTests
):
webdriver_class
=
'selenium.webdriver.chrome.webdriver.WebDriver'
class
AdminRawIdWidgetSeleniumIETests
(
AdminRawIdWidgetSeleniumFirefoxTests
):
webdriver_class
=
'selenium.webdriver.ie.webdriver.WebDriver'
\ No newline at end of file
tests/admin_widgets/widgetadmin.py
Dosyayı görüntüle @
995ffbb2
...
...
@@ -18,7 +18,7 @@ class CarTireAdmin(admin.ModelAdmin):
return
super
(
CarTireAdmin
,
self
)
.
formfield_for_foreignkey
(
db_field
,
request
,
**
kwargs
)
class
EventAdmin
(
admin
.
ModelAdmin
):
raw_id_fields
=
[
'
band
'
]
raw_id_fields
=
[
'
main_band'
,
'supporting_bands
'
]
class
SchoolAdmin
(
admin
.
ModelAdmin
):
...
...
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