Liu Bo
Live long and prosper. Don't panic.
import datetime
from django.test import TestCase
from polls.models import Poll, Choice
class PollsViewsTestCase(TestCase):
fixtures = ['polls_views_testdata.json']
def test_index(self):
resp = self.client.get('/polls/')
self.assertEqual(resp.status_code, 200)
self.assertTrue('latest_poll_list' in resp.context)
self.assertEqual([poll.pk for poll in
resp.context['latest_poll_list']], [1])
URL Test in Fabric
def url_test():
urls = ('http://host:8000/res/pic/all',
'http://host:8000/res/pic/87',)
for u in urls:
try:
resp = urlopen(u)
except Exception, e:
print red_bg("open %s error" % u)
abort("test fail, %s" % e)
if resp.code == 200 and bool(loads(resp.read())):
print green_bg('test %s pass' % u)
else:
abort('test ERROR')
+--------+--------------------------------------------------------------------------------------+
| Database | Create Database |
+--------+--------------------------------------------------------------------------------------+
| tablename | CREATE DATABASE `tablename` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin */ |
+--------+--------------------------------------------------------------------------------------+
settings.py
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'OPTIONS': {'charset': 'utf8mb4'}, 'NAME': 'dbname', 'USER': 'dev', 'PASSWORD': 'dev', 'HOST': '', 'PORT': '', }, }
_mysql_exceptions.OperationalError: (2019, "Can't initialize character set utf8mb4 (path: /usr/share/mysql/charsets/)
views.py
c=MySQLdb.connect('127.0.0.1', user='root', passwd='passwd', charset='utf8', use_unicode=True).cursor()
c.execute("set names utf8mb4")
IntegrityError: (1062, "Duplicate entry 'lol' for key 'name'")
Models.objecsts.get_or_create() ? MySql!
logger.info("Deleted local files of %s" % pic)
DjangoUnicodeDecodeError: 'utf8' codec can't decode byte 0xa1 in position 8: unexpected code byte. You passed in ()
$ vagrant init precise32 http://files.vagrantup.com/precise32.box $ vagrant up
$ vagrant ssh
By Liu Bo