2016-08-05 19 views
0

Ich schreibe Komponententests für meine Django REST Framework App und ich erstelle meine gefälschten Testdaten mit factory_boy. Ich habe über die folgenden Fehlermeldung kommen, wenn ich versuche, meine Testsdjango - factory_boy AttributeError: 'NoneType' Objekt hat kein Attribut '_meta'

File "/Users/thomasheatwole/osf-meetings/meetings/conferences/tests.py", line 69, in setUp 
    contributor = UserFactory() 
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/factory/base.py", line 67, in __call__ 
    return cls.create(**kwargs) 
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/factory/base.py", line 594, in create 
    return cls._generate(True, attrs) 
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/factory/base.py", line 519, in _generate 
    obj = cls._prepare(create, **attrs) 
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/factory/base.py", line 494, in _prepare 
    return cls._create(model_class, *args, **kwargs) 
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/factory/django.py", line 181, in _create 
    return manager.create(*args, **kwargs) 
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/django/db/models/manager.py", line 122, in manager_method 
    return getattr(self.get_queryset(), name)(*args, **kwargs) 
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/django/db/models/query.py", line 401, in create 
    obj.save(force_insert=True, using=self.db) 
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/django/db/models/base.py", line 708, in save 
    force_update=force_update, update_fields=update_fields) 
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/django/db/models/base.py", line 745, in save_base 
    update_fields=update_fields, raw=raw, using=using) 
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 192, in send 
    response = receiver(signal=self, sender=sender, **named) 
File "/Users/thomasheatwole/osf-meetings/meetings/submissions/signals.py", line 19, in add_permissions_on_submission_save 
    submission, submission_contributor, conference_admin, approval) 
File "/Users/thomasheatwole/osf-meetings/meetings/submissions/permissions.py", line 167, in set_unapproved_submission_permissions 
    approval, submission_contributor) 
File "/Users/thomasheatwole/osf-meetings/meetings/approvals/permissions.py", line 62, in add_approval_permissions_to_submission_contributor 
    assign_perm("approvals.delete_approval", submission_contributor, approval) 
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/guardian/shortcuts.py", line 92, in assign_perm 
    return model.objects.assign_perm(perm, user, obj) 
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/guardian/managers.py", line 43, in assign_perm 
    obj_perm, created = self.get_or_create(**kwargs) 
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/django/db/models/manager.py", line 122, in manager_method 
    return getattr(self.get_queryset(), name)(*args, **kwargs) 
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/django/db/models/query.py", line 467, in get_or_create 
    return self._create_object_from_params(lookup, params) 
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/django/db/models/query.py", line 499, in _create_object_from_params 
    obj = self.create(**params) 
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/django/db/models/query.py", line 401, in create 
    obj.save(force_insert=True, using=self.db) 
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/guardian/models.py", line 39, in save 
    content_type = ContentType.objects.get_for_model(self.content_object) 
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/django/contrib/contenttypes/models.py", line 55, in get_for_model 
    opts = self._get_opts(model, for_concrete_model) 
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/django/contrib/contenttypes/models.py", line 32, in _get_opts 
    model = model._meta.concrete_model 
AttributeError: 'NoneType' object has no attribute '_meta' 

ich ziemlich viel haben keine Ahnung, laufen, was da mein Verständnis von Back-End-Struktur vor sich geht ist nicht groß. Hier ist die Fabriken:

class UserFactory(factory.DjangoModelFactory): 
    class Meta: 
     model = User 

class ConferenceFactory(factory.DjangoModelFactory): 
    class Meta: 
     model = Conference 


class ApprovalFactory(factory.DjangoModelFactory): 
    class Meta: 
     model = approvalModels.Approval 


class SubmissionFactory(factory.DjangoModelFactory): 
    class Meta: 
     model = submissionModels.Submission 

Und hier, wo ich sie nenne:

def setUp(self): 
    self.user1 = UserFactory(
     username = 'Leo', 
     id = '99' 
     ) 
    self.user2 = UserFactory(
     username = 'LeoLeo' 
     ) 
    self.conference = ConferenceFactory(
     admin = self.user1 
    ) 
    self.submission1 = SubmissionFactory(
     conference = self.conference, 
     contributor = UserFactory() 
     ) 
    self.submission2 = SubmissionFactory(
     conference = self.conference, 
     contributor = UserFactory() 
     ) 

Wenn Sie die Fehlermeldung durchsehen, es speziell beschwert über contributor = UserFactory()

Lassen Sie mich wissen, ob es eine einfache Lösung oder sogar eine Erklärung dafür, was vor sich geht, wäre schön.

Vielen Dank!

Hier ist die Datei:

tests.py

+0

Ich habe eine Antwort geschrieben. Wenn Sie es immer noch nicht herausfinden können, geben Sie bitte auch die Modelldefinition an, damit wir wissen, mit welchen Beziehungen Sie es zu tun haben. – mariodev

Antwort

Verwandte Themen