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
38a8cf1c
Kaydet (Commit)
38a8cf1c
authored
May 18, 2013
tarafından
Andrew Godwin
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fix state tests a little
üst
7d041b93
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
7 deletions
+35
-7
state.py
django/db/migrations/state.py
+5
-6
test_state.py
tests/migrations/test_state.py
+30
-1
No files found.
django/db/migrations/state.py
Dosyayı görüntüle @
38a8cf1c
...
...
@@ -14,6 +14,9 @@ class ProjectState(object):
self
.
models
=
models
or
{}
self
.
app_cache
=
None
def
add_model_state
(
self
,
model_state
):
self
.
models
[(
model_state
.
app_label
,
model_state
.
name
.
lower
())]
=
model_state
def
clone
(
self
):
"Returns an exact copy of this ProjectState"
return
ProjectState
(
...
...
@@ -24,7 +27,7 @@ class ProjectState(object):
"Turns the project state into actual models in a new AppCache"
if
self
.
app_cache
is
None
:
self
.
app_cache
=
BaseAppCache
()
for
model
in
self
.
model
.
values
:
for
model
in
self
.
model
s
.
values
()
:
model
.
render
(
self
.
app_cache
)
return
self
.
app_cache
...
...
@@ -90,10 +93,6 @@ class ModelState(object):
meta
=
type
(
"Meta"
,
tuple
(),
meta_contents
)
# Then, work out our bases
# TODO: Use the actual bases
if
self
.
bases
:
raise
NotImplementedError
(
"Custom bases not quite done yet!"
)
else
:
bases
=
[
models
.
Model
]
# Turn fields into a dict for the body, add other bits
body
=
dict
(
self
.
fields
)
body
[
'Meta'
]
=
meta
...
...
@@ -101,6 +100,6 @@ class ModelState(object):
# Then, make a Model object
return
type
(
self
.
name
,
tuple
(
bases
),
tuple
(
self
.
bases
),
body
,
)
tests/migrations/test_state.py
Dosyayı görüntüle @
38a8cf1c
from
django.test
import
TestCase
from
django.db
import
models
from
django.db.models.loading
import
BaseAppCache
from
django.db.migrations.state
import
ProjectState
from
django.db.migrations.state
import
ProjectState
,
ModelState
class
StateTests
(
TestCase
):
...
...
@@ -13,6 +13,7 @@ class StateTests(TestCase):
"""
Tests making a ProjectState from an AppCache
"""
new_app_cache
=
BaseAppCache
()
class
Author
(
models
.
Model
):
...
...
@@ -41,3 +42,31 @@ class StateTests(TestCase):
self
.
assertEqual
(
author_state
.
fields
[
2
][
1
]
.
null
,
False
)
self
.
assertEqual
(
author_state
.
fields
[
3
][
1
]
.
null
,
True
)
self
.
assertEqual
(
author_state
.
bases
,
(
models
.
Model
,
))
self
.
assertEqual
(
book_state
.
app_label
,
"migrations"
)
self
.
assertEqual
(
book_state
.
name
,
"Book"
)
self
.
assertEqual
([
x
for
x
,
y
in
book_state
.
fields
],
[
"id"
,
"title"
,
"author"
])
self
.
assertEqual
(
book_state
.
fields
[
1
][
1
]
.
max_length
,
1000
)
self
.
assertEqual
(
book_state
.
fields
[
2
][
1
]
.
null
,
False
)
self
.
assertEqual
(
book_state
.
bases
,
(
models
.
Model
,
))
def
test_render
(
self
):
"""
Tests rendering a ProjectState into an AppCache.
"""
project_state
=
ProjectState
()
project_state
.
add_model_state
(
ModelState
(
"migrations"
,
"Tag"
,
[
(
"id"
,
models
.
AutoField
(
primary_key
=
True
)),
(
"name"
,
models
.
CharField
(
max_length
=
100
)),
(
"hidden"
,
models
.
BooleanField
()),
],
{},
None
,
))
new_app_cache
=
project_state
.
render
()
self
.
assertEqual
(
new_app_cache
.
get_model
(
"migrations"
,
"Tag"
)
.
_meta
.
get_field_by_name
(
"name"
)[
0
]
.
max_length
,
100
)
self
.
assertEqual
(
new_app_cache
.
get_model
(
"migrations"
,
"Tag"
)
.
_meta
.
get_field_by_name
(
"hidden"
)[
0
]
.
null
,
False
)
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