0
Test.pyとValueError:Djangoのモデルで解凍するためにあまりにも多くの値
ファイルがmemepostアプリ内のすべてのものをテストするのに役立ちます。
from django.test import TestCase
from memepost.models import memepost, memepostForm
from datetime import date
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
class memepostTestCase(TestCase):
def setUp(self):
memepost.objects.create(title="foo",
model_pic="/site_media/media/pic_folder/casual_headshot.jpg",
date=date(2017, 05, 14))
memepost.objects.create(title="bar",
date=date(2017,05, 1))
def test_memepost_enters_database(self):
foo = memepost.objects.get("foo")
bar = memepost.objects.get("bar")
self.assertEqual(foo.date, "6/15/17")
logger.debug("foo date is equal to %s", foo.date)
self.assertEqual(bar.model_pic, "no-img.jpg")
logger.debug("bar is equal to %s", bar.model_pic)
models.py
このファイルには、私のデータベースにミームを作成するための仕組みであることがあります。
from __future__ import unicode_literals
from django.forms import ModelForm
from django.db import models
# Create your models here.
class memepost(models.Model):
title = models.CharField(max_length=140)
model_pic = models.ImageField(upload_to='pic_folder/', default='pic_folder/no-img.jpg')
date = models.DateTimeField()
def __unicode__(self):
return self.title
class memepostForm(ModelForm):
class Meta:
model = memepost
fields = ["title", "model_pic", "date"]
エラー
わかりましたので、私はこの警告を取得していますが、私は、問題は、私はタイトルでget関数を呼び出すので、タイトルのparamaterとは何かを持っていると思います。私は明らかに希望します。
WARNING:py.warnings:/home/ubuntu/workspace/mysiteenv/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py:1393:
RuntimeWarning: DateTimeField memepost.date received a naive datetime (2017-05-01 00:00:00) while time zone support is active.
RuntimeWarning)
======================================================================
ERROR: test_memepost_enters_database (memepost.tests.memepostTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/ubuntu/workspace/mysite/memepost/tests.py", line 20, in test_memepost_enters_database
foo = memepost.objects.get("foo")
File "/home/ubuntu/workspace/mysiteenv/local/lib/python2.7/site-packages/django/db/models/manager.py", line 122, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/ubuntu/workspace/mysiteenv/local/lib/python2.7/site-packages/django/db/models/query.py", line 378, in get
clone = self.filter(*args, **kwargs)
File "/home/ubuntu/workspace/mysiteenv/local/lib/python2.7/site-packages/django/db/models/query.py", line 790, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "/home/ubuntu/workspace/mysiteenv/local/lib/python2.7/site-packages/django/db/models/query.py", line 808, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File "/home/ubuntu/workspace/mysiteenv/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1243, in add_q
clause, _ = self._add_q(q_object, self.used_aliases)
File "/home/ubuntu/workspace/mysiteenv/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1269, in _add_q
allow_joins=allow_joins, split_subq=split_subq,
File "/home/ubuntu/workspace/mysiteenv/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1146, in build_filter
arg, value = filter_expr
ValueError: too many values to unpack
----------------------------------------------------------------------
Ran 1 test in 0.007s