Skip to content
This repository has been archived by the owner on Jun 29, 2020. It is now read-only.

Use mysqlclient-python #1126

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from
Open

Use mysqlclient-python #1126

wants to merge 18 commits into from

Conversation

giginet
Copy link
Member

@giginet giginet commented Feb 11, 2017

closes #1126

To check CI status

from .pre_settings import *
from django.utils.translation import ugettext_lazy as _

IS_CI = os.environ['CI'] and os.environ['TRAVIS']
Copy link
Member

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 依存になってるから)

@@ -375,4 +379,5 @@ def show_debug_toolbar(request):
try:
from .local_settings import *
except ImportError:
pass
if CI:
from .ci_settings import *
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.travis_settings で(同様の理由)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.local_settings とは意味合い的に上下関係はないので別の try

@@ -324,6 +327,7 @@

# django-debug-toolbar
def show_debug_toolbar(request):
return False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これなんで?一時的なもの?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ミスった 😲

@giginet
Copy link
Member Author

giginet commented Feb 11, 2017

WIPになってるのは、まずTravis CIの設定をして、PyMySQLで落ちることを確認してからmysqlclientを入れたい

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.03%) to 97.648% when pulling ef55c54 on mysqlclient into bd7b78d on develop.

@giginet giginet force-pushed the mysqlclient branch 4 times, most recently from 1b14fca to 7ac9bb4 Compare February 11, 2017 15:39
@@ -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),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙏

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.001%) to 97.695% when pulling 630c2b5 on mysqlclient into 3286efa on develop.

@giginet giginet changed the title [WIP] Use mysqlclient-python Use mysqlclient-python Mar 26, 2017
@giginet
Copy link
Member Author

giginet commented Mar 26, 2017

@lambdalisue I migrated DB for testing from sqlite to MySQL.
Could you review it?

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.03%) to 97.67% when pulling 4a4ceb1 on mysqlclient into 3286efa on develop.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.001%) to 97.695% when pulling 4a4ceb1 on mysqlclient into 3286efa on develop.

Copy link
Member

@lambdalisue lambdalisue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. last() よりも first() のほうがベターなところが多々ある
  2. 順番保証テストが保持保証テストに変わってしまっているので見直す(順番保証が不要なら理由コメントほしい)
  3. ordering-pk に変更してる理由はわかるんだけど、1 とかで落ちてたから Django + MySQL の場合 pk の付け方ってシーケンシャルなのかな?という疑問。この辺の調査してくれると助かる。

@@ -1,3 +1,4 @@
factory_boy>=2.7
coverage
faker
mysqlclient
Copy link
Member

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)
Copy link
Member

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()
Copy link
Member

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))
Copy link
Member

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))
Copy link
Member

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)
Copy link
Member

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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここも順番保証のほうがいいかな

Copy link
Member

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()
Copy link
Member

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',)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[question]: MySQL での pk ってシーケンシャルなのかな?もしそうなら今まで直してきたテストはなんで落ちてたんだろうか(たぶんシーケンシャルだけど途中からとか?)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants