vendredi 16 septembre 2016

Fixture processed but not loaded

I created yaml fixture

test.yaml:

- model: myapp.person
  pk: 1
  fields: 
    email: test@example.com
    params: []

tests.py:

class MyTests(TestCase):
  fixtures = ['test.yaml']

  def test_1(self):
#    import pdb; pdb.set_trace()
    person = Person.objects.get(pk=1)

The test result is

Traceback (most recent call last):
  File "/home/django/myapp/tests.py", line 99, in test_part_count
    person = Person.objects.get(pk=1)
  File "/usr/lib/python3/dist-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/django/db/models/query.py", line 385, in get self.model._meta.object_name
myapp.models.DoesNotExist: Person matching query does not exist.

If I uncomment pdb.set_trace() and check Person.objects.all() got

(Pdb) Person
<class 'myapp.models.Person'>
(Pdb) Person.objects.all()
<QuerySet []>

So i think, that fixtures doesn't fill the database.

So I checked if fixture file is read. I changed params into paramz and got

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/django/db/models/options.py", line 617, in get_field
    return self.fields_map[field_name]
KeyError: 'paramz'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/django/core/serializers/pyyaml.py", line 78, in Deserializer
    for obj in PythonDeserializer(yaml.load(stream, Loader=SafeLoader), **options):
  File "/usr/lib/python3/dist-packages/django/core/serializers/python.py", line 129, in Deserializer
    field = Model._meta.get_field(field_name)
  File "/usr/lib/python3/dist-packages/django/db/models/options.py", line 619, in get_field
    raise FieldDoesNotExist('%s has no field named %r' % (self.object_name, field_name))
django.core.exceptions.FieldDoesNotExist: Person has no field named 'paramz'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/django/test/testcases.py", line 1019, in setUpClass
    'database': db_name,
  File "/usr/lib/python3/dist-packages/django/core/management/__init__.py", line 130, in call_command
    return command.execute(*args, **defaults)
  File "/usr/lib/python3/dist-packages/django/core/management/base.py", line 345, in execute
    output = self.handle(*args, **options)
  File "/usr/lib/python3/dist-packages/django/core/management/commands/loaddata.py", line 64, in handle
    self.loaddata(fixture_labels)
  File "/usr/lib/python3/dist-packages/django/core/management/commands/loaddata.py", line 104, in loaddata
    self.load_label(fixture_label)
  File "/usr/lib/python3/dist-packages/django/core/management/commands/loaddata.py", line 161, in load_label
    for obj in objects:
  File "/usr/lib/python3/dist-packages/django/core/serializers/pyyaml.py", line 84, in Deserializer
    six.reraise(DeserializationError, DeserializationError(e), sys.exc_info()[2])
  File "/usr/lib/python3/dist-packages/django/utils/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/usr/lib/python3/dist-packages/django/core/serializers/pyyaml.py", line 78, in Deserializer
    for obj in PythonDeserializer(yaml.load(stream, Loader=SafeLoader), **options):
  File "/usr/lib/python3/dist-packages/django/core/serializers/python.py", line 129, in Deserializer
    field = Model._meta.get_field(field_name)
  File "/usr/lib/python3/dist-packages/django/db/models/options.py", line 619, in get_field
    raise FieldDoesNotExist('%s has no field named %r' % (self.object_name, field_name))
django.core.serializers.base.DeserializationError: Problem installing fixture '/home/excursor/frontoffice/fixtures/test.yaml': Person has no field named 'paramz'

So this is prove, that test read the file, and checks with database. So why Person is empty?

Aucun commentaire:

Enregistrer un commentaire