Error running tests with proxy models in Django

Question:

I have a Seller table.

https://github.com/rg3915/django-experience/blob/master/djexperience/crm/models.py#L109-L118

class Seller(Employee):
objects = SellerManager()

class Meta:
    proxy = True
    verbose_name = 'vendedor'
    verbose_name_plural = 'vendedores'

def __str__(self):
    return self.username

She is a proxy models .

When I ran test_model_seller

https://github.com/rg3915/django-experience/blob/master/djexperience/crm/tests/test_model_seller.py

from datetime import datetime
from django.test import TestCase
from djexperience.crm.models import Seller, Occupation
from .data import EMPLOYEE_DICT


class SellerTest(TestCase):

    def setUp(self):
        self.occupation = Occupation.objects.create(occupation='Gerente')
        self.obj = Seller.objects.create(
            occupation=self.occupation,
            **EMPLOYEE_DICT)

    def test_create(self):
        self.assertTrue(Seller.objects.exists())

    def test_created(self):
        ''' Seller must have an auto created attr. '''
        self.assertIsInstance(self.obj.created, datetime)

This file has been truncated. original show

returned the following error:

$ m test
Creating test database for alias 'default'...
...........F......
======================================================================
FAIL: test_create (djexperience.crm.tests.test_model_seller.SellerTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/rg3915/gh/my/django-experience/djexperience/crm/tests/test_model_seller.py", line 16, in test_create
    self.assertTrue(Seller.objects.exists())
AssertionError: False is not true

----------------------------------------------------------------------
Ran 18 tests in 0.935s

FAILED (failures=1)
Destroying test database for alias 'default'...

Does the test not apply to proxy models ?

Answer:

"Your SellerManager only returns sellers and in testing you are creating a manager."

Switching to seller solves the problem.

Scroll to Top