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
d42a45de
Kaydet (Commit)
d42a45de
authored
Eyl 22, 2014
tarafından
Loic Bistuer
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Merged custom_columns_regress into the custom_columns test package.
üst
7fe554b2
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
66 additions
and
130 deletions
+66
-130
models.py
tests/custom_columns/models.py
+3
-0
tests.py
tests/custom_columns/tests.py
+63
-10
__init__.py
tests/custom_columns_regress/__init__.py
+0
-0
models.py
tests/custom_columns_regress/models.py
+0
-39
tests.py
tests/custom_columns_regress/tests.py
+0
-81
No files found.
tests/custom_columns/models.py
Dosyayı görüntüle @
d42a45de
...
...
@@ -23,6 +23,7 @@ from django.utils.encoding import python_2_unicode_compatible
@python_2_unicode_compatible
class
Author
(
models
.
Model
):
Author_ID
=
models
.
AutoField
(
primary_key
=
True
,
db_column
=
'Author ID'
)
first_name
=
models
.
CharField
(
max_length
=
30
,
db_column
=
'firstname'
)
last_name
=
models
.
CharField
(
max_length
=
30
,
db_column
=
'last'
)
...
...
@@ -36,8 +37,10 @@ class Author(models.Model):
@python_2_unicode_compatible
class
Article
(
models
.
Model
):
Article_ID
=
models
.
AutoField
(
primary_key
=
True
,
db_column
=
'Article ID'
)
headline
=
models
.
CharField
(
max_length
=
100
)
authors
=
models
.
ManyToManyField
(
Author
,
db_table
=
'my_m2m_table'
)
primary_author
=
models
.
ForeignKey
(
Author
,
db_column
=
'Author ID'
,
related_name
=
'primary_set'
,
null
=
True
)
def
__str__
(
self
):
return
self
.
headline
...
...
tests/custom_columns/tests.py
Dosyayı görüntüle @
d42a45de
...
...
@@ -8,15 +8,14 @@ from .models import Author, Article
class
CustomColumnsTests
(
TestCase
):
def
setUp
(
self
):
a1
=
Author
.
objects
.
create
(
first_name
=
"John"
,
last_name
=
"Smith"
)
a2
=
Author
.
objects
.
create
(
first_name
=
"Peter"
,
last_name
=
"Jones"
)
art
=
Article
.
objects
.
create
(
headline
=
"Django lets you build Web apps easily"
)
art
.
authors
=
[
a1
,
a2
]
def
setUp
(
self
):
self
.
a1
=
Author
.
objects
.
create
(
first_name
=
"John"
,
last_name
=
"Smith"
)
self
.
a2
=
Author
.
objects
.
create
(
first_name
=
"Peter"
,
last_name
=
"Jones"
)
self
.
authors
=
[
self
.
a1
,
self
.
a2
]
self
.
a
1
=
a1
self
.
art
=
art
self
.
a
rticle
=
Article
.
objects
.
create
(
headline
=
"Django lets you build Web apps easily"
,
primary_author
=
self
.
a1
)
self
.
art
icle
.
authors
=
self
.
authors
def
test_query_all_available_authors
(
self
):
self
.
assertQuerysetEqual
(
...
...
@@ -38,7 +37,6 @@ class CustomColumnsTests(TestCase):
"John Smith"
,
],
six
.
text_type
)
def
test_field_error
(
self
):
...
...
@@ -56,7 +54,7 @@ class CustomColumnsTests(TestCase):
def
test_get_all_authors_for_an_article
(
self
):
self
.
assertQuerysetEqual
(
self
.
art
.
authors
.
all
(),
[
self
.
art
icle
.
authors
.
all
(),
[
"Peter Jones"
,
"John Smith"
,
],
...
...
@@ -73,8 +71,63 @@ class CustomColumnsTests(TestCase):
def
test_get_author_m2m_relation
(
self
):
self
.
assertQuerysetEqual
(
self
.
art
.
authors
.
filter
(
last_name
=
'Jones'
),
[
self
.
art
icle
.
authors
.
filter
(
last_name
=
'Jones'
),
[
"Peter Jones"
],
six
.
text_type
)
def
test_author_querying
(
self
):
self
.
assertQuerysetEqual
(
Author
.
objects
.
all
()
.
order_by
(
'last_name'
),
[
'<Author: Peter Jones>'
,
'<Author: John Smith>'
]
)
def
test_author_filtering
(
self
):
self
.
assertQuerysetEqual
(
Author
.
objects
.
filter
(
first_name__exact
=
'John'
),
[
'<Author: John Smith>'
]
)
def
test_author_get
(
self
):
self
.
assertEqual
(
self
.
a1
,
Author
.
objects
.
get
(
first_name__exact
=
'John'
))
def
test_filter_on_nonexistant_field
(
self
):
self
.
assertRaisesMessage
(
FieldError
,
"Cannot resolve keyword 'firstname' into field. Choices are: Author_ID, article, first_name, last_name, primary_set"
,
Author
.
objects
.
filter
,
firstname__exact
=
'John'
)
def
test_author_get_attributes
(
self
):
a
=
Author
.
objects
.
get
(
last_name__exact
=
'Smith'
)
self
.
assertEqual
(
'John'
,
a
.
first_name
)
self
.
assertEqual
(
'Smith'
,
a
.
last_name
)
self
.
assertRaisesMessage
(
AttributeError
,
"'Author' object has no attribute 'firstname'"
,
getattr
,
a
,
'firstname'
)
self
.
assertRaisesMessage
(
AttributeError
,
"'Author' object has no attribute 'last'"
,
getattr
,
a
,
'last'
)
def
test_m2m_table
(
self
):
self
.
assertQuerysetEqual
(
self
.
article
.
authors
.
all
()
.
order_by
(
'last_name'
),
[
'<Author: Peter Jones>'
,
'<Author: John Smith>'
]
)
self
.
assertQuerysetEqual
(
self
.
a1
.
article_set
.
all
(),
[
'<Article: Django lets you build Web apps easily>'
]
)
self
.
assertQuerysetEqual
(
self
.
article
.
authors
.
filter
(
last_name
=
'Jones'
),
[
'<Author: Peter Jones>'
]
)
tests/custom_columns_regress/__init__.py
deleted
100644 → 0
Dosyayı görüntüle @
7fe554b2
tests/custom_columns_regress/models.py
deleted
100644 → 0
Dosyayı görüntüle @
7fe554b2
"""
Regression for #9736.
Checks some pathological column naming to make sure it doesn't break
table creation or queries.
"""
from
__future__
import
unicode_literals
from
django.db
import
models
from
django.utils.encoding
import
python_2_unicode_compatible
@python_2_unicode_compatible
class
Article
(
models
.
Model
):
Article_ID
=
models
.
AutoField
(
primary_key
=
True
,
db_column
=
'Article ID'
)
headline
=
models
.
CharField
(
max_length
=
100
)
authors
=
models
.
ManyToManyField
(
'Author'
,
db_table
=
'my m2m table'
)
primary_author
=
models
.
ForeignKey
(
'Author'
,
db_column
=
'Author ID'
,
related_name
=
'primary_set'
)
def
__str__
(
self
):
return
self
.
headline
class
Meta
:
ordering
=
(
'headline'
,)
@python_2_unicode_compatible
class
Author
(
models
.
Model
):
Author_ID
=
models
.
AutoField
(
primary_key
=
True
,
db_column
=
'Author ID'
)
first_name
=
models
.
CharField
(
max_length
=
30
,
db_column
=
'first name'
)
last_name
=
models
.
CharField
(
max_length
=
30
,
db_column
=
'last name'
)
def
__str__
(
self
):
return
'
%
s
%
s'
%
(
self
.
first_name
,
self
.
last_name
)
class
Meta
:
db_table
=
'my author table'
ordering
=
(
'last_name'
,
'first_name'
)
tests/custom_columns_regress/tests.py
deleted
100644 → 0
Dosyayı görüntüle @
7fe554b2
from
__future__
import
unicode_literals
from
django.core.exceptions
import
FieldError
from
django.test
import
TestCase
from
.models
import
Author
,
Article
def
pks
(
objects
):
""" Return pks to be able to compare lists"""
return
[
o
.
pk
for
o
in
objects
]
class
CustomColumnRegression
(
TestCase
):
def
setUp
(
self
):
self
.
a1
=
Author
.
objects
.
create
(
first_name
=
'John'
,
last_name
=
'Smith'
)
self
.
a2
=
Author
.
objects
.
create
(
first_name
=
'Peter'
,
last_name
=
'Jones'
)
self
.
authors
=
[
self
.
a1
,
self
.
a2
]
def
test_basic_creation
(
self
):
art
=
Article
(
headline
=
'Django lets you build Web apps easily'
,
primary_author
=
self
.
a1
)
art
.
save
()
art
.
authors
=
[
self
.
a1
,
self
.
a2
]
def
test_author_querying
(
self
):
self
.
assertQuerysetEqual
(
Author
.
objects
.
all
()
.
order_by
(
'last_name'
),
[
'<Author: Peter Jones>'
,
'<Author: John Smith>'
]
)
def
test_author_filtering
(
self
):
self
.
assertQuerysetEqual
(
Author
.
objects
.
filter
(
first_name__exact
=
'John'
),
[
'<Author: John Smith>'
]
)
def
test_author_get
(
self
):
self
.
assertEqual
(
self
.
a1
,
Author
.
objects
.
get
(
first_name__exact
=
'John'
))
def
test_filter_on_nonexistant_field
(
self
):
self
.
assertRaisesMessage
(
FieldError
,
"Cannot resolve keyword 'firstname' into field. Choices are: Author_ID, article, first_name, last_name, primary_set"
,
Author
.
objects
.
filter
,
firstname__exact
=
'John'
)
def
test_author_get_attributes
(
self
):
a
=
Author
.
objects
.
get
(
last_name__exact
=
'Smith'
)
self
.
assertEqual
(
'John'
,
a
.
first_name
)
self
.
assertEqual
(
'Smith'
,
a
.
last_name
)
self
.
assertRaisesMessage
(
AttributeError
,
"'Author' object has no attribute 'firstname'"
,
getattr
,
a
,
'firstname'
)
self
.
assertRaisesMessage
(
AttributeError
,
"'Author' object has no attribute 'last'"
,
getattr
,
a
,
'last'
)
def
test_m2m_table
(
self
):
art
=
Article
.
objects
.
create
(
headline
=
'Django lets you build Web apps easily'
,
primary_author
=
self
.
a1
)
art
.
authors
=
self
.
authors
self
.
assertQuerysetEqual
(
art
.
authors
.
all
()
.
order_by
(
'last_name'
),
[
'<Author: Peter Jones>'
,
'<Author: John Smith>'
]
)
self
.
assertQuerysetEqual
(
self
.
a1
.
article_set
.
all
(),
[
'<Article: Django lets you build Web apps easily>'
]
)
self
.
assertQuerysetEqual
(
art
.
authors
.
filter
(
last_name
=
'Jones'
),
[
'<Author: Peter Jones>'
]
)
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