mardi 24 octobre 2017

MultipleObjectsReturned: get() returned more than one Feed -- it returned 2

I'm writing some simple test for a django-model and I'm just using assertEqual and assertNotEqual for it. Now I'm not fully grasping how to test BooleanField in this case. I have a model field like this:

duplicate = models.BooleanField(default=False)

and I'm writing this test for it, just to check if it is equal:

def test_feed_duplicate_create(self):
    stefan_feed_duplicate = Feed.objects.get(duplicate='False')
    milan_feed_duplicate = Feed.objects.get(duplicate='False')
    self.assertEqual(
        stefan_feed_duplicate.duplicate, 'False'
    )
    self.assertEqual(
        milan_feed_duplicate.duplicate, 'False'
    )

But the error that I'm facing is:

(venv) vagrant@jessie:/var/www/vhosts/bspotted.net/app$ ./manage.py test --keepdb socialmedia
nosetests socialmedia --verbosity=1
Using existing test database for alias 'default'...
............E....................
======================================================================
ERROR: test_feed_duplicate_create (app.socialmedia.tests.test_feed_model.CommentsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/www/vhosts/http://ift.tt/2yLremR", line 225, in test_feed_duplicate_create
    stefan_feed_duplicate = Feed.objects.get(duplicate='False')
  File "/var/www/vhosts/http://ift.tt/2y3C7wv", line 127, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/var/www/vhosts/http://ift.tt/2yL30cj", line 338, in get
    (self.model._meta.object_name, num)
socialmedia.models.feed.MultipleObjectsReturned: get() returned more than one Feed -- it returned 2!

----------------------------------------------------------------------
Ran 33 tests in 0.159s

Can someone explain me what is the proper way of testing BooleanField in this case? Thanks.

Aucun commentaire:

Enregistrer un commentaire