python 2.7 - Django test model with FilerImageField -



python 2.7 - Django test model with FilerImageField -

all new django, want write tests indexview , detailview in analogy django tutorial.

i have model contains filerimagefield mandatory field (blank=false).

in order test views related model, want create model instance programmatically.

i aware of this question addressing how create filerimagefield in code. problem run applying alleged solution getting part right image's owner.

def create_exhibitor(name, image_path, active): filename = 'file' user = user.objects.get(username='myuser') open(image_path) f: file_obj = file(f, name=filename) image = image.objects.create( owner=user, original_filename=filename, file=file_obj ) homecoming exhibitor(name=name, image=image, active=active)

runnging them tests yields:

traceback (most recent phone call last): ... doesnotexist: user matching query not exist.

to me appears there no user in test database.

so question twofold really:

do need user there create instance of model containing filerimagefield?

if so, how create 1 test purposes?

i'm doing so:

from django.test import testcase django.contrib.auth.models import user django.core.files.uploadedfile import simpleuploadedfile .models import exhibitor class testcase(): su_username = 'user' su_password = 'pass' def setup(self): self.superuser = self.create_superuser() def create_superuser(self): homecoming user.objects.create_superuser(self.su_username, 'email@example.com', self.su_password) def create_exhibitor(self): name = 'eins' active = true image_file = simpleuploadedfile( 'monkey.jpg', b'monkey', content_type="image/jpeg" ) homecoming exhibitor(name=name, image=image_file, active=active)

django python-2.7 django-testing django-1.6 django-filer

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -