Django testing-TypeError:int()参数必须是字符串、类似字节的对象或数字,而不是';用户';

Django testing-TypeError:int()参数必须是字符串、类似字节的对象或数字,而不是';用户';,django,django-testing,django-mixer,Django,Django Testing,Django Mixer,我正在为我的第一个Django应用程序编写测试用例,并使用mixer为一些模块生成随机值 为测试模型而编写的测试用例如下 测试\u model.py from datetime import datetime, timedelta from django.core.exceptions import ValidationError from tzlocal import get_localzone import pytest from django.test import TestCase

我正在为我的第一个
Django
应用程序编写测试用例,并使用
mixer
为一些模块生成随机值

为测试模型而编写的测试用例如下

测试\u model.py

from datetime import datetime, timedelta

from django.core.exceptions import ValidationError
from tzlocal import get_localzone

import pytest
from django.test import TestCase
from mixer.backend.django import mixer

from transactions.models import ModeOfPayment, AmountGiven

pytestmark = pytest.mark.django_db

@pytest.mark.django_db
class TestAmountReturned(TestCase):
    def test_model_amount_return_add(self):
        amount_returned = mixer.blend(
            'transactions.AmountReturned',
            amount_given=mixer.blend(
                'transactions.AmountGiven',
                given_date=datetime.now(get_localzone()) - timedelta(days=300)
            ),
            amount=100.00,
            return_date=datetime.now(get_localzone()) - timedelta(days=50)
        )

        assert str(amount_returned) == str(amount_returned.amount), '__str__ should return amount string'

    def test_model_amount_due(self):
        amount = 10000.00
        interest_rate = 9.5
        duration = 365
        given_date = datetime.now(get_localzone()) - timedelta(days=200)
        returned_amount = 150.00

        amount_given = mixer.blend(
            'transactions.AmountGiven',
            contact=mixer.blend('contacts.Contact'),
            amount=amount,
            interest_rate=interest_rate,
            duration=duration,
            given_date=given_date,
            mode_of_payment=mixer.blend('transactions.ModeOfPayment', title='Cash')
        )

        mixer.blend(
            'transactions.AmountReturned',
            amount_given=amount_given,
            amount=returned_amount,
            return_date=datetime.now(get_localzone()) - timedelta(days=50)
        )

        assert amount_given.amount_due == amount_given.total_payable - returned_amount, 'Should return dues amount'
但是在运行测试时

pipenv run py.test
它给出了以下错误

______________________________ TestAmountReturned.test_model_amount_due _______________________

self = <django.db.models.fields.AutoField: id>, value = <User: khess>

    def to_python(self, value):
        if value is None:
            return value
        try:
>           return int(value)
E           TypeError: int() argument must be a string, a bytes-like object or a number, not 'User'

../../../.local/share/virtualenvs/koober-py-McGChbzt/lib/python3.6/site-packages/django/db/models/fields/__init__.py:940: TypeError

During handling of the above exception, another exception occurred:

self = <transactions.tests.test_models.TestAmountReturned testMethod=test_model_amount_due>

    def test_model_amount_due(self):
        amount = 10000.00
        interest_rate = 9.5
        duration = 365
        given_date = datetime.now(get_localzone()) - timedelta(days=200)
        returned_amount = 150.00

        amount_given = mixer.blend(
            'transactions.AmountGiven',
>           contact=mixer.blend('contacts.Contact'),
            amount=amount,
            interest_rate=interest_rate,
            duration=duration,
            given_date=given_date,
            mode_of_payment=mixer.blend('transactions.ModeOfPayment', title='Cash')
        )

src/transactions/tests/test_models.py:182: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
但无法确定此错误发生在哪一列。我也曾使用混合器将触点与其他位置混合,很少有触点工作正常

contact=mixer.blend('contacts.Contact'),