Django 1.11
我正在forms
中按Meta
测试ArrayList
Model
。{
我已经从我的问题中删除了不相关的代码。
models.py
class MailAPIScheduler(DirtyFieldsMixin, AbstractSoftModelController):
summary_email_receivers = ArrayField(
models.EmailField(blank=True),
blank=True
)
forms.py
import json
from django import forms
from eneos.apps.mail_api_schedule.models import MailAPIScheduler
class MailAPISchedulerForm(forms.ModelForm):
schedule_time = forms.TimeField()
class Meta:
model = MailAPIScheduler
fields = [
'api_url',
'schedule_time',
'parameters',
'summary_email_receivers',
]
def clean_schedule_time(self):
dt = self.cleaned_data['schedule_time']
return {
'hour': dt.hour,
'minute': dt.minute,
}
tests.py
def test_mail_api_scheulder_form(self):
data = {
'api_url': 'http://hotmail.com',
'schedule_time': '9:30',
'parameters': json.dumps({'key1': 'value1', 'key2': 'value2'}),
'summary_email_receivers': ["elcolie@gmail.com", "sarit.r@codium.co"]
}
form = MailAPISchedulerForm(data)
import pdb; pdb.set_trace()
self.assertEqual(True, form.is_valid())
self.assertDictEqual(form.cleaned_data.get('schedule_time'), {
'hour': 9,
'minute': 30,
})
Run tests
$ python manage.py test eneos.apps.mail_api_schedule.tests.TestMailAPIScheduler.test_mail_api_scheulder_form --nomigrations --settings=eneos.config.settings.local
Hey, I'm Local!
Creating test database for alias 'default'...
> /Users/el/Code/eneos-pos-web/eneos/apps/mail_api_schedule/tests.py(188)test_mail_api_scheulder_form()
-> self.assertEqual(True, form.is_valid())
(Pdb) n
AttributeError: 'list' object has no attribute 'split'
我哪里错了?