Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 单元测试中的django货币表单字段_Python_Django_Django Testing - Fatal编程技术网

Python 单元测试中的django货币表单字段

Python 单元测试中的django货币表单字段,python,django,django-testing,Python,Django,Django Testing,我正在使用并且我有一个money字段(value=MoneyField(…)),我想在模型表单中进行测试。代码如下: def test_post_valid(self): data = {'value': Money('99.99', currency='GBP'), } response = self.client.post(url, data) 我在表单解析代码中发现一个错误,说明: (Pdb++) form.errors

我正在使用并且我有一个money字段(
value=MoneyField(…)
),我想在模型表单中进行测试。代码如下:

def test_post_valid(self):
    data = {'value': Money('99.99', currency='GBP'), }
    response = self.client.post(url, data)
我在表单解析代码中发现一个错误,说明:

(Pdb++) form.errors                                                             
{u'value': [u'This field is required.']}

正确的格式是什么?

django money
对他们的
MoneyField
进行了一次黑客攻击,它不会转换为简单的HTML表单字段,而是为值和货币代码生成两个HTML表单字段

您必须传递3字符货币代码(
ChoiceField
)的类型为
Decimal
(或可以强制为
Decimal
)的
value
)和
value\u currency


您还可以查看django money的测试套件,以查看更多工作测试。在@HåkenLid和你之间,我知道了。你需要
data={'value_0':'99.99','value_1':'GBP'}
。啊,那么他们可能最近更改了API(可能是0.10),这很糟糕,因为它会破坏我们的代码,我在他们的文档中没有看到任何提到它的内容。在我们现有的版本中,我们必须为数值传递字段的原始名称,然后为货币代码传递字段的名称+“\u currency”。很高兴知道,但奇怪的是我必须在这里学习。
def test_post_valid(self):
    data = {'value_0': '99.99', 'value_1': 'GBP' }
    response = self.client.post(url, data)