-
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
Changes from all commits
5de5b51
e6c93bc
0c8281c
0458e49
7debc9d
5909405
afaa3f4
1e91e33
537ad71
916f426
3d04be3
cf4dc20
be16e56
ea6c52c
31830c3
267cab9
68337ae
4a4ceb1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# テスト用データーベースの設定 | ||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.mysql', | ||
'NAME': 'kawaz_travis', | ||
'USER': 'root', | ||
'PASSWORD': '', | ||
'HOST': 'localhost', | ||
'PORT': '', | ||
'OPTIONS': { | ||
'connect_timeout': 60, | ||
'init_command' : 'SET foreign_key_checks = 0;SET time_zone = "+00:00"', | ||
}, | ||
'STORAGE_ENGINE': 'INNODB', | ||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
PyMySQL<0.7.0 | ||
mysqlclient | ||
gunicorn | ||
git+https://github.com/kawazrepos/pylibmc.git@master#egg=pylibmc | ||
pylibmc |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
factory_boy>=2.7 | ||
coverage | ||
faker | ||
mysqlclient | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,2 @@ | ||
#! -*- coding: utf-8 -*- | ||
# | ||
# | ||
# | ||
|
||
__version__ = (0, 1, 0) | ||
VERSION = ".".join(map(str, __version__)) | ||
|
||
try: | ||
import pymysql | ||
pymysql.install_as_MySQLdb() | ||
except: | ||
pass |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,8 +43,8 @@ def test_published_by_authorized(self): | |
user = PersonaFactory() | ||
qs = Announcement.objects.published(user) | ||
self.assertEqual(qs.count(), 2) | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. [question] ん、ここ出現順番のテスト崩してもいいの?出現順番を保証するようにするほうが妥当じゃない? |
||
|
||
def test_published_by_anonymous(self): | ||
""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. 全体的に
って違いが発生してミスに気が付きやすくなると思う。 |
||
self.assertRedirects(r, '/announcements/{}/'.format(announcement.pk)) | ||
self.assertEqual(Announcement.objects.count(), 1) | ||
e = Announcement.objects.get(pk=1) | ||
self.assertEqual(e.title, '【悲報】データ消えました') | ||
announcement = Announcement.objects.last() | ||
self.assertEqual(announcement.title, '【悲報】データ消えました') | ||
self.assertTrue('messages' in r.cookies, "No messages are appeared") | ||
|
||
def test_authorized_user_can_create_via_create_view(self): | ||
|
@@ -217,11 +218,12 @@ def test_set_last_modifier_user(self): | |
'body' : 'サードインパクトだ!', | ||
'silently' : True | ||
}) | ||
self.assertRedirects(r, '/announcements/1/') | ||
announcement = Announcement.objects.last() | ||
self.assertRedirects(r, '/announcements/{}/'.format(announcement.pk)) | ||
self.assertEqual(Announcement.objects.count(), 1) | ||
e = Announcement.objects.get(pk=1) | ||
self.assertEqual(e.author, self.nerv) | ||
self.assertEqual(e.last_modifier, self.nerv) | ||
announcement = Announcement.objects.last() | ||
self.assertEqual(announcement.author, self.nerv) | ||
self.assertEqual(announcement.last_modifier, self.nerv) | ||
|
||
def test_staffs_cannot_modify_author_id(self): | ||
''' | ||
|
@@ -239,11 +241,12 @@ def test_staffs_cannot_modify_author_id(self): | |
'silently' : True, | ||
'author' : other.pk | ||
}) | ||
self.assertRedirects(r, '/announcements/1/') | ||
announcement = Announcement.objects.last() | ||
self.assertRedirects(r, '/announcements/{}/'.format(announcement.pk)) | ||
self.assertEqual(Announcement.objects.count(), 1) | ||
e = Announcement.objects.get(pk=1) | ||
self.assertEqual(e.author, self.nerv) | ||
self.assertNotEqual(e.author, other) | ||
announcement = Announcement.objects.last() | ||
self.assertEqual(announcement.author, self.nerv) | ||
self.assertNotEqual(announcement.author, other) | ||
self.assertTrue('messages' in r.cookies, "No messages are appeared") | ||
|
||
|
||
|
@@ -265,29 +268,29 @@ def setUp(self): | |
|
||
def test_anonymous_user_can_not_view_announcement_update_view(self): | ||
'''Tests anonymous user can not view AnnouncementUpdateView''' | ||
r = self.client.get('/announcements/1/update/') | ||
self.assertRedirects(r, settings.LOGIN_URL + '?next=/announcements/1/update/') | ||
r = self.client.get('/announcements/{}/update/'.format(self.announcement.pk)) | ||
self.assertRedirects(r, settings.LOGIN_URL + '?next=/announcements/{}/update/'.format(self.announcement.pk)) | ||
|
||
def test_wille_user_can_not_view_announcement_update_view(self): | ||
'''Tests wille user can not view AnnouncementUpdateView''' | ||
self.assertTrue(self.client.login(username=self.wille, password='password')) | ||
r = self.client.get('/announcements/1/update/') | ||
self.assertRedirects(r, settings.LOGIN_URL + '?next=/announcements/1/update/') | ||
r = self.client.get('/announcements/{}/update/'.format(self.announcement.pk)) | ||
self.assertRedirects(r, settings.LOGIN_URL + '?next=/announcements/{}/update/'.format(self.announcement.pk)) | ||
|
||
def test_general_user_can_not_view_announcement_update_view(self): | ||
''' | ||
Tests general user can view AnnouncementUpdateView | ||
''' | ||
self.assertTrue(self.client.login(username=self.other, password='password')) | ||
r = self.client.get('/announcements/1/update/') | ||
self.assertRedirects(r, settings.LOGIN_URL + '?next=/announcements/1/update/') | ||
r = self.client.get('/announcements/{}/update/'.format(self.announcement.pk)) | ||
self.assertRedirects(r, settings.LOGIN_URL + '?next=/announcements/{}/update/'.format(self.announcement.pk)) | ||
|
||
def test_staff_can_view_announcement_update_view(self): | ||
''' | ||
Tests staff members can view AnnouncementUpdateView | ||
''' | ||
self.assertTrue(self.client.login(username=self.nerv, password='password')) | ||
r = self.client.get('/announcements/1/update/') | ||
r = self.client.get('/announcements/{}/update/'.format(self.announcement.pk)) | ||
self.assertTemplateUsed(r, 'announcements/announcement_form.html') | ||
self.assertTrue('object' in r.context_data) | ||
self.assertEqual(r.context_data['object'], self.announcement) | ||
|
@@ -297,13 +300,13 @@ def test_anonymous_user_can_not_update_via_update_view(self): | |
Tests anonymous user can not update announcement via AnnouncementUpdateView | ||
It will redirect to LOGIN_URL | ||
''' | ||
r = self.client.post('/announcements/1/update/', { | ||
r = self.client.post('/announcements/{}/update/'.format(self.announcement.pk), { | ||
'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 commentThe reason will be displayed to describe this comment to others. Learn more. どのみち |
||
self.assertEqual(self.announcement.title, 'かわずたんのお知らせだよ☆') | ||
|
||
def test_wille_user_can_not_update_via_update_view(self): | ||
|
@@ -312,13 +315,13 @@ def test_wille_user_can_not_update_via_update_view(self): | |
It will redirect to LOGIN_URL | ||
''' | ||
self.assertTrue(self.client.login(username=self.wille, password='password')) | ||
r = self.client.post('/announcements/1/update/', { | ||
r = self.client.post('/announcements/{}/update/'.format(self.announcement.pk), { | ||
'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)) | ||
self.assertEqual(self.announcement.title, 'かわずたんのお知らせだよ☆') | ||
|
||
def test_other_user_cannot_update_via_update_view(self): | ||
|
@@ -327,28 +330,28 @@ def test_other_user_cannot_update_via_update_view(self): | |
It will redirect to LOGIN_URL | ||
''' | ||
self.assertTrue(self.client.login(username=self.other, password='password')) | ||
r = self.client.post('/announcements/1/update/', { | ||
r = self.client.post('/announcements/{}/update/'.format(self.announcement.pk), { | ||
'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)) | ||
self.assertEqual(self.announcement.title, 'かわずたんのお知らせだよ☆') | ||
|
||
def test_staff_can_update_via_update_view(self): | ||
'''Tests author user can update announcement via AnnouncementUpdateView''' | ||
self.assertTrue(self.client.login(username=self.nerv, password='password')) | ||
r = self.client.post('/announcements/1/update/', { | ||
r = self.client.post('/announcements/{}/update/'.format(self.announcement.pk), { | ||
'pub_state' : 'public', | ||
'title' : '【悲報】データ消えました', | ||
'body' : 'サードインパクトだ!', | ||
'silently' : True, | ||
}) | ||
self.assertRedirects(r, '/announcements/1/') | ||
self.assertRedirects(r, '/announcements/{}/'.format(self.announcement.pk)) | ||
self.assertEqual(Announcement.objects.count(), 1) | ||
e = Announcement.objects.get(pk=1) | ||
self.assertEqual(e.title, '【悲報】データ消えました') | ||
announcement = Announcement.objects.last() | ||
self.assertEqual(announcement.title, '【悲報】データ消えました') | ||
self.assertTrue('messages' in r.cookies, "No messages are appeared") | ||
|
||
def test_set_last_modifier_via_update_view(self): | ||
|
@@ -357,17 +360,17 @@ def test_set_last_modifier_via_update_view(self): | |
""" | ||
previous_modifier = self.announcement.last_modifier | ||
self.assertTrue(self.client.login(username=self.nerv, password='password')) | ||
r = self.client.post('/announcements/1/update/', { | ||
r = self.client.post('/announcements/{}/update/'.format(self.announcement.pk), { | ||
'pub_state' : 'public', | ||
'title' : '【悲報】データ消えました', | ||
'body' : 'サードインパクトだ!', | ||
'silently' : True, | ||
}) | ||
self.assertRedirects(r, '/announcements/1/') | ||
self.assertRedirects(r, '/announcements/{}/'.format(self.announcement.pk)) | ||
self.assertEqual(Announcement.objects.count(), 1) | ||
e = Announcement.objects.get(pk=1) | ||
self.assertEqual(e.last_modifier, self.nerv) | ||
self.assertNotEqual(e.last_modifier, previous_modifier) | ||
announcement = Announcement.objects.last() | ||
self.assertEqual(announcement.last_modifier, self.nerv) | ||
self.assertNotEqual(announcement.last_modifier, previous_modifier) | ||
|
||
def test_user_cannot_modify_author_id(self): | ||
''' | ||
|
@@ -378,19 +381,19 @@ def test_user_cannot_modify_author_id(self): | |
''' | ||
other = PersonaFactory() | ||
self.assertTrue(self.client.login(username=self.nerv, password='password')) | ||
r = self.client.post('/announcements/1/update/', { | ||
r = self.client.post('/announcements/{}/update/'.format(self.announcement.pk), { | ||
'pub_state' : 'public', | ||
'title' : 'ID書き換えます!', | ||
'body' : 'サードインパクトだ!', | ||
'silently' : True, | ||
'author' : other.pk # crackers attempt to masquerade | ||
}) | ||
self.assertRedirects(r, '/announcements/1/') | ||
self.assertRedirects(r, '/announcements/{}/'.format(self.announcement.pk)) | ||
self.assertEqual(Announcement.objects.count(), 1) | ||
e = Announcement.objects.get(pk=1) | ||
self.assertEqual(e.author, self.user) | ||
self.assertNotEqual(e.author, other) | ||
self.assertEqual(e.title, 'ID書き換えます!') | ||
announcement = Announcement.objects.last() | ||
self.assertEqual(announcement.author, self.user) | ||
self.assertNotEqual(announcement.author, other) | ||
self.assertEqual(announcement.title, 'ID書き換えます!') | ||
self.assertTrue('messages' in r.cookies, "No messages are appeared") | ||
|
||
class AnnouncementDeleteViewTestCase(TestCase): | ||
|
@@ -414,7 +417,7 @@ def test_author_can_delete_via_announcement_delete_view(self): | |
Tests author can delete its own announcements via AnnouncementDeleteView | ||
''' | ||
self.assertTrue(self.client.login(username=self.user, password='password')) | ||
r = self.client.post('/announcements/1/delete/', {}) | ||
r = self.client.post('/announcements/{}/delete/'.format(self.announcement.pk), {}) | ||
self.assertRedirects(r, '/announcements/') | ||
self.assertEqual(Announcement.objects.count(), 0) | ||
self.assertTrue('messages' in r.cookies, "No messages are appeared") | ||
|
@@ -424,7 +427,7 @@ def test_staff_can_delete_via_announcement_delete_view(self): | |
Tests members can delete its announcements via AnnouncementDeleteView | ||
''' | ||
self.assertTrue(self.client.login(username=self.nerv, password='password')) | ||
r = self.client.post('/announcements/1/delete/', {}) | ||
r = self.client.post('/announcements/{}/delete/'.format(self.announcement.pk), {}) | ||
self.assertRedirects(r, '/announcements/') | ||
self.assertEqual(Announcement.objects.count(), 0) | ||
self.assertTrue('messages' in r.cookies, "No messages are appeared") | ||
|
@@ -434,26 +437,26 @@ def test_other_cannot_delete_via_announcement_delete_view(self): | |
Tests others cannot delete announcements via AnnouncementDeleteView | ||
''' | ||
self.assertTrue(self.client.login(username=self.other, password='password')) | ||
r = self.client.post('/announcements/1/delete/', {}) | ||
r = self.client.post('/announcements/{}/delete/'.format(self.announcement.pk), {}) | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. nil: 順番通り適用するなら |
||
|
||
def test_wille_cannot_delete_via_announcement_delete_view(self): | ||
''' | ||
Tests wille cannot delete announcements via AnnouncementDeleteView | ||
''' | ||
self.assertTrue(self.client.login(username=self.wille, password='password')) | ||
r = self.client.post('/announcements/1/delete/', {}) | ||
r = self.client.post('/announcements/{}/delete/'.format(self.announcement.pk), {}) | ||
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)) | ||
|
||
def test_anonymous_cannot_delete_via_announcement_delete_view(self): | ||
''' | ||
Tests anonymous cannot delete announcements via AnnouncementDeleteView | ||
''' | ||
r = self.client.post('/announcements/1/delete/', {}) | ||
r = self.client.post('/announcements/{}/delete/'.format(self.announcement.pk), {}) | ||
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)) | ||
|
||
|
||
class AnnouncementListViewTestCase(TestCase): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,8 +57,8 @@ def test_published_with_authenticated(self): | |
user = PersonaFactory() | ||
qs = Entry.objects.published(user) | ||
self.assertEqual(qs.count(), 2) | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. ここも順番保証した方がいいと思う。MySQL で落ちるのであれば MySQL が返す順番がおかしいはず |
||
|
||
def test_published_with_wille(self): | ||
'''Tests Entry.objects.published() with wille user returns only public entries ''' | ||
|
@@ -132,15 +132,15 @@ def test_get_absolute_url(self): | |
user = PersonaFactory(username='mecha_kawaztan') | ||
published_at = datetime.datetime(2112, 9, 21, tzinfo=timezone.utc) | ||
entry = EntryFactory(published_at=published_at, author=user) | ||
self.assertEqual(entry.get_absolute_url(), '/blogs/mecha_kawaztan/2112/9/21/1/') | ||
self.assertEqual(entry.get_absolute_url(), '/blogs/mecha_kawaztan/2112/9/21/{}/'.format(entry.pk)) | ||
|
||
def test_get_absolute_url_of_draft(self): | ||
''' | ||
Tests get_absolute_url of draft returns update page. | ||
''' | ||
user = PersonaFactory(username='kawaztan_kawaztan') | ||
entry = EntryFactory(pub_state='draft', author=user) | ||
self.assertEqual(entry.get_absolute_url(), '/blogs/kawaztan_kawaztan/1/update/') | ||
self.assertEqual(entry.get_absolute_url(), '/blogs/kawaztan_kawaztan/{}/update/'.format(entry.pk)) | ||
|
||
def test_published_at_date_property(self): | ||
''' | ||
|
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
でインスコするべきかな