-
Notifications
You must be signed in to change notification settings - Fork 9
Use mysqlclient-python #1126
base: develop
Are you sure you want to change the base?
Use mysqlclient-python #1126
Conversation
src/kawaz/settings.py
Outdated
from .pre_settings import * | ||
from django.utils.translation import ugettext_lazy as _ | ||
|
||
IS_CI = os.environ['CI'] and os.environ['TRAVIS'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IS_TRAVIS
で(Travis で DB のテーブル作ってるので Travis 依存になってるから)
src/kawaz/settings.py
Outdated
@@ -375,4 +379,5 @@ def show_debug_toolbar(request): | |||
try: | |||
from .local_settings import * | |||
except ImportError: | |||
pass | |||
if CI: | |||
from .ci_settings import * |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.travis_settings
で(同様の理由)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.local_settings
とは意味合い的に上下関係はないので別の try
で
src/kawaz/settings.py
Outdated
@@ -324,6 +327,7 @@ | |||
|
|||
# django-debug-toolbar | |||
def show_debug_toolbar(request): | |||
return False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これなんで?一時的なもの?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ミスった 😲
WIPになってるのは、まずTravis CIの設定をして、PyMySQLで落ちることを確認してからmysqlclientを入れたい |
1b14fca
to
7ac9bb4
Compare
@@ -157,7 +157,7 @@ def test_get_related_activities(self): | |||
# it should not contain itself | |||
# the order of appearance is also important | |||
self.assertQuerysetEqual(activities, | |||
(5, 4, 2, 1), | |||
(activity5.pk, activity4.pk, activity2.pk, activity1.pk), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙏
@lambdalisue I migrated DB for testing from sqlite to MySQL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
last()
よりもfirst()
のほうがベターなところが多々ある- 順番保証テストが保持保証テストに変わってしまっているので見直す(順番保証が不要なら理由コメントほしい)
ordering
で-pk
に変更してる理由はわかるんだけど、1
とかで落ちてたから Django + MySQL の場合pk
の付け方ってシーケンシャルなのかな?という疑問。この辺の調査してくれると助かる。
@@ -1,3 +1,4 @@ | |||
factory_boy>=2.7 | |||
coverage | |||
faker | |||
mysqlclient |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これは travis の事情(ローカルでは依然 sqlite を使う)なので travis.yml
でインスコするべきかな
self.assertEqual(qs[0], b) | ||
self.assertEqual(qs[1], a) | ||
self.assertIn(b, qs) | ||
self.assertIn(a, qs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[question] ん、ここ出現順番のテスト崩してもいいの?出現順番を保証するようにするほうが妥当じゃない?
@@ -189,10 +189,11 @@ def test_staff_user_can_create_via_create_view(self): | |||
'body' : 'サードインパクトだ!', | |||
'silently' : True | |||
}) | |||
self.assertRedirects(r, '/announcements/1/') | |||
announcement = Announcement.objects.last() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
全体的に last
使ってるけど first
のほうがベターかな
self.assertEqual(Announcement.objects.count(), 1)
が通ることからも分かる通り MySQL で落ちたのはデータが残っていたからではなく MySQL の pk の適用方法が異なるためだと思う(たぶんシーケンシャル pk じゃないんだと邪推)なので last
でも first
でも返ってくるものは同じだけど、仮にゴミデータが残っていた + count()
をチェックしていない を満たすテストがあった場合
last
を使った場合:最後に追加されたものが返るのでテストが通るfirst
を使った場合:最初に追加されたものが返るのでテストが落ちる
って違いが発生してミスに気が付きやすくなると思う。
'pub_state' : 'public', | ||
'title' : '【悲報】データ消えました', | ||
'body' : 'サードインパクトだ!', | ||
'silently' : True, | ||
}) | ||
self.assertRedirects(r, settings.LOGIN_URL + '?next=/announcements/1/update/') | ||
self.assertRedirects(r, settings.LOGIN_URL + '?next=/announcements/{}/update/'.format(self.announcement.pk)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
どのみち format()
使うなら '{}?next=...{}/update/'.format(settings.LOGIN...)
にしたほうがいいかな
self.assertEqual(Announcement.objects.count(), 1) | ||
self.assertRedirects(r, '{0}?next=/announcements/1/delete/'.format(settings.LOGIN_URL)) | ||
self.assertRedirects(r, '{0}?next=/announcements/{1}/delete/'.format(settings.LOGIN_URL, self.announcement.pk)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nil: 順番通り適用するなら {}
を連続して使えば OK
self.assertEqual(qs[0], self.entries[1]) | ||
self.assertEqual(qs[1], self.entries[0]) | ||
self.assertIn(self.entries[0], qs) | ||
self.assertIn(self.entries[1], qs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここも順番保証した方がいいと思う。MySQL で落ちるのであれば MySQL が返す順番がおかしいはず
self.assertEqual(list[0], self.entries[1], 'protected') | ||
self.assertEqual(list[1], self.entries[0], 'public') | ||
self.assertIn(self.entries[1], list, 'protected') | ||
self.assertIn(self.entries[0], list, 'public') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここも順番保証のほうがいいかな
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
他にも何箇所かあったけど全部指摘するの面倒だから指摘してない。
@@ -307,18 +306,18 @@ def test_member_can_create_url_release_via_product_form(self): | |||
'url_releases-0-url': 'http://play.google.com', | |||
}) | |||
r = self.client.post(url, self.product_kwargs) | |||
e = Product.objects.get(pk=i+1) | |||
self.assertRedirects(r, e.get_absolute_url()) | |||
product = Product.objects.last() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ちなみにここは last()
で正しい(あと i
使わないなら enumerate()
も消したほうがいいかな)
@@ -70,7 +70,7 @@ class Activity(models.Model): | |||
objects = ActivityManager() | |||
|
|||
class Meta: | |||
ordering = ('-created_at',) | |||
ordering = ('-pk',) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[question]: MySQL での pk ってシーケンシャルなのかな?もしそうなら今まで直してきたテストはなんで落ちてたんだろうか(たぶんシーケンシャルだけど途中からとか?)
closes #1126
To check CI status