I create tests for api and models. The issue is to test if models are created. User model is this one:
class User(AbstractUser):
CUSTOMER = 1
EXECUTER = 2
USER_TYPES = (
(CUSTOMER, 'Customer'),
(EXECUTER, 'Executer'),
)
user_type = models.IntegerField(choices=USER_TYPES, default=EXECUTER, verbose_name='Тип пользователя')
balance = models.DecimalField(decimal_places=2, max_digits=7, default=0, verbose_name='Баланс')
def __str__(self):
return self.username
Task models look like:
class Task(models.Model):
title = models.CharField(max_length=255, verbose_name='Заголовок')
description = models.CharField(max_length=255, verbose_name='Описание')
money = models.DecimalField(max_digits=7, decimal_places=2, default=0, verbose_name='Цена')
assignee = models.ForeignKey('users.User', related_name='assignee', null=True, verbose_name='Исполнитель')
created_by = models.ForeignKey('users.User', related_name='created_by', verbose_name='Кем был создан')
I want to test models creation, but test model doesn't want to be made. Problem is in assignee and created by fields. This is my test:
def test_creating_models_instance(self):
User.objects.create(username="assignee", first_name="First_name_2", last_name="Surname_2",
user_type=2, balance="16155.00")
User.objects.create(username="created_by", first_name="First_name_1", last_name="Surname_1",
user_type=1, balance="16155.00")
Task.objects.create(title="Task_1", description="Description_1", money="155.00",
assignee="assignee", created_by="created_by")
And I have mistake like:
self.field.remote_field.model._meta.object_name,
ValueError: Cannot assign "'assignee'": "Task.assignee" must be a "User" instance.
Aucun commentaire:
Enregistrer un commentaire